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:master.outputs.JsonOutput.java

@Override
public void initAndValidate() {
    try {//w w  w  . j  a v a 2s.com
        pstream = new PrintStream(fileNameInput.get());
    } catch (FileNotFoundException e) {
        throw new RuntimeException("File " + fileNameInput.get() + " not found.");
    }
}

From source file:net.sourceforge.atunes.kernel.modules.player.vlcplayer.VlcTelnetClient.java

protected VlcTelnetClient(String newServer, int newPort) throws VlcTelnetClientException {

    // wait a title time for vlc process to be created 
    try {/*from w w  w.  j  a v  a  2 s .c o m*/
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        //we do nothing special
        //e.printStackTrace();
    }

    // Connect to the specified server
    logger.debug(LogCategories.NETWORK,
            "VlcTelnetClient : Connecting to port : " + newPort + " on server : " + newServer);

    try {
        telnet.connect(newServer, newPort);
    } catch (SocketException se) {
        se.printStackTrace();
        throw new VlcTelnetClientException(
                "Error while connecting to : " + newServer + " on : " + newPort + " : " + se.toString(), se);
    } catch (IOException ioe) {
        ioe.printStackTrace();
        throw new VlcTelnetClientException(
                "Error while connecting to : " + newServer + " on : " + newPort + " : " + ioe.toString(), ioe);
    }

    // Get input and output stream references
    try {
        in = telnet.getInputStream();
        out = new PrintStream(telnet.getOutputStream());
        //throw new Exception("Can't write or read form telnet client");
    } catch (Exception ex) {
        throw new VlcTelnetClientException("Can't write or read form telnet client", ex);
    }

}

From source file:jetbrains.exodus.sshd.RhinoCommand.java

@Override
public void setErrorStream(OutputStream err) {
    this.err = new PrintStream(err);
}

From source file:com.palantir.atlasdb.cli.runner.AbstractTestRunner.java

@Override
public String run(boolean failOnNonZeroExit, boolean singleLine) {
    PrintStream ps = System.out;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    System.setOut(new PrintStream(baos));
    try {// ww w. ja va 2s  .  c om
        int ret = cmd.execute(services);
        if (ret != 0 && failOnNonZeroExit) {
            throw new RuntimeException("CLI returned with nonzero exit code");
        }
    } finally {
        System.setOut(ps);
    }
    return singleLine ? baos.toString().replace("\n", " ").replace("\r", " ") : baos.toString();
}

From source file:Base64EncodeStream.java

public Base64EncodeStream(OutputStream out) {
    this.out = new PrintStream(out);
    closeOutOnClose = true;
}

From source file:de.weltraumschaf.groundzero.opt.commons.CommonsImplementation.java

@Override
public String help() {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    CONFIGURATION.format(HELP_FORMATTER, new PrintStream(out));
    return out.toString();
}

From source file:XMLWriter.java

/**
 * @param out : OutputStream
 */
public XMLWriter(OutputStream out) {
    this(new PrintStream(out));
}

From source file:net.gbmb.collector.example.SimpleLogPush.java

private String storeArchive(Collection collection) throws IOException {
    String cid = collection.getId();
    java.util.Collection<CollectionRecord> records = collectionRecords.get(cid);

    // index//  w  w w. jav  a 2 s .c  o m
    ByteArrayOutputStream indexStream = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE);
    PrintStream output = new PrintStream(indexStream);
    // zip
    ByteArrayOutputStream archiveStream = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE);
    ZipOutputStream zos = new ZipOutputStream(archiveStream);
    output.println("Serialize collection: " + collection.getId());
    output.println("  creation date: " + collection.getCreationDate());
    output.println("  end date:      " + collection.getEndDate());
    for (CollectionRecord cr : records) {
        output.print(cr.getRecordDate());
        output.print(" ");
        output.println(cr.getContent());
        if (cr.getAttachment() != null) {
            String attName = cr.getAttachment();
            output.println("  > " + attName);
            ZipEntry entry = new ZipEntry(cr.getAttachment());
            zos.putNextEntry(entry);
            InputStream content = temporaryStorage.get(cid, attName);
            IOUtils.copy(content, zos);
        }
    }
    // add the index file
    output.close();
    ZipEntry index = new ZipEntry("index");
    zos.putNextEntry(index);
    IOUtils.write(indexStream.toByteArray(), zos);
    // close zip
    zos.close();
    ByteArrayInputStream content = new ByteArrayInputStream(archiveStream.toByteArray());

    // send to final storage
    return finalStorage.store(cid, content);
}

From source file:eu.europa.ec.fisheries.uvms.plugins.inmarsat.twostage.Connect.java

public String connect(PollType poll, String path, String url, String port, String user, String psw, String dnid)
        throws TelnetException {

    String response = null;//from ww w  . jav  a 2  s . c o m
    try {
        TelnetClient telnet = new TelnetClient();

        telnet.connect(url, Integer.parseInt(port));
        BufferedInputStream input = new BufferedInputStream(telnet.getInputStream());
        PrintStream output = new PrintStream(telnet.getOutputStream());

        readUntil("name:", input, null, url, port);
        write(user, output);
        readUntil("word:", input, null, url, port);
        sendPsw(output, psw);
        readUntil(">", input, null, url, port);

        response = issueCommand(poll, output, input, dnid, path, url, port);

        if (telnet.isConnected()) {
            telnet.disconnect();
        }
    } catch (IOException ex) {
        LOG.error("Error when communicating with Telnet", ex);
    } catch (NullPointerException ex) {
        throw new TelnetException(ex);
    }
    return response;
}

From source file:de.unisb.cs.st.javalanche.rhino.RhinoTestRunnable.java

public void run() {
    List<String> argList = getArgs();
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final ByteArrayOutputStream err = new ByteArrayOutputStream();

    String[] arguments = argList.toArray(new String[0]);
    try {//from   www.j  a  v  a2 s  . c  o  m
        stopWatch.start();
        exitCode = WrappedMain.wrappedExec(arguments, new PrintStream(out), new PrintStream(err));

    } catch (Throwable t) {
        String message = "Caught exception during mutation testing. Exception is most probably caused by the mutation";
        logger.warn(message, t);
        logger.warn(t.toString() + " " + Arrays.toString(t.getStackTrace()));
        exitCode = -1;
    } finally {
        stopWatch.stop();
    }
    byte[] outByteArray = out.toByteArray();
    outString = new String(outByteArray);
    byte[] errByteArray = err.toByteArray();
    errString = new String(errByteArray);
    synchronized (this) {
        hasRun = true;
    }
    logger.info("Runnable finsihed  Took " + DurationFormatUtils.formatDurationHMS(stopWatch.getTime())
            + " \nOUT:\n" + outString + " \nERR\n" + errString);
}