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:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.SampleGenerator.java

@Override
public void run(CommandLine commandLine) throws IOException {
    ParameterFile parameterFile = new ParameterFile(new File(commandLine.getOptionValue("parameterFile")));

    int N = Integer.parseInt(commandLine.getOptionValue("numberOfSamples"));
    int D = parameterFile.size();

    Sequence sequence = null;//from  w  w  w  .  j av  a 2s .c  o  m

    if (commandLine.hasOption("method")) {
        OptionCompleter completer = new OptionCompleter("uniform", "latin", "sobol", "saltelli");
        String method = completer.lookup(commandLine.getOptionValue("method"));

        if (method.equals("latin")) {
            sequence = new LatinHypercube();
        } else if (method.equals("sobol")) {
            sequence = new Sobol();
        } else if (method.equals("saltelli")) {
            N *= (2 * D + 2);
            sequence = new Saltelli();
        } else if (method.equals("uniform")) {
            sequence = new Uniform();
        } else {
            throw new IllegalArgumentException("invalid method: " + commandLine.getOptionValue("method"));
        }
    } else {
        sequence = new Sobol();
    }

    if (commandLine.hasOption("seed")) {
        PRNG.setSeed(Long.parseLong(commandLine.getOptionValue("seed")));
    }

    PrintStream output = System.out;

    try {
        if (commandLine.hasOption("output")) {
            output = new PrintStream(
                    new BufferedOutputStream(new FileOutputStream(commandLine.getOptionValue("output"))));
        }

        double[][] samples = sequence.generate(N, D);

        for (int i = 0; i < N; i++) {
            output.print(parameterFile.get(0).getLowerBound() + samples[i][0]
                    * (parameterFile.get(0).getUpperBound() - parameterFile.get(0).getLowerBound()));

            for (int j = 1; j < D; j++) {
                output.print(' ');
                output.print(parameterFile.get(j).getLowerBound() + samples[i][j]
                        * (parameterFile.get(j).getUpperBound() - parameterFile.get(j).getLowerBound()));
            }

            output.println();
        }
    } finally {
        if ((output != null) && (output != System.out)) {
            output.close();
        }
    }
}

From source file:com.liferay.blade.cli.command.CreateCommand.java

private void _printTemplates() throws Exception {
    BladeCLI bladeCLI = getBladeCLI();//from  w w w.  j  a v a 2s. co  m

    Map<String, String> templates = BladeUtil.getTemplates(bladeCLI);

    List<String> templateNames = new ArrayList<>(BladeUtil.getTemplateNames(getBladeCLI()));

    Collections.sort(templateNames);

    Comparator<String> compareLength = Comparator.comparingInt(String::length);

    Stream<String> stream = templateNames.stream();

    String longestString = stream.max(compareLength).get();

    int padLength = longestString.length() + 2;

    for (String name : templateNames) {
        PrintStream out = bladeCLI.out();

        out.print(StringUtils.rightPad(name, padLength));

        bladeCLI.out(templates.get(name));
    }
}

From source file:fi.jumi.core.stdout.SynchronizedPrintStreamTest.java

/**
 * For example {@link Throwable#printStackTrace} does this, we must be careful to always acquire a lock on the
 * monitor of the PrintStream first, before all other locks.
 *//*www .j  a  v a2  s  . c  o  m*/
@Test
public void does_not_deadlock_if_somebody_locks_in_the_PrintStream_externally() throws Exception {
    final int ITERATIONS = 10;
    PrintStream printStream = SynchronizedPrintStream.create(new NullOutputStream(), Charset.defaultCharset(),
            lock);

    // will fail with a test timeout if a deadlock happens
    runConcurrently(() -> {
        // what Thread.printStackTrace() would do
        synchronized (printStream) {
            for (int i = 0; i < ITERATIONS; i++) {
                Thread.yield();
                printStream.print("X");
            }
        }
    }, () -> {
        // what a normal printer would do
        for (int i = 0; i < ITERATIONS; i++) {
            Thread.yield();
            printStream.print("X");
        }
    });
}

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

@Test
public void shouldNotCreateDuplicateReport() throws Exception {

    ModuleActivator activator = new PacsIntegrationActivator();
    activator.started();/*from  w w w.j  a  v a2  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|||||||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:opendap.metacat.URLClassifier.java

private void printClassifications(PrintStream ps, boolean print_urls, boolean print_all_urls,
        boolean print_histogram) {
    Integer i = 0;/*from   w  w  w . j a  v a  2s. co m*/
    for (URLGroup group : groups) {
        ps.print(i.toString() + ": ");
        for (String comp : group.getClassifications().getLexemeArray())
            ps.print(comp + " ");
        ps.println();
        ++i;

        if (print_histogram) {
            Equivalences equivs = group.getEquivalences();
            for (Equivalence e : equivs) {
                String tm = new Integer(e.getTotalMembers()).toString();
                String dv = new Integer(e.getNumberOfValues()).toString();
                ps.println("\tEquivalence class: " + e.getPattern() + "; Total members: " + tm
                        + "; Discreet values: " + dv);
                if (e.getNumberDateClassifications() > 0) {
                    ps.print("\t\tFound a potential date:");
                    for (DatePart dp : e.getDateClassifications())
                        ps.print(" " + dp.toString());
                    ps.println();
                }
            }

            ps.println();
        }

        if (print_urls) {
            // Find the Equivalence with the most date parts; then sort and
            // print
            Equivalence date = group.getDateEquivalence();

            // Either print the sorted URLs or just print them
            if (date != null) {
                SortedValues sc = date.getSortedValues();
                if (print_all_urls) {
                    for (DateString comp : sc) {
                        ps.println("\t" + date.getParsedURL(comp.getDateString()).getTheURL());
                    }
                } else { // Just print the first and last URL
                    DateString first = sc.get(0);
                    DateString last = sc.get(sc.size() - 1);
                    ps.println("\t" + date.getParsedURL(first.getDateString()).getTheURL());
                    ps.println("\t" + date.getParsedURL(last.getDateString()).getTheURL());
                }
            } else {
                URLs urls = group.getURLs();
                if (print_all_urls) {
                    for (ParsedURL u : urls)
                        ps.println("\t" + u.getTheURL());
                } else {
                    ParsedURL first = urls.get(0);
                    ParsedURL last = urls.get(urls.size() - 1);
                    ps.println("\t" + first.getTheURL());
                    ps.println("\t" + last.getTheURL());
                }
            }
            ps.println();
        }
    }
}

From source file:com.analog.lyric.dimple.solvers.core.parameterizedMessages.DirichletParameters.java

@Override
public void print(PrintStream out, int verbosity) {
    if (verbosity >= 0) {
        out.print("Dirichlet(");
        for (int i = 0, end = getSize(); i < end; ++i) {
            if (i > 0) {
                out.print(',');
                if (verbosity > 1) {
                    out.print(' ');
                }/*w w  w . j  ava  2s  . c o  m*/
            }
            if (verbosity > 1) {
                out.format("a%d=", i);
            }
            out.format("%g", getAlpha(i));
        }
        out.print(')');
    }
}

From source file:beast.structuredCoalescent.distribution.ExactStructuredCoalescent.java

@Override
public void init(PrintStream out) {
    out.print("max_posterior\t");
    for (int i = 0; i < states * (states - 1); i++)
        out.print("max_mig_rate" + i + "\t");
    for (int i = 0; i < states; i++)
        out.print("max_coal_rate" + i + "\t");

}

From source file:beast.structuredCoalescent.distribution.ExactStructuredCoalescent.java

@Override
public void log(int nSample, PrintStream out) {
    out.print(max_posterior + "\t");
    for (int i = 0; i < states * (states - 1); i++)
        out.print(max_mig[i] + "\t");
    for (int i = 0; i < states; i++)
        out.print(max_coal[i] + "\t");

}

From source file:com.aliyun.odps.mapred.bridge.BridgeRunningJob.java

/**
 * Print job progress./*w ww. j  a  v a  2  s.  c o  m*/
 *
 * @throws IOException
 * @throws OdpsException
 *     if get task progress failed
 */
private void printProgress() throws OdpsException {
    PrintStream out = System.out;

    List<StageProgress> stages = null;
    stages = instance.getTaskProgress(taskName);

    if (stages != null && stages.size() != 0) {

        out.print(Instance.getStageProgressFormattedString(stages));

        int mappers = 0;
        int reducers = 0;
        mapProgress = 0;
        reduceProgress = 0;
        for (StageProgress stage : stages) {
            int totalWorkers = stage.getTotalWorkers();
            if (stage.getName().startsWith("M")) {
                mappers += totalWorkers;
                mapProgress += stage.getFinishedPercentage() / 100.0 * totalWorkers;
            } else {
                reducers += totalWorkers;
                reduceProgress += stage.getFinishedPercentage() / 100.0 * totalWorkers;
            }
        }
        mapProgress = mappers == 0 ? 0 : mapProgress / mappers;
        reduceProgress = reducers == 0 ? 0 : reduceProgress / reducers;
    } else {
        out.print("...");
    }
    out.print('\r');
    out.flush();
}

From source file:cdr.forms.SwordDepositHandler.java

private File makeZipFile(gov.loc.mets.DocumentRoot metsDocumentRoot,
        IdentityHashMap<DepositFile, String> filenames) {

    // Get the METS XML

    String metsXml = serializeMets(metsDocumentRoot);

    // Create the zip file

    File zipFile;/*from  ww w  . j  a  va  2  s .co m*/

    try {
        zipFile = File.createTempFile("tmp", ".zip");
    } catch (IOException e) {
        throw new Error(e);
    }

    FileOutputStream fileOutput;

    try {
        fileOutput = new FileOutputStream(zipFile);
    } catch (FileNotFoundException e) {
        throw new Error(e);
    }

    ZipOutputStream zipOutput = new ZipOutputStream(fileOutput);

    try {

        ZipEntry entry;

        // Write the METS

        entry = new ZipEntry("mets.xml");
        zipOutput.putNextEntry(entry);

        PrintStream xmlPrintStream = new PrintStream(zipOutput);
        xmlPrintStream.print(metsXml);

        // Write files

        for (DepositFile file : filenames.keySet()) {

            if (!file.isExternal()) {

                entry = new ZipEntry(filenames.get(file));
                zipOutput.putNextEntry(entry);

                FileInputStream fileInput = new FileInputStream(file.getFile());

                byte[] buffer = new byte[1024];
                int length;

                while ((length = fileInput.read(buffer)) != -1)
                    zipOutput.write(buffer, 0, length);

                fileInput.close();

            }

        }

        zipOutput.finish();
        zipOutput.close();

        fileOutput.close();

    } catch (IOException e) {

        throw new Error(e);

    }

    return zipFile;

}