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:Main.java

public static void main(String[] args) {
    long i = 1234567890L;

    PrintWriter pw = new PrintWriter(System.out);

    // print long
    pw.print(i);//  w w  w . j a  va2  s.  c  om

    // print another long
    pw.print(987654321L);

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    String s = "tutorial from java2s.com";
    try {/*w  w  w .j a  va 2 s . c o m*/

        PrintWriter pw = new PrintWriter(System.out);

        // write substrings
        pw.write(s, 0, 5);
        pw.write(s, 6, 5);

        // flush the writer
        pw.flush();

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

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();

    String hostName = "hostName";
    String fileName = "fileName";

    SSLSocket sslsock = (SSLSocket) factory.createSocket(hostName, 443);

    SSLSession session = sslsock.getSession();
    X509Certificate cert;//from www. ja  va 2s.c o m
    try {
        cert = (X509Certificate) session.getPeerCertificates()[0];
    } catch (SSLPeerUnverifiedException e) {
        System.err.println(session.getPeerHost() + " did not present a valid certificate.");
        return;
    }

    System.out.println(session.getPeerHost() + " has presented a certificate belonging to:");
    Principal p = cert.getSubjectDN();
    System.out.println("\t[" + p.getName() + "]");
    System.out.println("The certificate bears the valid signature of:");
    System.out.println("\t[" + cert.getIssuerDN().getName() + "]");

    System.out.print("Do you trust this certificate (y/n)? ");
    System.out.flush();
    BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
    if (Character.toLowerCase(console.readLine().charAt(0)) != 'y')
        return;

    PrintWriter out = new PrintWriter(sslsock.getOutputStream());

    out.print("GET " + fileName + " HTTP/1.0\r\n\r\n");
    out.flush();

    BufferedReader in = new BufferedReader(new InputStreamReader(sslsock.getInputStream()));
    String line;
    while ((line = in.readLine()) != null)
        System.out.println(line);

    sslsock.close();
}

From source file:Printf3.java

public static void main(String[] args) {
        double price = 44.95;
        double tax = 7.75;
        double amountDue = price * (1 + tax / 100);
        PrintWriter out = new PrintWriter(System.out);
        Printf3.fprint(out, "Amount due = %8.2f\n", amountDue);
        out.flush();
    }//from   ww  w  .j  a  v  a 2 s .c  o m

From source file:Main.java

public static void main(String[] args) {
    String s = "tutorial from java2s.com";
    try {/*w  ww. jav a  2s. co m*/

        PrintWriter pw = new PrintWriter(System.out);

        // %s indicates a string will be placed there, which is s
        pw.printf("This is a %s program", s);

        // flush the writer
        pw.flush();

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

From source file:Main.java

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

    PrintWriter pw = new PrintWriter(System.out);

    // print chars
    pw.print(c);/*from www . jav  a 2 s  .c  o  m*/

    // change line
    pw.println();

    // print another char
    pw.print('b');

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    int i = 1234;

    PrintWriter pw = new PrintWriter(System.out);

    // print int//  w  ww.  j ava  2  s .com
    pw.print(i);

    // change the line
    pw.println();

    // print another int
    pw.print(567);

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    float f = 1234.56f;

    PrintWriter pw = new PrintWriter(System.out);

    // print float
    pw.print(f);// w  w w.  j a  v  a2  s. co m

    // change the line
    pw.println();

    // print another float
    pw.print(1.23f);

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    double d = 1234.567;

    PrintWriter pw = new PrintWriter(System.out);

    // print double
    pw.print(d);/* ww  w.ja v  a2  s .  c o  m*/

    // change the line
    pw.println();

    // print another double
    pw.print(987.654);

    // flush the writer
    pw.flush();

}

From source file:NewFingerServer.java

public static void main(String[] arguments) throws Exception {
    ServerSocketChannel sockChannel = ServerSocketChannel.open();
    sockChannel.configureBlocking(false);

    InetSocketAddress server = new InetSocketAddress("localhost", 79);
    ServerSocket socket = sockChannel.socket();
    socket.bind(server);//from  w  ww  . j  a va2 s.c  o m

    Selector selector = Selector.open();
    sockChannel.register(selector, SelectionKey.OP_ACCEPT);

    while (true) {
        selector.select();
        Set keys = selector.selectedKeys();
        Iterator it = keys.iterator();
        while (it.hasNext()) {
            SelectionKey selKey = (SelectionKey) it.next();
            it.remove();
            if (selKey.isAcceptable()) {
                ServerSocketChannel selChannel = (ServerSocketChannel) selKey.channel();
                ServerSocket selSocket = selChannel.socket();
                Socket connection = selSocket.accept();

                InputStreamReader isr = new InputStreamReader(connection.getInputStream());
                BufferedReader is = new BufferedReader(isr);
                PrintWriter pw = new PrintWriter(new BufferedOutputStream(connection.getOutputStream()), false);
                pw.println("NIO Finger Server");
                pw.flush();
                String outLine = null;
                String inLine = is.readLine();
                if (inLine.length() > 0) {
                    outLine = inLine;
                }
                readPlan(outLine, pw);
                pw.flush();
                pw.close();
                is.close();

                connection.close();
            }
        }
    }
}