Example usage for java.io PrintWriter PrintWriter

List of usage examples for java.io PrintWriter PrintWriter

Introduction

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

Prototype

public PrintWriter(File file) throws FileNotFoundException 

Source Link

Document

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

Usage

From source file:com.kappaware.logtrawler.output.flow.FileDataOutputFlow.java

public FileDataOutputFlow(String fileName) throws IOException {
    out = new PrintWriter(new BufferedWriter(new FileWriter(fileName, true)));
    log.info(String.format("Data events will be stored in to '%s'", fileName));
}

From source file:StopWatch.java

public StopWatch(String name, PrintWriter out) {
    this.name = name;
    if (out == null)
        this.out = new PrintWriter(System.err);
    else//from w w  w  .java  2s.  co m
        this.out = out;
    elapsedTime = -1L; // So we can tell if we are ever started
}

From source file:com.opengamma.integration.marketdata.WatchListRecorder.java

/**
 * Main entry point./* w  w w .  j  av a2  s . c om*/
 * 
 * @param args the arguments
 * @throws Exception if an error occurs
 */
public static void main(final String[] args) throws Exception { // CSIGNORE
    final CommandLineParser parser = new PosixParser();
    final Options options = new Options();
    final Option outputFileOpt = new Option("o", "output", true, "output file");
    outputFileOpt.setRequired(true);
    options.addOption(outputFileOpt);
    final Option urlOpt = new Option("u", "url", true, "server url");
    options.addOption(urlOpt);
    String outputFile = "watchList.txt";
    String url = "http://localhost:8080/jax";
    try {
        final CommandLine cmd = parser.parse(options, args);
        outputFile = cmd.getOptionValue("output");
        url = cmd.getOptionValue("url");
    } catch (final ParseException exp) {
        s_logger.error("Option parsing failed: {}", exp.getMessage());
        System.exit(0);
    }

    final WatchListRecorder recorder = create(URI.create(url), "main", "combined");
    recorder.addWatchScheme(ExternalSchemes.BLOOMBERG_TICKER);
    recorder.addWatchScheme(ExternalSchemes.BLOOMBERG_BUID);
    final PrintWriter pw = new PrintWriter(outputFile);
    recorder.setPrintWriter(pw);
    recorder.run();

    pw.close();
    System.exit(0);
}

From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtilTest.java

@Test
public void testWriteSoftFile() throws Exception {
    Experiment experiment = helper.makeGoodExperiment();
    String permaLinkUrl = "http://example.com/my-experiment";
    StringWriter sw = new StringWriter();
    PrintWriter out = new PrintWriter(sw);
    GeoSoftFileWriterUtil.writeSoftFile(experiment, permaLinkUrl, out);
    out.close();/*w  w  w.  j  ava 2s  .c  om*/
    @SuppressWarnings("unchecked")
    List<String> lines = IOUtils.readLines(new StringReader(sw.toString()));

    final String[] expected = { "^SAMPLE=test-hyb", "!Sample_title=test-hyb",
            "!Sample_description=test-sample1, test-sample2", "!Sample_supplementary_file=raw_file.data",
            "!Sample_table=derived_file.data", "!Sample_source_name=test-source",
            "!Sample_organism=test Organizm 1", "!Sample_organism=test Organizm 2",
            "!Sample_treatment_protocol=\"some treatment:treatment desc\"; \"another treatment:another treatment desc\"",
            "!Sample_growth_protocol=\"some growth:growth desc\"",
            "!Sample_extract_protocol=\"some extract:extract desc\"",
            "!Sample_label_protocol=\"some label:labeling desc\"",
            "!Sample_hyb_protocol=\"some hybridization:hybridization desc\"",
            "!Sample_scan_protocol=\"some scan:scan desc\"",
            "!Sample_data_processing=\"data processing:data proc desc\"", "!Sample_label=label",
            "!Sample_biomaterial_provider=Affymetrix", "!Sample_platform_id=test-ga",
            "!Sample_characteristics=test-factor:test-value growth",
            "!Sample_characteristics=OrganismPart:some tissue site",
            "!Sample_characteristics=DiseaseState:some disease state",
            "!Sample_characteristics=ExternalId:test external id",
            "!Sample_characteristics=test-cat:test-val growth",
            "!Sample_characteristics=CellType:some cell type", "!Sample_molecule=other", "^SERIES=test-exp-id",
            "!Series_title=test-title", "!Series_summary=test-title",
            "!Series_overall_design=\"test-design-type1 (MO)\"; \"test-design-type2 (MO)\"",
            "!Series_pubmed_id=test-pub", "!Series_contributor=fff,mmm,lll",
            "!Series_web_link=http://example.com/my-experiment", "!Series_sample_id=test-hyb" };

    for (int i = 0; i < expected.length; i++) {
        String result = lines.get(i);
        assertEquals("line " + (i + 1), expected[i], result);
    }

}

From source file:com.twitter.ambrose.util.JSONUtil.java

public static void writeJson(String fileName, Object object) throws IOException {
    Writer writer = new PrintWriter(fileName);
    try {//from   ww w .j a v  a  2 s.  co m
        JSONUtil.writeJson(writer, object);
    } finally {
        writer.close();
    }
}

From source file:eu.ensure.aging.AgingSimulator.java

/**
 * Write "help" to the provided OutputStream.
 *//*from w  ww .  j ava 2s  .c o  m*/
public static void printHelp(final Options options, final OutputStream out) {

    HelpFormatter formatter = new HelpFormatter();
    PrintWriter pw = new PrintWriter(out);

    final int printedRowWidth = 80;
    final int spacesBeforeOption = 1;
    final int spacesBeforeOptionDescription = 3;

    String syntax = appName + " [options] <source> [<destination>]";

    String header = "\nAvailable options:";

    String footer = "\n" + "The options <arg> is either 'true' or 'false' and by default the -n option is\n"
            + "'true'.\n\n"
            + "<source> and optionally <destination> are paths to Archival Information Packages\n"
            + "(AIPs) and this utility is used to flip bits in AIPs, which are assumed to use\n"
            + "the TAR format, in order to simulate aging of stored AIPs.\n";

    formatter.printHelp(pw, printedRowWidth, syntax, header, options, spacesBeforeOption,
            spacesBeforeOptionDescription, footer, false);

    pw.flush();
}

From source file:us.gaje.mq.db.DerbyServer.java

public void afterPropertiesSet() throws Exception {

    log.info("Loading mq-derby-plugin");
    log.info("Starting derby server");

    final NetworkServerControl networkServerControl = new NetworkServerControl();

    //this method forks into the background
    networkServerControl.start(new PrintWriter(System.out));
}

From source file:com.rabidgremlin.legalbeagle.report.TsvReportWriter.java

public void generateReport(String output, Report report) throws Exception {
    log.info("Writing report to {}...", output);

    PrintWriter out = new PrintWriter(new File(output));

    out.println("File\tStatus\tDescription\tLicense(s)\tError");

    for (ReportItem reportItem : report.getReportItems()) {
        out.print(reportItem.getFile().getAbsolutePath());
        out.print("\t");
        out.print(reportItem.getReportItemStatus());
        out.print("\t");

        if (reportItem.getDescription() != null) {
            out.print(reportItem.getDescription());
        }/*w  ww  .  j av a2s . com*/
        out.print("\t");

        out.print(StringUtils.join(reportItem.getLicenses(), "; "));
        out.print("\t");

        if (reportItem.getError() != null) {
            out.print(reportItem.getError());
        }

        out.println();

    }

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

From source file:com.stratio.explorer.converters.PropertiesToStringConverter.java

/**
 * Transform porperties (key-value) separate by lineSeparator
 * @param properties//  w ww.ja  va 2s . c  o  m
 * @return String with values
 */
public String transform(Properties properties) {

    StringWriter writer = new StringWriter();
    properties.list(new PrintWriter(writer));
    return deleteHeaderLine(writer.getBuffer().toString());
}

From source file:de.ailis.oneinstance.OneInstanceClient.java

/**
 * @see java.lang.Runnable#run()/*from  w  ww. j av  a  2s . c o  m*/
 */
@Override
public void run() {
    try {
        try {
            // Send the application ID.
            PrintWriter out = new PrintWriter(new OutputStreamWriter(this.socket.getOutputStream(), "UTF-8"));
            out.println(this.appId);
            out.flush();

            // Read the data from the client
            InputStream in = this.socket.getInputStream();
            ObjectInputStream objIn = new ObjectInputStream(in);
            File workingDir = (File) objIn.readObject();
            String[] args = (String[]) objIn.readObject();

            // Call event handler
            boolean result = OneInstance.getInstance().fireNewInstance(workingDir, args);

            // Send the result
            out.println(result ? "start" : "exit");
            out.flush();

            // Wait for client disconnect.
            in.read();
        } finally {
            this.socket.close();
        }
    } catch (IOException e) {
        LOG.error(e.toString(), e);
    } catch (ClassNotFoundException e) {
        LOG.error(e.toString(), e);
    }
}