Example usage for java.io PrintStream flush

List of usage examples for java.io PrintStream flush

Introduction

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

Prototype

public void flush() 

Source Link

Document

Flushes the stream.

Usage

From source file:Main.java

public static void main(String[] args) {
    int c = 123;/*from   w  ww .  j  a  va  2 s  .c o m*/

    PrintStream ps = new PrintStream(System.out);

    // print an integer and change line
    ps.println(c);
    ps.print("from java2s.com");

    // flush the stream
    ps.flush();

}

From source file:Main.java

public static void main(String[] args) {
    CharSequence csq = "from java2s.com";

    PrintStream ps = new PrintStream(System.out);

    // append our character sequences
    ps.append(csq, 6, 11);/*from www .  j  av  a2s.  c o  m*/
    ps.append(csq, 0, 5);

    // print the result
    ps.flush();
    ps.close();

}

From source file:Main.java

public static void main(String[] args) {
    char c = 'A';

    PrintStream ps = new PrintStream(System.out);

    // append our characters
    ps.append(c);/*from  w  ww . ja va  2s . c  om*/
    ps.append('y');
    ps.append('m');

    // print the result
    ps.flush();
    ps.close();

}

From source file:Main.java

public static void main(String[] args) {
    char c = 'a';

    PrintStream ps = new PrintStream(System.out);

    // print a char and change line
    ps.println(c);//from  www  . j  a  v a 2 s. co m
    ps.println('b');
    ps.print("from java2s.com");

    // flush the stream
    ps.flush();

}

From source file:Main.java

public static void main(String[] args) {
    long c = 1234567890L;
    try {// w ww .j av  a2  s .  com

        PrintStream ps = new PrintStream(System.out);

        // print a long and change line
        ps.println(c);
        ps.print("from java2s.com");

        // flush the stream
        ps.flush();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.googlecode.shutdownlistener.ShutdownUtility.java

public static void main(String[] args) throws Exception {
    final ShutdownConfiguration config = ShutdownConfiguration.getInstance();

    final String command;
    if (args.length > 0) {
        command = args[0];/*from  w  ww  .  ja va  2 s . c  o m*/
    } else {
        command = config.getStatusCommand();
    }

    System.out.println("Calling " + config.getHost() + ":" + config.getPort() + " with command: " + command);

    final InetAddress hostAddress = InetAddress.getByName(config.getHost());
    final Socket shutdownConnection = new Socket(hostAddress, config.getPort());
    try {
        shutdownConnection.setSoTimeout(5000);
        final BufferedReader reader = new BufferedReader(
                new InputStreamReader(shutdownConnection.getInputStream()));
        final PrintStream writer = new PrintStream(shutdownConnection.getOutputStream());
        try {
            writer.println(command);
            writer.flush();

            while (true) {
                final String line = reader.readLine();
                if (line == null) {
                    break;
                }

                System.out.println(line);
            }
        } finally {
            IOUtils.closeQuietly(reader);
            IOUtils.closeQuietly(writer);
        }
    } finally {
        try {
            shutdownConnection.close();
        } catch (IOException ioe) {
        }
    }

}

From source file:Main.java

public static void main(String[] args) {

    PrintStream ps = new PrintStream(System.out);

    // print this string
    ps.print("This is a String");

    // print new line
    ps.println();/*from w  ww.  j av a2 s  . co m*/

    // print a new string
    ps.println("from java2s.com");

    // flush the stream
    ps.flush();

}

From source file:com.act.lcms.ExtractFromNetCDFAroundMass.java

public static void main(String[] args) throws Exception {
    if (args.length != 4 || !args[0].endsWith(".nc")) {
        throw new RuntimeException(
                "Needs (1) NetCDF .nc file, " + "(2) mass value, e.g., 132.0772 for debugging, "
                        + "(3) how many timepoints to process (-1 for all), "
                        + "(4) prefix for .data and rendered .pdf, '-' for stdout");
    }/*  w ww.j ava2 s  .  c  o  m*/

    String netCDF = args[0];
    Double mz = Double.parseDouble(args[1]);
    Integer numSpectraToProcess = Integer.parseInt(args[2]);
    String outPrefix = args[3];
    String outPDF = outPrefix.equals("-") ? null : outPrefix + ".pdf";
    String outDATA = outPrefix.equals("-") ? null : outPrefix + ".data";

    ExtractFromNetCDFAroundMass e = new ExtractFromNetCDFAroundMass();
    List<Triple<Double, Double, Double>> window = e.get2DWindow(netCDF, mz, numSpectraToProcess);

    // Write data output to outfile
    PrintStream whereTo = outDATA == null ? System.out : new PrintStream(new FileOutputStream(outDATA));
    for (Triple<Double, Double, Double> xyz : window) {
        whereTo.format("%.4f\t%.4f\t%.4f\n", xyz.getLeft(), xyz.getMiddle(), xyz.getRight());
        whereTo.flush();
    }

    if (outDATA != null) {
        // if outDATA is != null, then we have written to .data file
        // now render the .data to the corresponding .pdf file

        // first close the .data
        whereTo.close();

        // render outDATA to outPDF using gnuplo
        Gnuplotter plotter = new Gnuplotter();
        plotter.plot3D(outDATA, outPDF, netCDF, mz);
    }
}

From source file:com.act.lcms.CompareTwoNetCDFAroundMass.java

public static void main(String[] args) throws Exception {
    if (args.length < 5 || !areNCFiles(Arrays.copyOfRange(args, 3, args.length))) {
        throw new RuntimeException("Needs: \n" + "(1) mass value, e.g., 132.0772 for debugging, \n"
                + "(2) how many timepoints to process (-1 for all), \n"
                + "(3) prefix for .data and rendered .pdf \n" + "(4,5..) 2 or more NetCDF .nc files");
    }/*from w  w  w. j  av a  2s . co  m*/

    String fmt = "pdf";
    Double mz = Double.parseDouble(args[0]);
    Integer numSpectraToProcess = Integer.parseInt(args[1]);
    String outPrefix = args[2];
    String outImg = outPrefix.equals("-") ? null : outPrefix + "." + fmt;
    String outData = outPrefix.equals("-") ? null : outPrefix + ".data";

    CompareTwoNetCDFAroundMass c = new CompareTwoNetCDFAroundMass();
    String[] netCDF_fnames = Arrays.copyOfRange(args, 3, args.length);
    List<List<Pair<Double, Double>>> spectra = c.getSpectraForMass(mz, netCDF_fnames, numSpectraToProcess);

    // Write data output to outfile
    PrintStream out = outData == null ? System.out : new PrintStream(new FileOutputStream(outData));

    // print out the spectra to outData
    for (List<Pair<Double, Double>> spectraInFile : spectra) {
        for (Pair<Double, Double> xy : spectraInFile) {
            out.format("%.4f\t%.4f\n", xy.getLeft(), xy.getRight());
            out.flush();
        }
        // delimit this dataset from the rest
        out.print("\n\n");
    }
    // find the ymax across all spectra, so that we can have a uniform y scale
    Double yrange = 0.0;
    for (List<Pair<Double, Double>> spectraInFile : spectra) {
        Double ymax = 0.0;
        for (Pair<Double, Double> xy : spectraInFile) {
            Double intensity = xy.getRight();
            if (ymax < intensity)
                ymax = intensity;
        }
        if (yrange < ymax)
            yrange = ymax;
    }

    if (outData != null) {
        // if outData is != null, then we have written to .data file
        // now render the .data to the corresponding .pdf file

        // first close the .data
        out.close();

        // render outData to outFILE using gnuplo
        Gnuplotter plotter = new Gnuplotter();
        plotter.plot2D(outData, outImg, netCDF_fnames, "time in seconds", yrange, "intensity", fmt);
    }
}

From source file:com.act.lcms.AnimateNetCDFAroundMass.java

public static void main(String[] args) throws Exception {
    if (args.length < 7 || !areNCFiles(Arrays.copyOfRange(args, 5, args.length))) {
        throw new RuntimeException(
                "Needs: \n" + "(1) mass value, e.g., 132.0772 \n" + "(2) time value, e.g., 39.2, (seconds), \n"
                        + "(3) minimum Mz Precision, 0.04 \n" + "(4) max z axis, e.g., 20000 \n"
                        + "(5) prefix for .data and rendered .pdf \n" + "(6..) 2 or more NetCDF .nc files");
    }//from  w w  w . j  a v  a 2  s  . c o m

    Double mz = Double.parseDouble(args[0]);
    Double time = Double.parseDouble(args[1]);
    Double minMzPrecision = Double.parseDouble(args[2]);
    Double maxZAxis = Double.parseDouble(args[3]);
    String outPrefix = args[4];

    // the mz values go from 50-950, we start with a big window and exponentially narrow down
    double mzWin = 100;
    // time values go from 0-450, we start with a big window and exponentially narrow down
    double timeWin = 50;

    // the factor by which to zoom in every step (has to be >1, a value of 2 is good)
    double factor = 1.2;

    // the animation frame count
    int frame = 1;

    AnimateNetCDFAroundMass c = new AnimateNetCDFAroundMass();
    String[] netCDFFnames = Arrays.copyOfRange(args, 5, args.length);
    List<List<XYZ>> spectra = c.getSpectra(netCDFFnames, time, timeWin, mz, mzWin);

    for (List<XYZ> s : spectra) {
        System.out.format("%d xyz datapoints in (initial narrowed) spectra\n", s.size());
    }

    String[] labels = new String[netCDFFnames.length];
    for (int i = 0; i < labels.length; i++)
        labels[i] = "Dataset: " + i;
    // you could set labels to netCDFFnames to get precise labels on the graphs

    Gnuplotter plotter = new Gnuplotter();
    String fmt = "png";

    List<String> outImgFiles = new ArrayList<>(), outDataFiles = new ArrayList<>();
    while (mzWin > minMzPrecision) {

        // exponentially narrow windows down
        mzWin /= factor;
        timeWin /= factor;

        List<List<XYZ>> windowedSpectra = c.getSpectraInWindowAll(spectra, time, timeWin, mz, mzWin);

        String frameid = String.format("%03d", frame);
        String outPDF = outPrefix + frameid + "." + fmt;
        String outDATA = outPrefix + frameid + ".data";
        outImgFiles.add(outPDF);
        outDataFiles.add(outDATA);
        frame++;

        // Write data output to outfile
        PrintStream out = new PrintStream(new FileOutputStream(outDATA));

        // print out the spectra to outDATA
        for (List<XYZ> windowOfSpectra : windowedSpectra) {
            for (XYZ xyz : windowOfSpectra) {
                out.format("%.4f\t%.4f\t%.4f\n", xyz.time, xyz.mz, xyz.intensity);
                out.flush();
            }
            // delimit this dataset from the rest
            out.print("\n\n");
        }

        // close the .data
        out.close();

        // render outDATA to outPDF using gnuplot
        plotter.plotMulti3D(outDATA, outPDF, fmt, labels, maxZAxis);
    }

    String outImgs = outPrefix + "*." + fmt;
    plotter.makeAnimatedGIF(outImgs, outPrefix + ".gif");
    // all the frames are now in the animated gif, remove the intermediate files
    for (String f : outDataFiles)
        new File(f).delete();
    for (String f : outImgFiles)
        new File(f).delete();
}