コード例 #1
0
ファイル: UploadFile.java プロジェクト: venci78/maven
  public static void main(String args[]) {
    Connection c = null;
    PreparedStatement stmt = null;
    try {
      Class.forName("org.postgresql.Driver");
      c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test", "pdv", "pdv");
      System.out.println("Opened database successfully");
      List<String> results = new ArrayList<String>();
      File dir = new File("D:/jboss/eclipse/workspace/LTF");
      Iterator<File> files =
          FileUtils.iterateFilesAndDirs(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
      StopWatch timerAll = new StopWatch();
      timerAll.start();
      while (files.hasNext()) {
        File file = (File) files.next();
        if (file.isFile()) {
          StopWatch timeForAFile = new StopWatch();
          timeForAFile.start();
          String toDB = encodeFileToBase64Binary(file);
          String sql =
              "INSERT INTO test (file_id,file_name,file_data,file_date) VALUES (nextval('test_file_id_seq'),?,?,?)";
          stmt = c.prepareStatement(sql);

          stmt.setString(1, file.getAbsolutePath());
          stmt.setString(2, toDB);
          stmt.setDate(3, new java.sql.Date(Calendar.getInstance().getTimeInMillis()));
          stmt.executeUpdate();
          timeForAFile.stop();
          System.out.println(timeForAFile.toString());
        }
      }
      timerAll.stop();
      System.out.println("=================================================");
      System.out.println(timerAll.toString());

      stmt.close();
      /*
       * Statement statement = null; statement = c.createStatement();
       * ResultSet rs = statement.executeQuery(
       * "select file_data from test limit 1"); while (rs.next()) { String
       * encoded = rs.getString("file_data"); byte[] decoded =
       * Base64.getDecoder().decode(encoded); FileOutputStream fos = new
       * FileOutputStream("c:/temp/2.jpg"); fos.write(decoded);
       * fos.close(); }
       */

      c.close();
    } catch (Exception e) {
      System.err.println(e.getClass().getName() + ": " + e.getMessage());
      System.exit(0);
    }
    System.out.println("Table created successfully");
  }
コード例 #2
0
 public T execute() throws Exception {
   stopWatch.start();
   T result = executeImpl();
   stopWatch.stop();
   logger.debug("Message={} - Elapsed time: {}", message, stopWatch.toString());
   return result;
 }
コード例 #3
0
ファイル: Main.java プロジェクト: graeme-lockley/Learnings
  public static void main(String[] args) throws Exception {
    List<Book> books = new ArrayList<Book>();
    books.add(new Book("The Hitchhiker's Guide to the Galaxy", 5.70, true, "0"));
    books.add(new Book("Life, the Universe and Everything", 5.60, false, "N"));
    books.add(new Book("The > Restaurant at the < End of the Universe & all", 5.40, true, "Yes"));

    Map<String, Object> model = new HashMap<String, Object>();
    model.put("books", books);
    model.put("pageName", "My Bookshelf");

    JadeConfiguration jadeConfiguration = new JadeConfiguration();
    jadeConfiguration.setPrettyPrint(true);
    jadeConfiguration.setMode(Jade4J.Mode.XML);

    JadeTemplate template = jadeConfiguration.getTemplate("src/main/java/jade2j/index.jade");

    StopWatch stopWatch = new StopWatch();

    stopWatch.start();
    String result = jadeConfiguration.renderTemplate(template, model);
    stopWatch.stop();

    System.out.println(result);
    System.out.println(stopWatch.toString());
  }
コード例 #4
0
 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
     throws IOException, ServletException {
   HttpServletRequest httpRequest = (HttpServletRequest) request;
   // 如果在excludePath中,则跳过
   if (StringUtils.isNotBlank(
       UrlUtils.urlMatch(excludePathSet, RequestUtils.getReqPath(httpRequest)))) {
     chain.doFilter(request, response);
     return;
   }
   StopWatch stopWatch = new StopWatch();
   stopWatch.start();
   request.setAttribute(START_TIME, stopWatch);
   chain.doFilter(request, response);
   stopWatch.stop();
   if (null != request.getAttribute(START_TIME)) {
     logger.info(
         "URL[" + httpRequest.getRequestURI() + "]executeTime[" + stopWatch.toString() + "]");
   }
 }
コード例 #5
0
    @Override
    protected List<RssItem> doInBackground(Void... urls) {
      DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context);

      SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
      boolean onlyUnreadItems = mPrefs.getBoolean(SettingsActivity.CB_SHOWONLYUNREAD_STRING, false);
      boolean onlyStarredItems = false;
      if (idFolder != null)
        if (idFolder
            == SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_STARRED_ITEMS.getValue())
          onlyStarredItems = true;

      String sqlSelectStatement = null;
      if (idFeed != null)
        sqlSelectStatement =
            dbConn.getAllItemsIdsForFeedSQL(
                idFeed, onlyUnreadItems, onlyStarredItems, sortDirection);
      else if (idFolder != null) {
        if (idFolder
            == SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_STARRED_ITEMS.getValue())
          onlyUnreadItems = false;
        sqlSelectStatement =
            dbConn.getAllItemsIdsForFolderSQL(idFolder, onlyUnreadItems, sortDirection);
      }
      if (sqlSelectStatement != null) {
        dbConn.insertIntoRssCurrentViewTable(sqlSelectStatement);
      }

      StopWatch sw = new StopWatch();
      sw.start();

      List<RssItem> items = dbConn.getCurrentRssItemView(0);

      sw.stop();
      Log.v(TAG, "Time needed (init loading): " + sw.toString());

      return items;
    }