List of usage examples for java.util Formatter Formatter
public Formatter(OutputStream os)
From source file:com.dgsd.android.ShiftTracker.Adapter.WeekAdapter.java
public WeekAdapter(Context context, Cursor c, int julianDay) { super(context, c, false); inflater = LayoutInflater.from(context); mStartingJulianDay = julianDay;//ww w . java 2s .c om mRand = new Random(); mTime = new Time(); mIs24Hour = DateFormat.is24HourFormat(context); mStringBuilder = new StringBuilder(); mFormatter = new Formatter((mStringBuilder)); mCurrencyFormatter = NumberFormat.getCurrencyInstance(); //Caching mJdToTitleArray = new SparseArray<String>(); mIdToTimeArray = new SparseArray<String>(); mIdToPayArray = new SparseArray<String>(); mCurrentJulianDay = TimeUtils.getCurrentJulianDay(); mShowIncomePref = Prefs.getInstance(context).get(context.getString(R.string.settings_key_show_income), true); }
From source file:com.amazon.carbonado.repo.tupl.LogEventListener.java
private String format(EventType type, String message, Object... args) { StringBuilder b = new StringBuilder(); b.append('"').append(mName).append("\" ").append(type.category.toString()).append(": "); return new Formatter(b).format(message, args).toString(); }
From source file:org.megam.api.http.TransportTools.java
public String toString() { StringBuilder strbd = new StringBuilder(); final Formatter formatter = new Formatter(strbd); formatter.format("%s%n", "*----------------------------------------------*"); formatter.format("%12s = %s%n", "url", urlString()); formatter.format("%12s = %s%n", "pairs", pairs()); formatter.format("%12s = %s%n", "headers", headers()); formatter.format("%12s = %s%n", "query", isQuery()); formatter.format("%12s = %s%n", "encoding", encoding()); formatter.format("%12s = %s%n", "contenttype", contentType()); formatter.format("%12s = %s%n", "contentstring", contentString()); formatter.format("%s%n", "*----------------------------------------------*"); formatter.close();/*from www.j av a 2 s . c om*/ return strbd.toString(); }
From source file:scenario.EncodingTest.java
@Test public void utf16EncodingFromBytesTest() throws IOException { System.setProperty("javax.xml.transform.TransformerFactory", XslScenario.SAXON_TRANSFORMER_FACTORY_FQCN); File xmlFile = new File(testResources.get("utf16-doc.xml").getURI()); File xslFile = new File(testResources.get("encoding.xsl").getURI()); XslScenario sc = new XslScenario(xslFile); byte[] bytes = FileUtils.readFileToByteArray(xmlFile); for (byte b : bytes) { System.out.format("%02x ", b); }//from w w w .java 2 s . c o m System.out.println(); // BOM UTF-16LE StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb); formatter.format("%02x", bytes[0]); assertEquals("ff", sb.toString()); sb.delete(0, 2); formatter.format("%02x", bytes[1]); assertEquals("fe", sb.toString()); Map<String, String> outputs = sc.apply(bytes); assertNotNull("outputs object cannot be null.", outputs); }
From source file:com.itemanalysis.psychometrics.scaling.ScoreTable.java
@Override public String toString() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); String f1 = "%10." + precision + "f"; String f2 = "%10s"; // String f3="%10.4f"; //table header f.format("%28s", "SCORE TABLE"); f.format("%n"); f.format("%45s", "============================================="); f.format("%n"); f.format(f2, "Original"); f.format("%5s", ""); f.format(f2, "Kelley"); f.format("%n"); f.format(f2, "Value"); f.format("%5s", ""); f.format(f2, "Score"); f.format("%n"); f.format("%45s", "---------------------------------------------"); f.format("%n"); for (Double d : table.keySet()) { f.format(f1, d);// w ww. jav a2s. c o m f.format("%5s", ""); f.format(f1, table.get(d)); f.format("%5s", ""); f.format("%n"); } f.format("%45s", "============================================="); f.format("%n"); return f.toString(); }
From source file:org.apache.sqoop.io.SplittingOutputStream.java
/** Initialize the OutputStream to the next file to write to. *//*from w ww .j a va 2s .co m*/ private void openNextFile() throws IOException { StringBuffer sb = new StringBuffer(); Formatter fmt = new Formatter(sb); fmt.format("%05d", this.fileNum++); String filename = filePrefix + fmt.toString(); if (codec != null) { filename = filename + codec.getDefaultExtension(); } Path destFile = new Path(destDir, filename); FileSystem fs = destFile.getFileSystem(conf); LOG.debug("Opening next output file: " + destFile); if (fs.exists(destFile)) { Path canonicalDest = destFile.makeQualified(fs); throw new IOException("Destination file " + canonicalDest + " already exists"); } OutputStream fsOut = fs.create(destFile); // Count how many actual bytes hit HDFS. this.countingFilterStream = new CountingOutputStream(fsOut); if (codec != null) { // Wrap that in a compressing stream. this.writeStream = codec.createOutputStream(this.countingFilterStream); } else { // Write to the counting stream directly. this.writeStream = this.countingFilterStream; } }
From source file:com.cloudera.sqoop.io.SplittingOutputStream.java
/** Initialize the OutputStream to the next file to write to. */// ww w . ja va2 s. c om private void openNextFile() throws IOException { FileSystem fs = FileSystem.get(conf); StringBuffer sb = new StringBuffer(); Formatter fmt = new Formatter(sb); fmt.format("%05d", this.fileNum++); String filename = filePrefix + fmt.toString(); if (this.doGzip) { filename = filename + ".gz"; } Path destFile = new Path(destDir, filename); LOG.debug("Opening next output file: " + destFile); if (fs.exists(destFile)) { Path canonicalDest = destFile.makeQualified(fs); throw new IOException("Destination file " + canonicalDest + " already exists"); } OutputStream fsOut = fs.create(destFile); // Count how many actual bytes hit HDFS. this.countingFilterStream = new CountingOutputStream(fsOut); if (this.doGzip) { // Wrap that in a Gzip stream. this.writeStream = new GZIPOutputStream(this.countingFilterStream); } else { // Write to the counting stream directly. this.writeStream = this.countingFilterStream; } }
From source file:com.itemanalysis.psychometrics.polycor.PolychoricTwoStepOLD.java
public String printThresholds() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); double r = this.value(); double[] t = this.getRowThresholds(); for (int i = 0; i < t.length - 1; i++) { f.format("% 6.4f", t[i]); f.format("%2s", ""); }/*from www . j ava 2s . c om*/ return f.toString(); }
From source file:ar.com.zauber.labs.kraken.providers.wikipedia.apps.administrative.ArgentinaDepartmentsSync.java
/** * Entrada de la tabla. 3 columnas: departamento, cabecera, partido. * // w ww. j a v a 2 s . co m * [[Departamento Alberdi]] / [[Campo Gallo]] / * [[Provincia de Santiago del Estero|Santiago del Estero]] */ public final void parseTableLine(final String l) { Validate.notNull(l); if (l.trim().length() != 0) { final String[] rows = l.split("/"); if (rows.length == 3) { try { parseTableLine(nullify(rows[0].trim()), nullify(rows[1].trim()), nullify(rows[2].trim())); } catch (final Throwable t) { logger.error("Procesing line " + lineNumber + ": " + t.getLocalizedMessage(), t); } } else { final StringBuilder sb = new StringBuilder(); new Formatter(sb).format("Procesing line %d: Expected 3 columns. Got %d. `%s'", lineNumber, rows.length, l); throw new IllegalArgumentException(sb.toString()); } } }
From source file:net.sourceforge.fenixedu.domain.candidacyProcess.Formation.java
public void exportValues(StringBuilder result) { Formatter formatter = new Formatter(result); formatter.format("\n%s:\n", BundleUtil.getString(Bundle.CANDIDATE, "title.other.academic.titles")); formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.other.academic.titles.program.name"), getDesignation());//from w w w. j a v a2s . c om formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.other.academic.titles.institution"), getInstitution().getName()); formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.other.academic.titles.conclusion.date"), StringUtils.isEmpty(getYear()) ? StringUtils.EMPTY : getYear()); formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.other.academic.titles.conclusion.grade"), StringUtils.isEmpty(getConclusionGrade()) ? StringUtils.EMPTY : getConclusionGrade()); formatter.close(); }