List of usage examples for java.io Writer flush
public abstract void flush() throws IOException;
From source file:MainClass.java
public static void main(String[] args) throws Exception { String serverName = System.getProperty("WHOIS_SERVER", DEFAULT_HOST); InetAddress server = null;/*from w ww. ja va2 s. c om*/ server = InetAddress.getByName(serverName); Socket theSocket = new Socket(server, DEFAULT_PORT); Writer out = new OutputStreamWriter(theSocket.getOutputStream(), "8859_1"); out.write("\r\n"); out.flush(); InputStream raw = theSocket.getInputStream(); InputStream in = new BufferedInputStream(theSocket.getInputStream()); int c; while ((c = in.read()) != -1) System.out.write(c); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String hostname = "localhost"; Socket connection = null;// w ww . j a va 2 s .c o m connection = new Socket(hostname, DEFAULT_PORT); Writer out = new OutputStreamWriter(connection.getOutputStream(), "8859_1"); out.write("\r\n"); out.flush(); InputStream raw = connection.getInputStream(); BufferedInputStream buffer = new BufferedInputStream(raw); InputStreamReader in = new InputStreamReader(buffer, "8859_1"); int c; while ((c = in.read()) != -1) { if ((c >= 32 && c < 127) || c == '\t' || c == '\r' || c == '\n') { System.out.write(c); } } connection.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { FileInputStream is = new FileInputStream("your.keystore"); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(is, "my-keystore-password".toCharArray()); String alias = "myalias"; Certificate cert = keystore.getCertificate(alias); File file = null;//from ww w. ja v a 2 s. co m byte[] buf = cert.getEncoded(); FileOutputStream os = new FileOutputStream(file); os.write(buf); os.close(); Writer wr = new OutputStreamWriter(os, Charset.forName("UTF-8")); wr.write(new sun.misc.BASE64Encoder().encode(buf)); wr.flush(); }
From source file:Main.java
public static void main(String[] args) { CharSequence csq = "from java2s.com!"; Writer writer = new PrintWriter(System.out); try {/*from ww w.j a v a 2 s .c om*/ writer.append("This is an example\n"); // flush the writer writer.flush(); // append a new sequence writer.append(csq, 2, 30); // flush the writer to see the result writer.flush(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com"; Writer writer = new PrintWriter(System.out); try {/* w ww . j a va2 s . c o m*/ // append a string writer.append(s); // flush the writer writer.flush(); // append a new string writer.append("\nThis is an example"); // flush and close the stream writer.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com"; Writer writer = new PrintWriter(System.out); try {/*from w ww .j a v a2 s . c o m*/ // append a string writer.append(s); // flush the writer writer.flush(); // append a new string in a new line writer.append("\nThis is an example"); // flush the stream again writer.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String str = "tutorial from java2s.com!"; Writer writer = new PrintWriter(System.out); try {/* w w w. j a va2 s . com*/ // write a string writer.write(str); // flush the writer writer.flush(); // change line and write another string writer.write("\nThis is an example"); // flush the stream again writer.flush(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { char[] c1 = { 'h', 'e', 'l', 'l', 'o' }; char[] c2 = { 'w', 'o', 'r', 'l', 'd' }; Writer writer = new PrintWriter(System.out); try {//from ww w.j a va 2 s. c o m // write a char array writer.write(c1); // flush the writer writer.flush(); // write a new char array writer.write(c2); // flush the stream again writer.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String str = "tutorial from java2s.com!"; Writer writer = new PrintWriter(System.out); try {/*from w w w .j av a2 s. c om*/ // write a string portion writer.write(str, 0, 5); // flush the writer writer.flush(); // write another string portion writer.write(str, 5, 6); // flush the stream again writer.flush(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { char[] c = { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm' }; Writer writer = new PrintWriter(System.out); try {/* w w w .ja v a2 s . co m*/ // write a portion of a char array writer.write(c, 0, 5); // flush the writer writer.flush(); // write another portion of a char array writer.write(c, 5, 5); // flush the stream again writer.close(); } catch (IOException ex) { ex.printStackTrace(); } }