Example usage for java.io PrintStream PrintStream

List of usage examples for java.io PrintStream PrintStream

Introduction

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

Prototype

public PrintStream(File file) throws FileNotFoundException 

Source Link

Document

Creates a new print stream, without automatic line flushing, with the specified file.

Usage

From source file:hudson.cli.CopyJobCommandTest.java

@Test
public void copyBetweenFolders() throws Exception {
    MockFolder dir1 = j.createFolder("dir1");
    MockFolder dir2 = j.createFolder("dir2");
    FreeStyleProject p = dir1.createProject(FreeStyleProject.class, "p1");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PrintStream outS = new PrintStream(out);
    int result = new CopyJobCommand().main(Arrays.asList("dir1/p1", "dir2/p2"), Locale.ENGLISH,
            new NullInputStream(0), outS, outS);
    outS.flush();//from   w  w  w . ja  v a  2 s  .c  o m
    assertEquals(out.toString(), 0, result);
    assertEquals("", out.toString());
    assertNotNull(j.jenkins.getItemByFullName("dir2/p2"));
    // TODO test copying from/to root, or into nonexistent folder
}

From source file:com.mtnfog.idyl.e3.sdk.IdylE3StreamingClient.java

@Override
public EntityExtractionResponse stream(final String text) throws IOException {

    if (socket.isClosed()) {
        throw new IllegalStateException("The socket is closed.");
    }/*from  w ww.  ja v  a 2  s.c om*/

    PrintStream out = new PrintStream(socket.getOutputStream());
    BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

    out.print(text);

    String json = in.readLine();

    System.out.println(json);

    in.close();
    out.close();

    return gson.fromJson(json, EntityExtractionResponse.class);

}

From source file:hudson.cli.GetJobCommandTest.java

@Issue("JENKINS-20236")
@Test//from   w  w w.j a  v  a 2  s. c o  m
public void withFolders() throws Exception {
    MockFolder d = j.createFolder("d");
    FreeStyleProject p = d.createProject(FreeStyleProject.class, "p");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PrintStream outS = new PrintStream(out);
    int result = new GetJobCommand().main(Collections.singletonList("d/p"), Locale.ENGLISH,
            new NullInputStream(0), outS, outS);
    outS.flush();
    String output = out.toString();
    assertEquals(output, 0, result);
    assertEquals(p.getConfigFile().asString(), output);
    out = new ByteArrayOutputStream();
    outS = new PrintStream(out);
    result = new GetJobCommand().main(Collections.singletonList("d"), Locale.ENGLISH, new NullInputStream(0),
            outS, outS);
    outS.flush();
    output = out.toString();
    assertEquals(output, 0, result);
    assertEquals(d.getConfigFile().asString(), output);
}

From source file:at.ac.tuwien.big.moea.print.PopulationWriter.java

@Override
public String write(final Population population) {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final PrintStream ps = new PrintStream(baos);
    write(ps, population);/*from  ww  w  .  j  a va  2s  .c  om*/
    ps.close();
    try {
        return baos.toString("UTF-8");
    } catch (final UnsupportedEncodingException e) {
        return e.getMessage();
    }
}

From source file:avantssar.aslanpp.testing.BackendTask.java

public void run() {
    //int idx = 0;
    synchronized (nextIndex) {
        //idx = nextIndex;
        nextIndex++;//from w  w w .j av a  2 s . co  m
    }
    System.out.print("+");
    String runnerPrefix = FilenameUtils.removeExtension(aslanFile.getAbsolutePath()) + "."
            + runner.getName().replaceAll("[^a-zA-Z0-9]", "").toLowerCase();
    File outputFile = new File(runnerPrefix + ".output.txt");
    File errorsFile = new File(runnerPrefix + ".errors.txt");
    try {
        PrintStream captureOutput = new PrintStream(outputFile);
        PrintStream captureErrors = new PrintStream(errorsFile);
        // runner.purgeParameters();
        // for (String p : parameters) {
        // runner.addParameter(p);
        // }
        Verdict v = runner.analyze(aslanFile, parameters, captureOutput, captureErrors);
        captureOutput.close();
        captureErrors.close();
        outputFile = Tester.deleteIfZero(outputFile);
        errorsFile = Tester.deleteIfZero(errorsFile);
        ti.putVerdict(runner, v, outputFile, errorsFile);
    } catch (FileNotFoundException e) {
        ti.putVerdict(runner, Verdict.Error, null, null);
    }
    System.out.print("-");
}

From source file:com.tvh.infrastructure.openedge.Broker.java

public BrokerStatus getStatus() throws RemoteException {

    PrintStream nulloutput = new PrintStream(new NullOutputStream());
    PrintStream out = System.out;
    PrintStream err = System.err;
    int maxAgents = 0;
    int maxClients = 0;
    try {// w  w  w.j  a  v a  2 s .c  o m
        System.setOut(nulloutput);
        System.setErr(nulloutput);

        IChimeraRemoteCommand connect = server.connect(getBrokerName());
        int result = connect.runIt(new String[] { (type == BrokerType.ASBROKER ? "AS" : "WS"), "q" });
        if (connect.getSystemOutput().contains("(8313)")) {
            return new BrokerStatus(BrokerStatus.RunningStatus.STOPPED);
        }
        connect.runIt(new String[] { (type == BrokerType.ASBROKER ? "AS" : "WS"), "z", "maxSrvrInstance" });
        maxAgents = Integer.parseInt(connect.getStructuredSystemOutput().get("maxSrvrInstance").toString());
        connect.runIt(new String[] { (type == BrokerType.ASBROKER ? "AS" : "WS"), "z", "maxClientInstance" });
        maxClients = Integer.parseInt(connect.getStructuredSystemOutput().get("maxClientInstance").toString());

    } finally {
        System.setOut(out);
        System.setErr(err);
    }

    HashMap<Integer, String> labels = new HashMap<>(15);
    HashMap<String, String> values = new HashMap<>(15);
    ToolRemoteCmdDescriptor cmd = new ToolRemoteCmdDescriptor();

    ToolRemoteCmdStatus cmdStatus;
    cmd.makeGetSummaryStatusLblPkt((type == BrokerType.ASBROKER ? "AS." : "WS.") + getBrokerName());
    /*cmd.makeGetSummaryStatusDataPkt( (type == BrokerType.ASBROKER ? "AS." : "WS.") + getBrokerName() );*/
    ToolRemoteCmdStatus labelFetcher = remoteStub.getRemoteManageObject().doRemoteToolCmd(cmd);
    Enumeration summaryLabels = labelFetcher.fetchGetSummaryStatuslblStatus();
    if (summaryLabels != null) {

        int i = 0;
        while (summaryLabels.hasMoreElements()) {
            String label = (String) summaryLabels.nextElement();
            labels.put(i, label.trim());
            i++;
        }

        cmd.makeGetSummaryStatusDataPkt((type == BrokerType.ASBROKER ? "AS." : "WS.") + getBrokerName());
        ToolRemoteCmdStatus statusFetcher = remoteStub.getRemoteManageObject().doRemoteToolCmd(cmd);
        Enumeration summaryValues = statusFetcher.fetchGetSummaryStatusDataStatus();
        i = 0;
        while (summaryValues.hasMoreElements()) {
            String value = (String) summaryValues.nextElement();
            values.put(labels.get(i), value.trim());
            i++;
        }
    }
    return new BrokerStatus(values, maxAgents, maxClients);

}

From source file:com.seer.datacruncher.eventtrigger.DynamicJavaCompiler.java

public String compile(String srcFiles[]) {
    StringWriter err = new StringWriter();
    PrintWriter errPrinter = new PrintWriter(err);

    String args[] = buildJavacArgs(srcFiles);

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    int resultCode = compiler.run(null, System.out, ps, args);
    errPrinter.close();//from   w w  w  .  jav a2 s.  c  o  m
    String errorMsg = baos.toString();
    if (StringUtils.isNotEmpty(errorMsg)) {
        String[] eMsg = errorMsg.split("error:");
        errorMsg = eMsg[1];
    }
    return (resultCode == 0) ? null : errorMsg;
}

From source file:com.hazelcast.simulator.probes.probes.impl.HdrLatencyDistributionResult.java

@Override
public String toHumanString() {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PrintStream stream = new PrintStream(outputStream);
    histogram.outputPercentileDistribution(stream, 1.0);
    stream.flush();//from  w w  w .java  2 s  .  co m
    return new String(outputStream.toByteArray());
}

From source file:com.l2jfree.gameserver.util.GPLLicenseChecker.java

private static void parse(File f) throws IOException {
    System.out.println(f.getCanonicalPath());

    if (f.isDirectory()) {
        for (File tmp : f.listFiles(FILTER))
            parse(tmp);/*from w  w w  .ja  v  a 2 s  . com*/
    } else {
        List<String> tmpList = read(f);

        if (tmpList == null)
            return;

        ArrayList<String> list2 = new ArrayList<String>();

        for (String line : LICENSE)
            list2.add(line);

        boolean foundPackageDeclaration = false;
        for (String line : tmpList)
            if (foundPackageDeclaration |= containsPackageName(line))
                list2.add(line);

        PrintStream ps = null;
        try {
            ps = new PrintStream(f);

            for (String line : list2)
                ps.println(line);
        } finally {
            IOUtils.closeQuietly(ps);
        }
    }
}

From source file:com.adobe.acs.tools.csv.impl.CsvUtil.java

/**
 * Adds a populated terminating field to the ends of CSV entries.
 * If the last entry in a CSV row is empty, the CSV library has difficulty understanding that is the end of the row.
 *
 * @param is        the CSV file as an inputstream
 * @param separator The field separator/*from   w  w w.j av a 2 s  .  c  om*/
 * @param charset   The charset
 * @return An inputstream that is the same as is, but each line has a populated line termination entry
 * @throws IOException
 */
public static InputStream terminateLines(final InputStream is, final char separator, final String charset)
        throws IOException {

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final PrintStream printStream = new PrintStream(baos);

    final LineIterator lineIterator = IOUtils.lineIterator(is, charset);

    while (lineIterator.hasNext()) {
        String line = StringUtils.stripToNull(lineIterator.next());

        if (line != null) {
            line += separator + TERMINATED;
            printStream.println(line);
        }
    }

    return new ByteArrayInputStream(baos.toByteArray());
}