Example usage for java.io PrintStream flush

List of usage examples for java.io PrintStream flush

Introduction

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

Prototype

public void flush() 

Source Link

Document

Flushes the stream.

Usage

From source file:com.googlecode.clearnlp.component.AbstractStatisticalComponent.java

protected void saveDefaultConfiguration(ZipOutputStream zout, String entryName) throws Exception {
    zout.putNextEntry(new ZipEntry(entryName));
    PrintStream fout = UTOutput.createPrintBufferedStream(zout);
    LOG.info("Saving configuration.\n");

    fout.println(s_models.length);//from ww w.  j  a  v a  2 s  .  c  om

    fout.flush();
    zout.closeEntry();
}

From source file:com.panet.imeta.shared.SharedObjects.java

public void saveToFile() throws IOException, KettleException {
    OutputStream outputStream = KettleVFS.getOutputStream(filename, false);

    PrintStream out = new PrintStream(outputStream);

    out.print(XMLHandler.getXMLHeader(Const.XML_ENCODING));
    out.println("<" + XML_TAG + ">");

    Collection<SharedObjectInterface> collection = objectsMap.values();
    for (SharedObjectInterface sharedObject : collection) {
        out.println(sharedObject.getXML());
    }//from www.  j ava 2s . c  om

    out.println("</" + XML_TAG + ">");

    out.flush();
    out.close();
    outputStream.close();
}

From source file:io.takari.maven.testing.executor.ForkedLauncher.java

public int run(String[] cliArgs, Map<String, String> envVars, File multiModuleProjectDirectory,
        File workingDirectory, File logFile) throws IOException, LauncherException {
    String javaHome;//from w  w w . jav a2 s.c  o  m
    if (envVars == null || envVars.get("JAVA_HOME") == null) {
        javaHome = System.getProperty("java.home");
    } else {
        javaHome = envVars.get("JAVA_HOME");
    }

    File executable = new File(javaHome, Os.isFamily(Os.FAMILY_WINDOWS) ? "bin/javaw.exe" : "bin/java");

    CommandLine cli = new CommandLine(executable);
    cli.addArgument("-classpath").addArgument(classworldsJar.getAbsolutePath());
    cli.addArgument("-Dclassworlds.conf=" + new File(mavenHome, "bin/m2.conf").getAbsolutePath());
    cli.addArgument("-Dmaven.home=" + mavenHome.getAbsolutePath());
    cli.addArgument("-Dmaven.multiModuleProjectDirectory=" + multiModuleProjectDirectory.getAbsolutePath());
    cli.addArgument("org.codehaus.plexus.classworlds.launcher.Launcher");

    cli.addArguments(args.toArray(new String[args.size()]));
    if (extensions != null && !extensions.isEmpty()) {
        cli.addArgument("-Dmaven.ext.class.path=" + toPath(extensions));
    }

    cli.addArguments(cliArgs);

    Map<String, String> env = new HashMap<>();
    if (mavenHome != null) {
        env.put("M2_HOME", mavenHome.getAbsolutePath());
    }
    if (envVars != null) {
        env.putAll(envVars);
    }
    if (envVars == null || envVars.get("JAVA_HOME") == null) {
        env.put("JAVA_HOME", System.getProperty("java.home"));
    }

    DefaultExecutor executor = new DefaultExecutor();
    executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
    executor.setWorkingDirectory(workingDirectory.getAbsoluteFile());

    try (OutputStream log = new FileOutputStream(logFile)) {
        PrintStream out = new PrintStream(log);
        out.format("Maven Executor implementation: %s\n", getClass().getName());
        out.format("Maven home: %s\n", mavenHome);
        out.format("Build work directory: %s\n", workingDirectory);
        out.format("Environment: %s\n", env);
        out.format("Command line: %s\n\n", cli.toString());
        out.flush();

        PumpStreamHandler streamHandler = new PumpStreamHandler(log);
        executor.setStreamHandler(streamHandler);
        return executor.execute(cli, env); // this throws ExecuteException if process return code != 0
    } catch (ExecuteException e) {
        throw new LauncherException("Failed to run Maven: " + e.getMessage() + "\n" + cli, e);
    }
}

From source file:com.tamingtext.tagrecommender.TestStackOverflowTagger.java

/** Dump the overall metrics */
public void dumpStats(PrintStream out, int postCount, int totalSingleCorrect, int totalHalfCorrect) {
    out.println("evaluated " + postCount + " posts; " + totalSingleCorrect + " with one correct tag, "
            + totalHalfCorrect + " with half correct");

    out.print("\t %single correct: " + nf.format((totalSingleCorrect * 100) / (float) postCount));
    out.println(", %half correct: " + nf.format((totalHalfCorrect * 100) / (float) postCount));
    out.println();//w  ww  .  j  a  v a  2s  . com
    out.flush();
}

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

@Test
public void shouldNotCreateDuplicateReport() throws Exception {

    ModuleActivator activator = new PacsIntegrationActivator();
    activator.started();//from www . ja va2s. 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.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|||||||Test&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());

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

        Thread.sleep(2000);

        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));

    } finally {
        activator.stopped();
    }

}

From source file:org.codice.git.hook.Artifact.java

/**
 * Prompts for the blacklist artifact info.
 *
 * @param in  the reader to read user input from
 * @param out the output stream where to print messages to the user
 * @throws IOException if an error occurs
 *///from ww  w. jav  a  2s  .com
public void promptInfo(BufferedReader in, PrintStream out) throws IOException {
    this.mvnInfo = null;
    this.mvnName = null;
    LOGGER.log(Level.WARNING, "The {0} file was not found.", name);
    out.printf("%sThe %s file was not found%n", iprefix, name);
    out.printf("%sDo you wish to download it automatically (y/n) [Y]? ", iprefix);
    out.flush();
    final String yn = StringUtils.lowerCase(StringUtils.trim(in.readLine()));

    if (!yn.isEmpty() && (yn.charAt(0) == 'n')) {
        out.printf("%s You can always manually copy the file to: %n", iprefix);
        out.printf("%s    %n", iprefix, file);
        if (!infofile.exists()) { // make sure we no longer cache the info
            infofile.delete();
        }
        return;
    }
    out.println(iprefix);
    out.printf("%sPlease provide the maven artifact's coordinates for the %s file:%n", iprefix, name);
    final String email = handler.getConfigString("user", null, "email");
    String dgroup = null;

    if (StringUtils.isNotEmpty(email)) {
        final int i = email.indexOf('@');

        if (i != -1) {
            final String domain = email.substring(i + 1);
            final int j = domain.indexOf('.');

            if (j != -1) {
                dgroup = domain.substring(j + 1) + '.' + domain.substring(0, j);
            }
        }
    }
    String group;
    final String id;
    final String version;
    final String type;
    final String classifier;

    do {
        if (dgroup == null) {
            do {
                out.printf("%s   group id: ", iprefix);
                out.flush();
                group = StringUtils.trim(in.readLine());
            } while (StringUtils.isEmpty(group));
        } else {
            out.printf("%s   group id [%s]: ", iprefix, dgroup);
            out.flush();
            group = StringUtils.defaultIfBlank(StringUtils.trim(in.readLine()), dgroup);
        }
    } while (StringUtils.isEmpty(group));
    out.printf("%s   artifact id [blacklist-words]: ", iprefix);
    out.flush();
    id = StringUtils.defaultIfBlank(StringUtils.trim(in.readLine()), "blacklist-words");
    out.printf("%s   version [RELEASE]: ", iprefix);
    out.flush();
    version = StringUtils.defaultIfBlank(StringUtils.trim(in.readLine()), "RELEASE");
    out.printf("%s   type [txt]: ", iprefix);
    out.flush();
    type = StringUtils.defaultIfBlank(StringUtils.trim(in.readLine()), "txt");
    out.printf("%s   classifier []: ", iprefix);
    out.flush();
    classifier = StringUtils.trim(in.readLine());
    this.mvnInfo = group + ':' + id + ':' + version + ':' + type;

    if (StringUtils.isNotEmpty(classifier)) {
        this.mvnInfo += ':' + classifier;
    }
    this.mvnName = id + '.' + type;
}

From source file:com.googlecode.clearnlp.component.AbstractStatisticalComponent.java

/** Called by {@link AbstractStatisticalComponent#saveModels(ZipOutputStream)}}. */
protected void saveStatisticalModels(ZipOutputStream zout, String entryName) throws Exception {
    int i, size = s_models.length;
    PrintStream fout;

    for (i = 0; i < size; i++) {
        zout.putNextEntry(new ZipEntry(entryName + i));
        fout = UTOutput.createPrintBufferedStream(zout);
        s_models[i].save(fout);//w  ww  . j a v  a 2s  . c  o  m
        fout.flush();
        zout.closeEntry();
    }
}

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

@Test
public void shouldNotImportORM_001MessageWithDuplicateOrderNumber() throws Exception {

    ModuleActivator activator = new PacsIntegrationActivator();
    activator.started();//  ww  w .  ja  v 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.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:org.openmrs.module.pacsintegration.component.HL7ListenerComponentTest.java

@Test
public void shouldListenForAndParseORU_R01Message() throws Exception {

    ModuleActivator activator = new PacsIntegrationActivator();
    activator.started();//w w w .  j a  v 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();// www .  ja  va  2s.  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();
    }

}