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:com.ning.metrics.collector.processing.db.DatabaseCounterStorage.java

/**
 * serialize the given rolled-up counter data's distribution to a byte
 * array for storage in a blob/* w  w  w.  j  av  a2  s .c om*/
 * @param counter
 * @return
 * @throws java.io.IOException technically, but unlikely because all ops are
 *          in memory
 */
public static byte[] serializeDistribution(RolledUpCounterData counter) throws IOException {

    ByteArrayOutputStream result = new ByteArrayOutputStream();
    GZIPOutputStream zipStream = new GZIPOutputStream(result);
    PrintStream printer = new PrintStream(zipStream, true, "UTF-8");

    int index = 0;

    // iterate through all the entries in the distribution and generate a
    // serialization of the form:
    //
    // uniqueId1|count1\n
    // uniqueId2|count2\n
    // ...
    //
    // and then gzip the result into a byte array
    for (Map.Entry<String, Integer> entry : counter.getDistribution().entrySet()) {
        String id = entry.getKey();
        int value = entry.getValue() == null ? 0 : entry.getValue();

        // Don't write unique ids that have a zero count
        if (value == 0) {
            continue;
        }

        if (index++ > 0) {
            printer.println();
        }

        printer.print(id);
        printer.print('|');
        printer.print(Integer.toString(value));
    }

    zipStream.finish();
    printer.close();

    return result.toByteArray();
}

From source file:com.ripariandata.timberwolf.conf4j.ConfigFileParser.java

/**
 * Prints usage information for the config entries to the given stream.
 * Wraps usage information to 80 characters wide.
 * <p>//from ww  w .  j  av  a 2  s .c  om
 * Example output:
 * <pre>
 * my.property          - This is how to use this property.
 *
 * longer.property.name - All the hyphens line up.
 *
 * long.usage           - Long usage descriptions will wrap at 80 characters wide
 *                        and remain lined up like this.
 * </pre>
 */
public void printUsage(final PrintStream out) {
    out.println("Valid properties in the configuration file:");

    int longestNameLength = 0;
    for (ConfigEntry entry : entries) {
        if (entry.name().length() > longestNameLength) {
            longestNameLength = entry.name().length();
        }
    }

    for (ConfigEntry entry : entries) {
        out.print(entry.name());
        out.print(ofChars(' ', longestNameLength - entry.name().length()));
        String separator = " - ";
        out.print(separator);
        out.println(splitAndPad(entry.usage(), DEFAULT_OUTPUT_WIDTH,
                DEFAULT_OUTPUT_WIDTH - longestNameLength - separator.length()));
    }
}

From source file:com.github.lindenb.jvarkit.tools.backlocate.BackLocate.java

@Override
public Collection<Throwable> call() throws Exception {
    final List<String> args = this.getInputFiles();
    PrintStream out = null;
    try {/*from w  w w .java2  s.  c om*/

        out = this.openFileOrStdoutAsPrintStream();

        out.print("#User.Gene");
        out.print('\t');
        out.print("AA1");
        out.print('\t');
        out.print("petide.pos.1");
        out.print('\t');
        out.print("AA2");
        out.print('\t');
        out.print("knownGene.name");
        out.print('\t');
        out.print("knownGene.strand");
        out.print('\t');
        out.print("knownGene.AA");
        out.print('\t');
        out.print("index0.in.rna");
        out.print('\t');
        out.print("wild.codon");
        out.print('\t');
        out.print("potential.var.codons");
        out.print('\t');
        out.print("base.in.rna");
        out.print('\t');
        out.print("chromosome");
        out.print('\t');
        out.print("index0.in.genomic");
        out.print('\t');
        out.print("exon");
        if (this.printSequences) {
            out.print('\t');
            out.print("mRNA");
            out.print('\t');
            out.print("protein");
        }
        out.println();
        if (args.isEmpty()) {
            LOG.info("reading from stdin");
            LineIterator in = IOUtils.openStdinForLineIterator();
            this.run(out, in);
            CloserUtil.close(in);
        } else {
            for (String filename : args) {
                LOG.info("reading from " + filename);
                LineIterator in = IOUtils.openURIForLineIterator(filename);
                this.run(out, in);
                CloserUtil.close(in);
            }
        }
        return RETURN_OK;
    } catch (Exception e) {
        return wrapException(e);
    } finally {
        CloserUtil.close(out);
    }
}

From source file:org.debian.paulliu.kajiradoubra.controller.KajiraDouBraController.java

public void sendBluetoothData(String s) {
    java.io.PrintStream outputStream = null;
    try {//w w w. j av  a2s.  c  o m
        outputStream = new java.io.PrintStream(mBluetoothSocket.getOutputStream());
    } catch (java.io.IOException e) {
        Log.w(LOGTAG, "Cannot get outputStream from BluetoothSocket");
    }

    if (outputStream != null) {
        outputStream.print(s);
        outputStream.flush();
    } else {
        Log.w(LOGTAG, "Bluetooth outputStream is null");
    }
}

From source file:org.openmrs.module.pacsintegration.component.HL7ListenerComponentTest.java

@Test
public void shouldNotImportORM_001MessageWithDuplicateOrderNumber() throws Exception {

    ModuleActivator activator = new PacsIntegrationActivator();
    activator.started();//from  ww  w  .j a  v a 2 s .  co  m
    Context.getService(PacsIntegrationService.class).initializeHL7Listener();

    List<Patient> patients = patientService.getPatients(null, "101-6",
            Collections.singletonList(emrApiProperties.getPrimaryIdentifierType()), true);
    assertThat(patients.size(), is(1)); // sanity check
    Patient patient = patients.get(0);
    List<Encounter> encounters = encounterService.getEncounters(patient, null, null, null, null,
            Collections.singletonList(radiologyProperties.getRadiologyStudyEncounterType()), null, null, null,
            false);
    assertThat(encounters.size(), is(0)); // sanity check

    try {

        String message = "MSH|^~\\&|HMI||RAD|REPORTS|20130228174643||ORM^O01|RTS01CE16057B105AC0|P|2.3|\r"
                + "PID|1||101-6||Patient^Test^||19770222|M||||||||||\r" + "ORC|\r"
                + "OBR|1||0000001297|127689^SOME_X-RAY|||20130228170350||||||||||||MBL^CR||||||P|||||||&Goodrich&Mark&&&&||||20130228170350\r"
                + "OBX|1|RP|||||||||F\r" + "OBX|2|TX|EventType^EventType|1|REVIEWED\r"
                + "OBX|3|CN|Technologist^Technologist|1|1435^Duck^Donald\r"
                + "OBX|4|TX|ExamRoom^ExamRoom|1|100AcreWoods\r"
                + "OBX|5|TS|StartDateTime^StartDateTime|1|20111009215317\r"
                + "OBX|6|TS|StopDateTime^StopDateTime|1|20111009215817\r"
                + "OBX|7|TX|ImagesAvailable^ImagesAvailable|1|1\r"
                + "ZDS|2.16.840.1.113883.3.234.1.3.101.1.2.1013.2011.15607503.2^HMI^Application^DICOM\r";

        Thread.sleep(2000); // give the simple server time to start

        Socket socket = new Socket("127.0.0.1", 6665);

        PrintStream writer = new PrintStream(socket.getOutputStream());

        // send the message twice
        for (int i = 0; i < 2; i++) {
            writer.print(header);
            writer.print(message);
            writer.print(trailer + "\r");
            writer.flush();
        }

        Thread.sleep(2000);

        // confirm that only one encounter has been created
        encounters = encounterService.getEncounters(patient, null, null, null, null,
                Collections.singletonList(radiologyProperties.getRadiologyStudyEncounterType()), null, null,
                null, false);
        assertThat(encounters.size(), is(1));

    } finally {
        activator.stopped();
    }

}

From source file:hu.bme.mit.sette.GeneratorUI.java

public void run(BufferedReader in, PrintStream out) throws Exception {
    // directories
    File snippetProjectDir = generator.getSnippetProjectSettings().getBaseDirectory();
    File runnerProjectDir = generator.getRunnerProjectSettings().getBaseDirectory();

    out.println("Snippet project: " + snippetProjectDir);
    out.println("Runner project: " + runnerProjectDir);

    // backup output directory if it exists
    if (runnerProjectDir.exists()) {
        out.print(
                "The output directory exists. It will be deleted before generation. Would you like to make a backup? [yes] ");

        String line = in.readLine();

        if (line == null) {
            out.println("EOF detected, exiting");
            return;
        }/*from www .j  a v  a2  s.  c o  m*/

        if (!line.trim().equalsIgnoreCase("no")) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH;mm;ss");

            File backup = new File(runnerProjectDir.getParentFile(),
                    runnerProjectDir.getName() + "-backup-" + dateFormat.format(new Date())).getCanonicalFile();

            if (runnerProjectDir.renameTo(backup)) {
                out.println("Backup location: " + backup);
            } else {
                out.println("Backup failed, exiting");
                return;
            }
        }
    }

    try {
        // generate runner project
        out.println("Starting generation");
        FileUtils.deleteDirectory(runnerProjectDir);
        generator.generate();
        out.println("Generation successful");
    } catch (Exception e) {
        out.println("Generation failed: " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.openmrs.module.pacsintegration.component.HL7ListenerComponentTest.java

@Test
public void shouldListenForAndParseORU_R01Message() throws Exception {

    ModuleActivator activator = new PacsIntegrationActivator();
    activator.started();/*from  w ww. j  av a 2 s . c o  m*/
    Context.getService(PacsIntegrationService.class).initializeHL7Listener();

    List<Patient> patients = patientService.getPatients(null, "101-6",
            Collections.singletonList(emrApiProperties.getPrimaryIdentifierType()), true);
    assertThat(patients.size(), is(1)); // sanity check
    Patient patient = patients.get(0);
    List<Encounter> encounters = encounterService.getEncounters(patient, null, null, null, null,
            Collections.singletonList(radiologyProperties.getRadiologyReportEncounterType()), null, null, null,
            false);
    assertThat(encounters.size(), is(0)); // sanity check

    try {
        String message = "MSH|^~\\&|HMI|Mirebalais Hospital|RAD|REPORTS|20130228174549||ORU^R01|RTS01CE16055AAF5290|P|2.3|\r"
                + "PID|1||101-6||Patient^Test^||19770222|M||||||||||\r" + "PV1|1||||||||||||||||||\r"
                + "OBR|1||0000001297|127689^SOME_X-RAY|||20130228170556||||||||||||MBL^CR||||||F|||||||M123&Goodrich&Mark&&&&||||20130228170556\r"
                + "OBX|1|TX|127689^SOME_X-RAY||Clinical Indication: ||||||F\r";

        Thread.sleep(2000); // give the simple server time to start

        Socket socket = new Socket("127.0.0.1", 6665);

        PrintStream writer = new PrintStream(socket.getOutputStream());
        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        writer.print(header);
        writer.print(message);
        writer.print(trailer + "\r");
        writer.flush();

        Thread.sleep(2000);

        // confirm that report encounter has been created and has obs (we more thoroughly test the handler in the ORU_R01 handler and Radiology Service (in emr module) tests)
        encounters = encounterService.getEncounters(patient, null, null, null, null,
                Collections.singletonList(radiologyProperties.getRadiologyReportEncounterType()), null, null,
                null, false);
        assertThat(encounters.size(), is(1));
        assertThat(encounters.get(0).getObs().size(), is(4));

        // confirm that the proper ack is sent out
        String response = reader.readLine();
        assertThat(response, containsString("|ACK|"));
    } finally {
        activator.stopped();
    }

}

From source file:org.openmrs.module.pacsintegration.component.HL7ListenerComponentTest.java

@Test
public void shouldListenForAndParseORU_R01MessageMissingProcedureCode() throws Exception {

    ModuleActivator activator = new PacsIntegrationActivator();
    activator.started();/*from   w  ww  .  ja  va2  s. c  o m*/
    Context.getService(PacsIntegrationService.class).initializeHL7Listener();

    List<Patient> patients = patientService.getPatients(null, "101-6",
            Collections.singletonList(emrApiProperties.getPrimaryIdentifierType()), true);
    assertThat(patients.size(), is(1)); // sanity check
    Patient patient = patients.get(0);
    List<Encounter> encounters = encounterService.getEncounters(patient, null, null, null, null,
            Collections.singletonList(radiologyProperties.getRadiologyReportEncounterType()), null, null, null,
            false);
    assertThat(encounters.size(), is(0)); // sanity check

    try {
        String message = "MSH|^~\\&|HMI|Mirebalais Hospital|RAD|REPORTS|20130228174549||ORU^R01|RTS01CE16055AAF5290|P|2.3|\r"
                + "PID|1||101-6||Patient^Test^||19770222|M||||||||||\r" + "PV1|1||||||||||||||||||\r"
                + "OBR|1||0000001297||||20130228170556||||||||||||MBL^CR||||||F|||||||M123&Goodrich&Mark&&&&||||20130228170556\r"
                + "OBX|1|TX|127689^SOME_X-RAY||Clinical Indication: ||||||F\r";

        Thread.sleep(2000); // give the simple server time to start

        Socket socket = new Socket("127.0.0.1", 6665);

        PrintStream writer = new PrintStream(socket.getOutputStream());
        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        writer.print(header);
        writer.print(message);
        writer.print(trailer + "\r");
        writer.flush();

        Thread.sleep(2000);

        // confirm that report encounter has been created and has obs (we more thoroughly test the handler in the ORU_R01 handler and Radiology Service (in emr module) tests)
        encounters = encounterService.getEncounters(patient, null, null, null, null,
                Collections.singletonList(radiologyProperties.getRadiologyReportEncounterType()), null, null,
                null, false);
        assertThat(encounters.size(), is(1));
        assertThat(encounters.get(0).getObs().size(), is(3)); // only 3 because no procedure obs

        // confirm that the proper ack is sent out
        String response = reader.readLine();
        assertThat(response, containsString("|ACK|"));
    } finally {
        activator.stopped();
    }

}

From source file:com.ning.billing.beatrix.osgi.SetupBundleWithAssertion.java

private void createConfigFile(final PluginJavaConfig pluginConfig) throws IOException {

    PrintStream printStream = null;
    try {/*from   w ww . j ava  2s  . c om*/
        final File configFile = new File(pluginConfig.getPluginVersionRoot(),
                config.getOSGIKillbillPropertyName());
        configFile.createNewFile();
        printStream = new PrintStream(new FileOutputStream(configFile));
        printStream.print("pluginType=" + PluginType.NOTIFICATION);
    } finally {
        if (printStream != null) {
            printStream.close();
        }
    }
}

From source file:org.openmrs.module.pacsintegration.component.HL7ListenerComponentTest.java

@Test
public void shouldListenForAndParseORM_001Message() throws Exception {

    ModuleActivator activator = new PacsIntegrationActivator();
    activator.started();//ww w  .  j a  v  a2 s.  co m
    Context.getService(PacsIntegrationService.class).initializeHL7Listener();

    List<Patient> patients = patientService.getPatients(null, "101-6",
            Collections.singletonList(emrApiProperties.getPrimaryIdentifierType()), true);
    assertThat(patients.size(), is(1)); // sanity check
    Patient patient = patients.get(0);
    List<Encounter> encounters = encounterService.getEncounters(patient, null, null, null, null,
            Collections.singletonList(radiologyProperties.getRadiologyStudyEncounterType()), null, null, null,
            false);
    assertThat(encounters.size(), is(0)); // sanity check

    try {

        String message = "MSH|^~\\&|HMI||RAD|REPORTS|20130228174643||ORM^O01|RTS01CE16057B105AC0|P|2.3|\r"
                + "PID|1||101-6||Patient^Test^||19770222|M||||||||||\r" + "ORC|\r"
                + "OBR|1||0000001297|127689^SOME_X-RAY|||20130228170350||||||||||||MBL^CR||||||P|||||||&Goodrich&Mark&&&&^||||20130228170350\r"
                + "OBX|1|RP|||||||||F\r" + "OBX|2|TX|EventType^EventType|1|REVIEWED\r"
                + "OBX|3|CN|Technologist^Technologist|1|1435^Duck^Donald\r"
                + "OBX|4|TX|ExamRoom^ExamRoom|1|100AcreWoods\r"
                + "OBX|5|TS|StartDateTime^StartDateTime|1|20111009215317\r"
                + "OBX|6|TS|StopDateTime^StopDateTime|1|20111009215817\r"
                + "OBX|7|TX|ImagesAvailable^ImagesAvailable|1|1\r"
                + "ZDS|2.16.840.1.113883.3.234.1.3.101.1.2.1013.2011.15607503.2^HMI^Application^DICOM\r";

        Thread.sleep(2000); // give the simple server time to start

        Socket socket = new Socket("127.0.0.1", 6665);

        PrintStream writer = new PrintStream(socket.getOutputStream());
        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        writer.print(header);
        writer.print(message);
        writer.print(trailer + "\r");
        writer.flush();

        Thread.sleep(2000);

        // confirm that study encounter has been created and has obs (we more thoroughly test the handler in the ORU_R01 handler and Radiology Service (in emr module) tests)
        encounters = encounterService.getEncounters(patient, null, null, null, null,
                Collections.singletonList(radiologyProperties.getRadiologyStudyEncounterType()), null, null,
                null, false);
        assertThat(encounters.size(), is(1));
        assertThat(encounters.get(0).getObs().size(), is(3));

        // confirm that the proper ack is sent out
        String response = reader.readLine();
        assertThat(response, containsString("|ACK|"));
    } finally {
        activator.stopped();
    }

}