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:com.filelocker.gui.Events.java

public void make() {
    //      PrintStream oldOut = System.out;

    PrintStream printStream = new PrintStream(new OutputStream() {
        @Override/*from w  w  w. jav  a  2s.  c  o m*/
        public void write(byte[] buffer, int offset, int length) throws IOException {
            final String text = new String(buffer, offset, length);
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    vNotificationArea.append(text);
                }
            });
        }

        @Override
        public void write(int b) throws IOException {
            write(new byte[] { (byte) b }, 0, 1);
        }

    });
    System.setOut(printStream);

    vPasswordField.setEchoChar('#');
    vPasswordLabel.setFont(bigFont);
    vBrowseLabel.setFont(bigFont);
    vNotificationArea.setVisible(false);
    vNotificationArea.setEditable(false);
    vScroller.setVisible(false);
    vScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    vScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    vPanel = new JPanel();
    vPanel.add(vLockButton);
    vPanel.add(vCloseButton);
    vFrame.getContentPane().add(BorderLayout.SOUTH, vPanel);

    vPanel = new JPanel();
    vPanel.add(vPasswordLabel);
    vPanel.add(vPasswordField);
    vPanel.add(vBrowseLabel);
    vPanel.add(vBrowseField);
    vPanel.add(vBrowseButton);
    vPanel.add(vScroller);
    //      vPanel.setLayout (new BoxLayout (vPanel, BoxLayout.Y_AXIS));
    vFrame.getContentPane().add(BorderLayout.CENTER, vPanel);

    vLockButton.addActionListener(new vLockButton_Click());
    vCloseButton.addActionListener(new vCloseButton_Click());

    vBrowseButton.addActionListener(new vBrowseButton_Click());

}

From source file:Base64EncodeStream.java

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

From source file:playground.dgrether.analysis.categoryhistogram.CategoryHistogramWriter.java

public void writeCsv(CategoryHistogram histo, String filename) {
    PrintStream stream;/*from w  w w . j  a va2s .  c  o  m*/
    try {
        stream = new PrintStream(new File(filename + ".csv"));
    } catch (FileNotFoundException e) {
        throw new IllegalArgumentException("Filename " + filename + " is not found", e);
    }
    write(histo, stream);
    stream.close();
}

From source file:playground.christoph.evacuation.analysis.AgentsInEvacuationAreaActivityWriter.java

/**
 * Writes the gathered data tab-separated into a text file.
 *
 * @param filename The name of a file where to write the gathered data.
 *//*from   w w  w .  j a  v  a  2 s.c  o  m*/
public void write(final String filename, int[] activities, int[] activitiesParticipatingAtHome,
        int[] activitiesParticipatingNotAtHome, int[] activitiesNotParticipatingAtHome,
        int[] activitiesNotParticipatingNotAtHome) {
    PrintStream stream;
    try {
        stream = new PrintStream(new File(filename));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return;
    }
    write(stream, activities, activitiesParticipatingAtHome, activitiesParticipatingNotAtHome,
            activitiesNotParticipatingAtHome, activitiesNotParticipatingNotAtHome);
    stream.close();
}

From source file:it.cnr.icar.eric.client.admin.function.AbstractFunctionTest.java

/** Creates and sets up an AdminFunctionContext for use by a test. */
protected void setUp() throws Exception {
    super.setUp();
    context = AdminFunctionContext.getInstance();

    testOut = new ByteArrayOutputStream();
    context.setOutStream(new PrintStream(testOut));

    JAXRService service = new JAXRService();
    service.setAlias(getTestUserAlias());
    service.setKeyPass(getTestUserKeypass());
    service.connect();//from ww w.j  a  va  2s.  com
    context.setService(service);
}

From source file:com.act.lcms.plotter.WriteAndPlotMS1Results.java

public void plotTIC(List<XZ> tic, String outPrefix, String fmt) throws IOException {
    String outImg = outPrefix + "." + fmt;
    String outData = outPrefix + ".data";

    // Write data output to outfile
    try (PrintStream out = new PrintStream(new FileOutputStream(outData))) {
        // print each time point + intensity to outDATA
        for (XZ xz : tic) {
            out.format("%.4f\t%.4f\n", xz.getTime(), xz.getIntensity());
            out.flush();//  ww  w.j  a  v  a  2s .c o  m
        }
    }

    // render outDATA to outPDF using gnuplot
    new Gnuplotter().plot2D(outData, outImg, new String[] { "TIC" }, "time", null, "intensity", fmt);
}

From source file:com.simiacryptus.util.io.HtmlNotebookOutput.java

/**
 * Instantiates a new Html notebook output.
 *
 * @param parentDirectory the parent directory
 * @param out             the out/* w w w. j  a va 2  s . c o m*/
 * @throws FileNotFoundException the file not found exception
 */
public HtmlNotebookOutput(final File parentDirectory, @javax.annotation.Nonnull final OutputStream out)
        throws FileNotFoundException {
    primaryOut = new PrintStream(out);
    workingDir = parentDirectory;
    out("<html><head><style>\n" + "pre {\n" + "    background-color: lightyellow;\n"
            + "    margin-left: 20pt;\n" + "    font-family: monospace;\n" + "}\n" + "</style></head><body>");
}

From source file:com.appeligo.search.actions.ResponseReportAction.java

public String execute() throws Exception {
    long timestamp = new Date().getTime();
    String day = Utils.getDatePath(timestamp);
    String hostname = null;/*w  w  w . j a v a  2 s  . co m*/
    try {
        hostname = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        hostname = "UnknownHost";
    }
    String dirname = documentRoot + "/stats/" + day + "/" + hostname;
    String responseFileName = dirname + "/response-" + reporter + ".html";
    try {
        File dir = new File(dirname);
        if ((!dir.exists()) && (!dir.mkdirs())) {
            throw new IOException("Error creating directory " + dirname);
        }
        File file = new File(responseFileName);
        PrintStream responseFile = null;
        if (file.exists()) {
            responseFile = new PrintStream(new FileOutputStream(responseFileName, true));
        } else {
            responseFile = new PrintStream(new FileOutputStream(responseFileName));
            String title = "Response Times for " + getServletRequest().getServerName() + " to " + reporter;
            responseFile.println("<html><head><title>" + title + "</title></head>");
            responseFile.println("<body><h1>" + title + "</h1>");
            responseFile.println("<table border='1'>");
            responseFile.println("<tr>");
            responseFile.println("<th>Time (UTC)</th>");
            responseFile.println("<th>Response (Millis)</th>");
            responseFile.println("<th>Status</th>");
            responseFile.println("<th>Bytes Read</th>");
            responseFile.println("<th>Timed Out</th>");
            responseFile.println("<th>Exception</th>");
            responseFile.println("</tr>");
        }
        Calendar cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone("GMT"));
        cal.setTimeInMillis(timestamp);
        String time = String.format("%1$tH:%1$tM:%1$tS", cal);
        responseFile.print("<tr>");
        responseFile.print("<td>" + time + "</td>");
        responseFile.format("<td>%,d</td>", responseMillis);
        responseFile.print("<td>" + status + "</td>");
        responseFile.format("<td>%,d</td>", bytesRead);
        responseFile.print("<td>" + timedOut + "</td>");
        responseFile.print("<td>" + exception + "</td>");
        responseFile.println("</tr>");
    } catch (IOException e) {
        log.error("Error opening or writing to " + responseFileName, e);
    }

    return SUCCESS;
}

From source file:au.org.ala.delta.translation.PrintFile.java

public PrintFile(final StringBuilder buffer) {

    _output = new PrintStream(new OutputStream() {
        @Override//  w  ww.j  a v  a2  s . c  o m
        public void write(int b) throws IOException {
            buffer.append((char) b);
        }
    });
    initialise();
}

From source file:cz.zcu.kiv.eegdatabase.logic.csv.SimpleCSVFactory.java

/**
 * Generating csv file from scenarios//from   w  w  w  . j  a v a2 s. c  om
 *
 * @return csv file with scenarios
 * @throws IOException - error writing to stream
 */
@Transactional(readOnly = true)
public OutputStream generateScenariosCsvFile() throws IOException {

    log.debug("Creating output stream");
    OutputStream out = new ByteArrayOutputStream();
    PrintStream printStream = new PrintStream(out);
    List<Scenario> scenarioList = scenarioDao.getAllRecords();
    log.debug("Creating table header");
    printStream.println(
            CSVUtils.SCENARIO_TITLE + CSVUtils.SEMICOLON + CSVUtils.SCENARIO_LENGTH + CSVUtils.SEMICOLON
                    + CSVUtils.SCENARIO_DESCRIPTION + CSVUtils.SEMICOLON + CSVUtils.SCENARIO_DETAILS);
    log.debug("Printing experiments to outputstream");
    for (int i = 0; i < scenarioList.size(); i++) {
        printStream.println(scenarioList.get(i).getTitle() + CSVUtils.SEMICOLON
                + scenarioList.get(i).getScenarioLength() + CSVUtils.SEMICOLON
                + scenarioList.get(i).getDescription() + CSVUtils.SEMICOLON + CSVUtils.PROTOCOL_HTTP + domain
                + CSVUtils.SCENARIO_URL + scenarioList.get(i).getScenarioId());
    }
    printStream.close();

    return out;
}