List of usage examples for java.util Formatter format
public Formatter format(String format, Object... args)
From source file:Networking.Server.java
private static String toHexString(byte[] bytes) { Formatter formatter = new Formatter(); for (byte b : bytes) { formatter.format("%02x", b); }// w w w .j a v a 2 s . c o m return formatter.toString(); }
From source file:edu.cmu.tetrad.cli.search.FgsCli.java
private static String createArgsInfo() { Formatter fmt = new Formatter(); if (dataFile != null) { fmt.format("data = %s%n", dataFile.getFileName()); }/* ww w. ja v a 2s . co m*/ if (excludedVariableFile != null) { fmt.format("exclude-variables = %s%n", excludedVariableFile.getFileName()); } if (knowledgeFile != null) { fmt.format("knowledge = %s%n", knowledgeFile.getFileName()); } fmt.format("delimiter = %s%n", Args.getDelimiterName(delimiter)); fmt.format("verbose = %s%n", verbose); fmt.format("thread = %s%n", numOfThreads); fmt.format("penalty-discount = %f%n", penaltyDiscount); fmt.format("ignore-linear-dependence = %s%n", ignoreLinearDependence); fmt.format("depth = %d%n", depth); fmt.format("heuristic-speedup = %s%n", heuristicSpeedup); fmt.format("graphml = %s%n", graphML); fmt.format("skip-unique-var-name = %s%n", skipUniqueVarName); fmt.format("skip-non-zero-variance = %s%n", skipZeroVariance); fmt.format("out = %s%n", dirOut.getFileName().toString()); fmt.format("output-prefix = %s%n", outputPrefix); fmt.format("no-validation-output = %s%n", !validationOutput); return fmt.toString(); }
From source file:edu.cmu.tetrad.cli.search.FgsDiscrete.java
private static String createArgsInfo() { Formatter fmt = new Formatter(); if (dataFile != null) { fmt.format("data = %s%n", dataFile.getFileName()); }//from w w w. j a va 2s . c o m if (excludedVariableFile != null) { fmt.format("exclude-variables = %s%n", excludedVariableFile.getFileName()); } if (knowledgeFile != null) { fmt.format("knowledge = %s%n", knowledgeFile.getFileName()); } fmt.format("delimiter = %s%n", Args.getDelimiterName(delimiter)); fmt.format("verbose = %s%n", verbose); fmt.format("thread = %s%n", numOfThreads); fmt.format("structure-prior = %f%n", structurePrior); fmt.format("sample-prior = %f%n", samplePrior); fmt.format("depth = %d%n", depth); fmt.format("heuristic-speedup = %s%n", heuristicSpeedup); fmt.format("graphml = %s%n", graphML); fmt.format("skip-unique-var-name = %s%n", skipUniqueVarName); fmt.format("skip-category-limit = %s%n", skipCategoryLimit); fmt.format("out = %s%n", dirOut.getFileName().toString()); fmt.format("output-prefix = %s%n", outputPrefix); fmt.format("no-validation-output = %s%n", !validationOutput); return fmt.toString(); }
From source file:com.netradius.hibernate.support.HibernateUtil.java
/** * Pretty prints a list of String arrays. This method assumes the first array in the list * is the header./*w w w . j a v a 2 s .c o m*/ * * @param rows the rows to print */ private static void prettyPrint(List<String[]> rows) { if (!rows.isEmpty()) { final int numCol = rows.get(0).length; final int[] maxLength = new int[numCol]; Arrays.fill(maxLength, 0); for (String[] row : rows) { for (int i = row.length - 1; i >= 0; i--) { if (row[i] == null && maxLength[i] < 4) maxLength[i] = 4; else if (row[i] != null && row[i].length() > maxLength[i]) maxLength[i] = row[i].length(); } } final StringBuilder sb = new StringBuilder(); int totalLength = 0; for (int i = 0; i < maxLength.length; i++) { totalLength += maxLength[i]; if (i == 0) sb.append("| "); sb.append("%").append(i + 1).append("$-").append(maxLength[i]).append("s | "); if (i == maxLength.length - 1) sb.append("\n"); } totalLength += numCol * 3 + 1; final String pattern = sb.toString(); final Formatter formatter = new Formatter(System.out); System.out.print(line('=', totalLength)); for (int i = 0; i < rows.size(); i++) { formatter.format(pattern, (Object[]) rows.get(i)); if (i == 0) System.out.print(line('=', totalLength)); else System.out.print(line('-', totalLength)); } } }
From source file:com.lightbox.android.bitmap.BitmapUtils.java
private static String md5ToString(byte[] md5Hash) { Formatter formatter = new Formatter(); for (byte b : md5Hash) { formatter.format("%02x", b); }//from w w w.j av a2s .c om return formatter.toString(); }
From source file:com.lightbox.android.bitmap.BitmapUtils.java
private static String getMD5String(byte[] data) { MessageDigest md5 = null;// w w w.j av a 2s. c om try { md5 = MessageDigest.getInstance("MD5"); md5.reset(); md5.update(data); byte[] md5Hash = md5.digest(); Formatter formatter = new Formatter(); for (byte b : md5Hash) { formatter.format("%02x", b); } return formatter.toString(); } catch (NoSuchAlgorithmException e1) { Log.w(TAG, e1); } return ""; }
From source file:de.uzk.hki.da.pkg.MetsConsistencyChecker.java
/** * Byte array2 hex.// w w w . j a v a 2 s. c o m * * @param hash the hash * @return the string */ private static String byteArray2Hex(byte[] hash) { Formatter formatter = new Formatter(); for (byte b : hash) { formatter.format("%02x", b); } String result = formatter.toString(); formatter.close(); return result; }
From source file:org.gradle.util.GUtil.java
public static String toString(Iterable<?> names) { Formatter formatter = new Formatter(); boolean first = true; for (Object name : names) { if (first) { formatter.format("'%s'", name); first = false;/*w w w. j a v a2s . c om*/ } else { formatter.format(", '%s'", name); } } return formatter.toString(); }
From source file:org.kalypso.model.wspm.tuhh.core.wspwin.WspWinExporter.java
private static void write1DTuhhSteuerparameter(final TuhhCalculation calculation, final File batFile, final File zustFile, final File qwtFile, final File psiFile, final TuhhStationRange stationRange) throws IOException { final MODE calcMode = calculation.getCalcMode(); Formatter pw = null; try {/*from w w w .ja va2s . c o m*/ batFile.getParentFile().mkdirs(); pw = new Formatter(batFile); pw.format("# %s%n", calculation.getName()); //$NON-NLS-1$ pw.format("# %s%n", //$NON-NLS-1$ DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date())); pw.format("%n"); //$NON-NLS-1$ pw.format("PROJEKTPFAD=%s%n", "."); //$NON-NLS-1$ //$NON-NLS-2$ pw.format("STRANGDATEI=%s%n", zustFile.getName()); //$NON-NLS-1$ pw.format("%n"); //$NON-NLS-1$ pw.format("# mgliche Werte:%n"); //$NON-NLS-1$ pw.format("# WATERLEVEL%n"); //$NON-NLS-1$ pw.format("# BF_UNIFORM%n"); //$NON-NLS-1$ pw.format("# BF_NON_UNIFORM%n"); //$NON-NLS-1$ pw.format("# REIB_KONST%n"); //$NON-NLS-1$ pw.format("BERECHNUNGSMODUS=%s%n", calcMode.name()); //$NON-NLS-1$ pw.format("%n"); //$NON-NLS-1$ pw.format("# mgliche Werte:%n"); //$NON-NLS-1$ pw.format("# DARCY_WEISBACH_OHNE_FORMEINFLUSS%n"); //$NON-NLS-1$ pw.format("# DARCY_WEISBACH_MIT_FORMEINFLUSS%n"); //$NON-NLS-1$ pw.format("# MANNING_STRICKLER%n"); //$NON-NLS-1$ pw.format("FLIESSGESETZ=%s%n", calculation.getFliessgesetz().name()); //$NON-NLS-1$ pw.format("%n"); //$NON-NLS-1$ pw.format(Locale.US, "ANFANGSSTATION=%s%n", stationRange.getExportFrom()); //$NON-NLS-1$ pw.format(Locale.US, "ENDSTATION=%s%n", stationRange.getExportTo()); //$NON-NLS-1$ pw.format("%n"); //$NON-NLS-1$ pw.format("# mgliche Werte%n"); //$NON-NLS-1$ pw.format("# CRITICAL_WATER_DEPTH%n"); //$NON-NLS-1$ pw.format("# UNIFORM_BOTTOM_SLOPE%n"); //$NON-NLS-1$ pw.format("# WATERLEVEL%n"); //$NON-NLS-1$ pw.format("ART_RANDBEDINGUNG=%s%n", calculation.getStartKind().name()); //$NON-NLS-1$ final Double startWaterlevel = calculation.getStartWaterlevel(); if (startWaterlevel != null) { pw.format(Locale.US, "ANFANGSWASSERSPIEGEL=%s%n", startWaterlevel); //$NON-NLS-1$ } final BigDecimal startSlope = calculation.getStartSlope(); if (startSlope != null) { pw.format("GEFAELLE=%s%n", startSlope); //$NON-NLS-1$ } pw.format("%n"); //$NON-NLS-1$ pw.format("# mgliche Werte%n"); //$NON-NLS-1$ pw.format("# NON%n"); //$NON-NLS-1$ pw.format("# DVWK%n"); //$NON-NLS-1$ pw.format("# BJOERNSEN%n"); //$NON-NLS-1$ pw.format("# DFG%n"); //$NON-NLS-1$ pw.format("VERZOEGERUNGSVERLUST=%s%n", calculation.getVerzoegerungsverlust().name()); //$NON-NLS-1$ pw.format("%n"); //$NON-NLS-1$ pw.format("# mgliche Werte%n"); //$NON-NLS-1$ pw.format("# SIMPLE%n"); //$NON-NLS-1$ pw.format("# EXACT%n"); //$NON-NLS-1$ pw.format("ITERATIONSART=%s%n", calculation.getIterationType().name()); //$NON-NLS-1$ pw.format("%n"); //$NON-NLS-1$ pw.format("# mgliche Werte%n"); //$NON-NLS-1$ pw.format("# TRAPEZ_FORMULA%n"); //$NON-NLS-1$ pw.format("# GEOMETRIC_FORMULA%n"); //$NON-NLS-1$ pw.format("REIBUNGSVERLUST=%s%n", calculation.getReibungsverlust().name()); //$NON-NLS-1$ pw.format("%n"); //$NON-NLS-1$ pw.format("# mgliche Werte: true / false%n"); //$NON-NLS-1$ pw.format("MIT_BRUECKEN=%b%n", calculation.isCalcBridges()); //$NON-NLS-1$ pw.format("MIT_WEHREN=%b%n", calculation.isCalcBarrages()); //$NON-NLS-1$ pw.format("USE_EXTREM_ROUGH=%b%n", calculation.isUseExtremeRoughness()); //$NON-NLS-1$ pw.format("%n"); //$NON-NLS-1$ pw.format("ABFLUSSEREIGNIS=%s%n", qwtFile.getName()); //$NON-NLS-1$ pw.format("%n"); //$NON-NLS-1$ pw.format("EINZELVERLUSTE=%s%n", psiFile.getName()); //$NON-NLS-1$ //$NON-NLS-2$ pw.format("%n"); //$NON-NLS-1$ final Double minQ = calculation.getMinQ(); if (minQ != null) { pw.format(Locale.US, "MIN_Q=%s%n", minQ); //$NON-NLS-1$ } final Double maxQ = calculation.getMaxQ(); if (maxQ != null) { pw.format(Locale.US, "MAX_Q=%s%n", maxQ); //$NON-NLS-1$ } final Double qstep = calculation.getQStep(); if (qstep != null) { pw.format(Locale.US, "DELTA_Q=%s%n", qstep); //$NON-NLS-1$ } pw.format("%n"); //$NON-NLS-1$ // Einheit des Durchflusses wird standardmig festgelegt pw.format("# mgliche Werte%n"); //$NON-NLS-1$ pw.format("# QM_S%n"); //$NON-NLS-1$ pw.format("# L_S%n"); //$NON-NLS-1$ pw.format("DURCHFLUSS_EINHEIT=QM_S%n"); //$NON-NLS-1$ FormatterUtils.checkIoException(pw); } finally { if (pw != null) { pw.close(); } } }
From source file:com.base.service.WeixinService.java
private static String byteToHex(final byte[] hash) { Formatter formatter = new Formatter(); for (byte b : hash) { formatter.format("%02x", b); }/* w ww . ja v a 2 s . c o m*/ String result = formatter.toString(); formatter.close(); return result; }