Example usage for java.io PrintWriter flush

List of usage examples for java.io PrintWriter flush

Introduction

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

Prototype

public void flush() 

Source Link

Document

Flushes the stream.

Usage

From source file:com.bc.fiduceo.post.PostProcessingTool.java

static void printUsageTo(OutputStream outputStream) {
    final PrintWriter writer = new PrintWriter(outputStream);
    writer.println("post-processing-tool version " + VERSION_NUMBER);
    writer.println();/*from   w  w  w .ja va  2 s.  com*/

    final HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.printHelp(writer, 120, "post-processing-tool <options>", "Valid options are:", getOptions(),
            3, 3, "");

    writer.flush();
}

From source file:groovy.ui.GroovyMain.java

private static void printHelp(PrintStream out, Options options) {
    HelpFormatter formatter = new HelpFormatter();
    PrintWriter pw = new PrintWriter(out);

    formatter.printHelp(pw, 80, "groovy [options] [args]", "options:", options, 2, 4, null, // footer
            false);//from w w  w . ja va2s  .co m

    pw.flush();
}

From source file:io.warp10.worf.WorfCLI.java

private static int runInteractive(String warp10Configuration) throws WorfException {
    WorfInteractive worfInteractive = new WorfInteractive();
    PrintWriter out = worfInteractive.getPrintWriter();

    // read warp10 configuration
    out.println("Reading warp10 configuration " + warp10Configuration);
    Properties config = Worf.readConfig(warp10Configuration, out);

    if (config == null) {
        out.println("Unable to read warp10 configuration.");
        out.flush();
        return -1;
    }/*from w ww. j  ava 2 s.  c  om*/

    if (WorfTemplate.isTemplate(config)) {
        warp10Configuration = worfInteractive.runTemplate(config, warp10Configuration);
        // reload config
        config = Worf.readConfig(warp10Configuration, out);
    }
    // get Default values
    Properties worfConfig = Worf.readDefault(warp10Configuration, out);
    worfInteractive.run(config, worfConfig);

    return 0;
}

From source file:com.dumontierlab.pdb2rdf.Pdb2Rdf.java

private static void outputStats(CommandLine cmd, Map<String, Double> stats) throws FileNotFoundException {
    File outputDir = getOutputDirectory(cmd);
    File statsFile = null;/*from ww w  . j  ava2 s  .  co m*/
    if (outputDir != null) {
        statsFile = new File(outputDir, STATSFILE_NAME);
    } else {
        statsFile = new File(STATSFILE_NAME);
    }
    PrintWriter out = new PrintWriter(statsFile);
    try {
        for (Map.Entry<String, Double> stat : stats.entrySet()) {
            out.println(stat.getKey() + ": " + stat.getValue());
        }
        out.flush();
    } finally {
        out.close();
    }

}

From source file:com.zimbra.qa.unittest.prov.ldap.TestLdapReadTimeout.java

private static void usage(Options options) {
    System.out.println("\n");
    PrintWriter pw = new PrintWriter(System.out, true);
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(pw, formatter.getWidth(),
            "zmjava " + TestLdapReadTimeout.class.getCanonicalName() + " [options]", null, options,
            formatter.getLeftPadding(), formatter.getDescPadding(), null);
    System.out.println("\n");
    pw.flush();
}

From source file:com.ebay.erl.mobius.core.mapred.ConfigurableJob.java

private static void writePartitionFile(JobConf job, Sampler sampler) {
    try {/*www  .j  a v a2 s.co m*/
        ////////////////////////////////////////////////
        // first, getting samples from the data sources
        ////////////////////////////////////////////////
        LOGGER.info("Running local sampling for job [" + job.getJobName() + "]");
        InputFormat inf = job.getInputFormat();
        Object[] samples = sampler.getSample(inf, job);
        LOGGER.info("Samples retrieved, sorting...");

        ////////////////////////////////////////////////
        // sort the samples
        ////////////////////////////////////////////////
        RawComparator comparator = job.getOutputKeyComparator();
        Arrays.sort(samples, comparator);

        if (job.getBoolean("mobius.print.sample", false)) {
            PrintWriter pw = new PrintWriter(
                    new OutputStreamWriter(new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(
                            new File(job.get("mobius.sample.file", "./samples.txt.gz")))))));
            for (Object obj : samples) {
                pw.println(obj);
            }
            pw.flush();
            pw.close();
        }

        ////////////////////////////////////////////////
        // start to write partition files
        ////////////////////////////////////////////////

        FileSystem fs = FileSystem.get(job);
        Path partitionFile = fs.makeQualified(new Path(TotalOrderPartitioner.getPartitionFile(job)));
        while (fs.exists(partitionFile)) {
            partitionFile = new Path(partitionFile.toString() + "." + System.currentTimeMillis());
        }
        fs.deleteOnExit(partitionFile);
        TotalOrderPartitioner.setPartitionFile(job, partitionFile);
        LOGGER.info("write partition file to:" + partitionFile.toString());

        int reducersNbr = job.getNumReduceTasks();
        Set<Object> wroteSamples = new HashSet<Object>();

        SequenceFile.Writer writer = SequenceFile.createWriter(fs, job, partitionFile, Tuple.class,
                NullWritable.class);

        float avgReduceSize = samples.length / reducersNbr;

        int lastBegin = 0;
        for (int i = 0; i < samples.length;) {
            // trying to distribute the load for every reducer evenly,
            // dividing the <code>samples</code> into a set of blocks
            // separated by boundaries, objects that selected from the
            // <code>samples</code> array, and each blocks should have
            // about the same size.

            // find the last index of element that equals to samples[i], as
            // such element might appear multiple times in the samples.
            int upperBound = Util.findUpperBound(samples, samples[i], comparator);

            int lowerBound = i;//Util.findLowerBound(samples, samples[i], comparator);

            // the repeat time of samples[i], if the key itself is too big
            // select it as boundary
            int currentElemSize = upperBound - lowerBound + 1;

            if (currentElemSize > avgReduceSize * 2) // greater than two times of average reducer size
            {
                // the current element is too big, greater than
                // two times of the <code>avgReduceSize</code>, 
                // put itself as boundary
                writer.append(((DataJoinKey) samples[i]).getKey(), NullWritable.get());
                wroteSamples.add(((DataJoinKey) samples[i]).getKey());
                //pw.println(samples[i]);

                // immediate put the next element to the boundary,
                // the next element starts at <code> upperBound+1
                // </code>, to prevent the current one consume even 
                // more.
                if (upperBound + 1 < samples.length) {
                    writer.append(((DataJoinKey) samples[upperBound + 1]).getKey(), NullWritable.get());
                    wroteSamples.add(((DataJoinKey) samples[upperBound + 1]).getKey());
                    //pw.println(samples[upperBound+1]);

                    // move on to the next element of <code>samples[upperBound+1]/code>
                    lastBegin = Util.findUpperBound(samples, samples[upperBound + 1], comparator) + 1;
                    i = lastBegin;
                } else {
                    break;
                }
            } else {
                // current element is small enough to be consider
                // with previous group
                int size = upperBound - lastBegin;
                if (size > avgReduceSize) {
                    // by including the current elements, we have
                    // found a block that's big enough, select it
                    // as boundary
                    writer.append(((DataJoinKey) samples[i]).getKey(), NullWritable.get());
                    wroteSamples.add(((DataJoinKey) samples[i]).getKey());
                    //pw.println(samples[i]);

                    i = upperBound + 1;
                    lastBegin = i;
                } else {
                    i = upperBound + 1;
                }
            }
        }

        writer.close();

        // if the number of wrote samples doesn't equals to number of
        // reducer minus one, then it means the key spaces is too small
        // hence TotalOrderPartitioner won't work, it works only if 
        // the partition boundaries are distinct.
        //
        // we need to change the number of reducers
        if (wroteSamples.size() + 1 != reducersNbr) {
            LOGGER.info("Write complete, but key space is too small, sample size=" + wroteSamples.size()
                    + ", reducer size:" + (reducersNbr));
            LOGGER.info("Set the reducer size to:" + (wroteSamples.size() + 1));

            // add 1 because the wrote samples define boundary, ex, if
            // the sample size is two with two element [300, 1000], then 
            // there should be 3 reducers, one for handling i<300, one 
            // for n300<=i<1000, and another one for 1000<=i
            job.setNumReduceTasks((wroteSamples.size() + 1));
        }

        samples = null;
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}

From source file:com.dumbster.smtp.SimpleSmtpServer.java

/**
 * Send response to client.//from w ww.  j  a v  a 2s  .c o m
 * 
 * @param out
 *            socket output stream
 * @param smtpResponse
 *            response object
 */
private static void sendResponse(PrintWriter out, SmtpResponse smtpResponse) {
    if (smtpResponse.getCode() > 0) {
        int code = smtpResponse.getCode();
        String message = smtpResponse.getMessage();
        out.print(code + " " + message + "\r\n");
        out.flush();
    }
}

From source file:at.tuwien.ifs.somtoolbox.data.InputDataWriter.java

/** Writes the class information to a tab-separated file. */
public static void writeToFileTabSeparated(SOMLibClassInformation classInfo, String fileName)
        throws IOException, SOMLibFileFormatException {
    PrintWriter writer = FileUtils.openFileForWriting("Tab-separated class info", fileName);
    for (String element : classInfo.getDataNames()) {
        writer.println(element + "\t" + classInfo.getClassName(element));
    }//from   w w w  .  j  a v a2 s  .c  o m
    writer.flush();
    writer.close();
}

From source file:TrainLogistic.java

private static void saveTo(FileOutputStream modelOutput, OnlineLogisticRegression lr) {
    PrintWriter w = new PrintWriter(new OutputStreamWriter(modelOutput));
    String str = new String(" ");
    //System.out.printf("%d columns\n",lr.getBeta().numCols());
    System.out.printf("Now, writing file...\n");
    for (int column = 0; column < lr.getBeta().numCols(); column++) {
        //System.out.printf("%f, ", lr.getBeta().get(0, column));
        str = java.lang.String.format("%f\n", lr.getBeta().get(0, column));
        w.write(str);/*w w  w  .  j  a v a2 s . co  m*/
        w.flush();
    }
    w.close();
}

From source file:glacierpipe.GlacierPipeMain.java

public static void printHelp(PrintWriter writer) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(writer, HelpFormatter.DEFAULT_WIDTH,
            "<other-command> ... | java -jar glacierpipe.jar [--help | --upload] -e <glacier-endpoint> -v <vault-nane> <archive-name>",
            null, OPTIONS, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null);

    writer.printf("%nBuild-in endpoint aliases:%n%n");
    for (Entry<String, String> entry : ConfigBuilder.GLACIER_ENDPOINTS.entrySet()) {
        writer.printf("  %20s %s%n", entry.getKey() + " ->", entry.getValue());
    }//from  w w w. ja v  a 2s. co m

    writer.flush();
}