Example usage for java.io PrintStream print

List of usage examples for java.io PrintStream print

Introduction

In this page you can find the example usage for java.io PrintStream print.

Prototype

public void print(Object obj) 

Source Link

Document

Prints an object.

Usage

From source file:org.corpus_tools.pepper.cli.ConvertWizardConsole.java

/**
 * Waits for a user input from passed input stream and returns it. If the
 * command "exit" was entered. null is returned.
 * // w  ww  .j  a  v a 2 s . c  o  m
 * @param in
 * @param out
 * @return
 */
private String getUserInput(BufferedReader in, PrintStream out) {
    String userInput = "";

    try {
        out.println();
        out.print(prompt);
        out.print(">");
        userInput = in.readLine();
        if (userInput != null) {
            userInput = userInput.trim();
        }
    } catch (IOException ioe) {
        out.println("Cannot read command.");
    }
    if (("exit".equalsIgnoreCase(userInput))) {
        throw new ExitWizardException();
    }
    return (userInput);
}

From source file:de.juwimm.cms.model.EditionHbmDaoImpl.java

@Override
protected void handleUnitsToXmlRecursive(Integer siteId, PrintStream out, EditionHbm edition) throws Exception {
    out.println("\t<units>");
    try {// w w  w .  j  ava2  s . c o  m
        Collection units = getUnitHbmDao().findAll(siteId);
        Iterator it = units.iterator();
        while (it.hasNext()) {
            UnitHbm unit = (UnitHbm) it.next();
            out.print(getUnitHbmDao().toXmlRecursive(2, unit));
        }
    } catch (Exception exe) {
        log.error("Error occured", exe);
    }
    out.println("\t</units>");

}

From source file:com.google.cloud.dataflow.sdk.runners.worker.TextReaderTest.java

@Test
public void testNonStringCoders() throws Exception {
    File tmpFile = tmpFolder.newFile();
    PrintStream writer = new PrintStream(new FileOutputStream(tmpFile));
    List<Integer> expected = TestUtils.INTS;
    List<Integer> expectedSizes = new ArrayList<>();
    for (Integer elem : expected) {
        byte[] encodedElem = CoderUtils.encodeToByteArray(TextualIntegerCoder.of(), elem);
        writer.print(elem);
        writer.print("\n");
        expectedSizes.add(1 + encodedElem.length);
    }//w  ww  .j  a va 2s  . c om
    writer.close();

    TextReader<Integer> textReader = new TextReader<>(tmpFile.getPath(), true, null, null,
            TextualIntegerCoder.of(), TextIO.CompressionType.UNCOMPRESSED);
    ExecutorTestUtils.TestReaderObserver observer = new ExecutorTestUtils.TestReaderObserver(textReader);

    List<Integer> actual = new ArrayList<>();
    try (Reader.ReaderIterator<Integer> iterator = textReader.iterator()) {
        while (iterator.hasNext()) {
            actual.add(iterator.next());
        }
    }

    assertEquals(expected, actual);
    assertEquals(expectedSizes, observer.getActualSizes());
}

From source file:de.juwimm.cms.model.EditionHbmDaoImpl.java

@Override
protected void handleHostsToXmlRecursive(Integer siteId, PrintStream out, EditionHbm edition) throws Exception {
    out.println("\t<hosts>");
    try {//from w  ww .  j  a v  a2  s .c o m
        Collection hostList = getHostHbmDao().findAll(siteId);
        Iterator it = hostList.iterator();
        while (it.hasNext()) {
            HostHbm host = (HostHbm) it.next();
            out.print(host.toXml(2));
        }
    } catch (Exception exe) {
        log.error("Error occured", exe);
    }
    out.println("\t</hosts>");

}

From source file:com.act.lcms.MS2.java

private void plot(MS2Collected Ams2Peaks, MS2Collected Bms2Peaks, Double mz, String outPrefix, String fmt)
        throws IOException {

    MS2Collected[] ms2Spectra = new MS2Collected[] { Ams2Peaks, Bms2Peaks };

    String outPDF = outPrefix + "." + fmt;
    String outDATA = outPrefix + ".data";

    // Write data output to outfile
    PrintStream out = new PrintStream(new FileOutputStream(outDATA));

    List<String> plotID = new ArrayList<>(ms2Spectra.length);
    for (MS2Collected yzSlice : ms2Spectra) {
        plotID.add(String.format("time: %.4f, volts: %.4f", yzSlice.triggerTime, yzSlice.voltage));
        // print out the spectra to outDATA
        for (YZ yz : yzSlice.ms2) {
            out.format("%.4f\t%.4f\n", yz.mz, yz.intensity);
            out.flush();//from   ww w  .j a  v a 2 s .  c o  m
        }
        // delimit this dataset from the rest
        out.print("\n\n");
    }

    // close the .data
    out.close();

    // render outDATA to outPDF using gnuplot
    // 105.0 here means 105% for the y-range of a [0%:100%] plot. We want to leave some buffer space at
    // at the top, and hence we go a little outside of the 100% max range.
    new Gnuplotter().plot2DImpulsesWithLabels(outDATA, outPDF, plotID.toArray(new String[plotID.size()]),
            mz + 50.0, "mz", 105.0, "intensity (%)", fmt);
}

From source file:org.csp.everyaware.internet.StoreAndForwardService.java

public static byte[] zipStringToBytes(String input) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    //BufferedOutputStream buffs = new BufferedOutputStream (new GZIPOutputStream (bos));

    //use PrintStream to avod converting a String into byte array, that can cause out of memory error
    final PrintStream printStream = new PrintStream(new GZIPOutputStream(bos));
    printStream.print(input);
    printStream.close();/*from ww w. j a  v  a 2 s . c o  m*/

    //buffs.write (input. getBytes ());
    //buffs.close ();

    byte[] retval = bos.toByteArray();
    bos.close();
    return retval;
}

From source file:org.broadinstitute.sting.analyzecovariates.AnalyzeCovariates.java

private void writeDataTables() {

    int numReadGroups = 0;

    // for each read group
    for (Object readGroupKey : dataManager.getCollapsedTable(0).data.keySet()) {

        if (NUM_READ_GROUPS_TO_PROCESS == -1 || ++numReadGroups <= NUM_READ_GROUPS_TO_PROCESS) {
            String readGroup = readGroupKey.toString();
            RecalDatum readGroupDatum = (RecalDatum) dataManager.getCollapsedTable(0).data.get(readGroupKey);
            logger.info(String.format(
                    "Writing out data tables for read group: %s\twith %s observations\tand aggregate residual error = %.3f",
                    readGroup, readGroupDatum.getNumObservations(),
                    readGroupDatum.empiricalQualDouble(0, MAX_QUALITY_SCORE)
                            - readGroupDatum.getEstimatedQReported()));

            // for each covariate
            for (int iii = 1; iii < requestedCovariates.size(); iii++) {
                Covariate cov = requestedCovariates.get(iii);

                // Create a PrintStream
                File outputFile = new File(OUTPUT_DIR,
                        readGroup + "." + cov.getClass().getSimpleName() + ".dat");
                PrintStream output;
                try {
                    output = new PrintStream(FileUtils.openOutputStream(outputFile));
                } catch (IOException e) {
                    throw new UserException.CouldNotCreateOutputFile(outputFile, e);
                }/*from   w  ww . j a va2  s.c om*/

                try {
                    // Output the header
                    output.println("Covariate\tQreported\tQempirical\tnMismatches\tnBases");

                    for (Object covariateKey : ((Map) dataManager.getCollapsedTable(iii).data.get(readGroupKey))
                            .keySet()) {
                        output.print(covariateKey.toString() + "\t"); // Covariate
                        RecalDatum thisDatum = (RecalDatum) ((Map) dataManager.getCollapsedTable(iii).data
                                .get(readGroupKey)).get(covariateKey);
                        output.print(String.format("%.3f", thisDatum.getEstimatedQReported()) + "\t"); // Qreported
                        output.print(String.format("%.3f", thisDatum.empiricalQualDouble(0, MAX_QUALITY_SCORE))
                                + "\t"); // Qempirical
                        output.print(thisDatum.getNumMismatches() + "\t"); // nMismatches
                        output.println(thisDatum.getNumObservations()); // nBases
                    }
                } finally {
                    // Close the PrintStream
                    IOUtils.closeQuietly(output);
                }
            }
        } else {
            break;
        }

    }
}

From source file:org.cytobank.acs.core.TableOfContents.java

/**
 * Writes out the XML that represents this <code>TableOfContents</code> to an <code>OutputStream</code>.
 *
 * @param outputStream the <code>OutputStream</code> to write out the xml to
 * @throws IOException If an input or output exception occurred
 * @throws InvalidIndexException If there is a problem with the <code>TableOfContents</code>
 *//*from  ww w  .j  a v a 2  s .  c o  m*/
public void writeXml(OutputStream outputStream) throws IOException, InvalidIndexException {
    PrintStream out = new PrintStream(outputStream, true);
    out.print(toXml());
}

From source file:de.juwimm.cms.model.EditionHbmDaoImpl.java

@Override
protected void handleViewdocumentsToXmlRecursive(Integer siteId, PrintStream out, EditionHbm edition)
        throws Exception {
    out.println("\t<viewDocuments>");
    try {//from  w  ww.j  a v a2s. c  o m
        Collection vdocs = getViewDocumentHbmDao().findAll(siteId);
        Iterator it = vdocs.iterator();
        while (it.hasNext()) {
            ViewDocumentHbm vdoc = (ViewDocumentHbm) it.next();
            out.print(vdoc.toXml(2));
        }
    } catch (Exception exe) {
        log.error("Error occured", exe);
    }
    out.println("\t</viewDocuments>");
}

From source file:edu.caltechUcla.sselCassel.projects.jMarkets.frontdesk.web.data.SessionBean.java

/** Save this object to the given path as a file */
public void serialize(String path) {
    try {// w  ww. j  a  va  2s . c  om
        File file = new File(path);
        file.createNewFile();

        FileOutputStream outStream = new FileOutputStream(file);
        PrintStream printer = new PrintStream(outStream);
        //ObjectOutputStream objStream = new ObjectOutputStream(outStream);

        log.info("Wrote session definition to xml");
        printer.print(this.toString());

        printer.flush();
        printer.close();

        //objStream.writeObject(xml);
        //objStream.close();
        outStream.close();
    } catch (IOException e) {
        System.out.println("IO error writing session to a file");
        e.printStackTrace();
    }
}