List of usage examples for java.util Formatter Formatter
public Formatter(OutputStream os)
From source file:com.itemanalysis.psychometrics.rasch.JMLE.java
/** * Publishes global iteration information in the jmetrik log. *//* w ww . j a va2s .c om*/ public String printIterationSummary() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); int iter = 1; f.format("%-35s", "RASCH ANALYSIS ITERATION SUMMARY"); f.format("%n"); f.format("%10s", "Iteration"); f.format("%5s", ""); f.format("%10s", "Max Change"); f.format("%n"); f.format("%-35s", "==================================="); f.format("%n"); for (Double d : iterationDelta) { f.format("%10d", iter); f.format("%5s", ""); f.format("%10.6f", d); f.format("%n"); iter++; } if (extremeIterationDelta.size() > 0) { iter = 0; f.format("%n"); f.format("%n"); f.format("%-35s", "EXTREME ITEM/PERSON ITERATION SUMMARY"); f.format("%n"); f.format("%10s", "Iteration"); f.format("%5s", ""); f.format("%10s", "Max Change"); f.format("%n"); f.format("%-35s", "==================================="); f.format("%n"); for (Double d : extremeIterationDelta) { f.format("%10d", iter); f.format("%5s", ""); f.format("%10.6f", d); f.format("%n"); iter++; } } return f.toString(); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public static String getQuotedTimestampString(Calendar val) { if (val == null) { return ("null"); } else {/* ww w. j a v a2 s . c o m*/ StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); buff.append("T"); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", val.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public static String getQuotedTZDateString(Calendar val) { if (val == null) { return ("null"); } else {/*from w w w . j a v a 2s .c o m*/ Calendar cal; if (val.getTimeZone().equals(getServerTimeZone())) { cal = val; } else { cal = new GregorianCalendar(getServerTimeZone()); cal.setTimeInMillis(val.getTimeInMillis()); } StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", cal.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", cal.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", cal.get(Calendar.DAY_OF_MONTH)); buff.append("T"); fmt.format("%1$02d", cal.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", cal.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", cal.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public static String getQuotedTZTimeString(Calendar val) { if (val == null) { return ("null"); } else {//from ww w .j a v a2 s . c o m Calendar cal; if (val.getTimeZone().equals(getServerTimeZone())) { cal = val; } else { cal = new GregorianCalendar(getServerTimeZone()); cal.setTimeInMillis(val.getTimeInMillis()); } StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", cal.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", cal.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", cal.get(Calendar.DAY_OF_MONTH)); buff.append("T"); fmt.format("%1$02d", cal.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", cal.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", cal.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public static String getQuotedTZTimestampString(Calendar val) { if (val == null) { return ("null"); } else {/*w ww.ja v a2s . c o m*/ Calendar cal; if (val.getTimeZone().equals(getServerTimeZone())) { cal = val; } else { cal = new GregorianCalendar(getServerTimeZone()); cal.setTimeInMillis(val.getTimeInMillis()); } StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", cal.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", cal.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", cal.get(Calendar.DAY_OF_MONTH)); buff.append("T"); fmt.format("%1$02d", cal.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", cal.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", cal.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } }
From source file:org.apache.hadoop.hdfs.server.balancer.Balancer.java
/** main method of Balancer * @param args arguments to a Balancer/*from w ww .j av a2 s . com*/ * @exception any exception occurs during datanode balancing */ public int run(String[] args) throws Exception { long startTime = Util.now(); OutputStream out = null; try { // initialize a balancer init(parseArgs(args)); /* Check if there is another balancer running. * Exit if there is another one running. */ out = checkAndMarkRunningBalancer(); if (out == null) { System.out.println("Another balancer is running. Exiting..."); return ALREADY_RUNNING; } Formatter formatter = new Formatter(System.out); System.out.println( "Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved"); int iterations = 0; while (true) { /* get all live datanodes of a cluster and their disk usage * decide the number of bytes need to be moved */ long bytesLeftToMove = initNodes(); if (bytesLeftToMove == 0) { System.out.println("The cluster is balanced. Exiting..."); return SUCCESS; } else { LOG.info("Need to move " + StringUtils.byteDesc(bytesLeftToMove) + " bytes to make the cluster balanced."); } /* Decide all the nodes that will participate in the block move and * the number of bytes that need to be moved from one node to another * in this iteration. Maximum bytes to be moved per node is * Min(1 Band worth of bytes, MAX_SIZE_TO_MOVE). */ long bytesToMove = chooseNodes(); if (bytesToMove == 0) { System.out.println("No block can be moved. Exiting..."); return NO_MOVE_BLOCK; } else { LOG.info("Will move " + StringUtils.byteDesc(bytesToMove) + "bytes in this iteration"); } formatter.format("%-24s %10d %19s %18s %17s\n", DateFormat.getDateTimeInstance().format(new Date()), iterations, StringUtils.byteDesc(bytesMoved.get()), StringUtils.byteDesc(bytesLeftToMove), StringUtils.byteDesc(bytesToMove)); /* For each pair of <source, target>, start a thread that repeatedly * decide a block to be moved and its proxy source, * then initiates the move until all bytes are moved or no more block * available to move. * Exit no byte has been moved for 5 consecutive iterations. */ if (dispatchBlockMoves() > 0) { notChangedIterations = 0; } else { notChangedIterations++; if (notChangedIterations >= 5) { System.out.println("No block has been moved for 5 iterations. Exiting..."); return NO_MOVE_PROGRESS; } } // clean all lists resetData(); try { Thread.sleep(2 * conf.getLong("dfs.heartbeat.interval", 3)); } catch (InterruptedException ignored) { } iterations++; } } catch (IllegalArgumentException ae) { return ILLEGAL_ARGS; } catch (IOException e) { System.out.println("Received an IO exception: " + e.getMessage() + " . Exiting..."); return IO_EXCEPTION; } finally { // shutdown thread pools dispatcherExecutor.shutdownNow(); moverExecutor.shutdownNow(); shouldRun = false; try { if (keyupdaterthread != null) keyupdaterthread.interrupt(); } catch (Exception e) { LOG.warn("Exception shutting down access key updater thread", e); } // close the output file IOUtils.closeStream(out); if (fs != null) { try { fs.delete(BALANCER_ID_PATH, true); } catch (IOException ignored) { } } System.out.println("Balancing took " + time2Str(Util.now() - startTime)); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public static String getDateString(Calendar val) { if (val == null) { return ("null"); } else {//from w w w . j a v a 2 s. c om StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public static String getTimeString(Calendar val) { if (val == null) { return ("null"); } else {//from w w w .j av a 2 s. co m StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", val.get(Calendar.SECOND)); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccPgSql.CFAccPgSqlSchema.java
public static String getQuotedDateString(Calendar val) { if (val == null) { return ("null"); } else {//w ww . ja va 2 s.c o m StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); buff.append("'"); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public static String getTimestampString(Calendar val) { if (val == null) { return ("null"); } else {/*from ww w. j a v a 2 s .co m*/ StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); buff.append("T"); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", val.get(Calendar.SECOND)); fmt.close(); return (buff.toString()); } }