List of usage examples for java.io OutputStream flush
public void flush() throws IOException
From source file:MainClass.java
public static void main(String[] args) throws Exception { int port = 37; ServerSocket server = new ServerSocket(port); while (true) { Socket connection = null; connection = server.accept();/*from w w w .j a v a2s . co m*/ OutputStream out = connection.getOutputStream(); out.write(123); out.flush(); connection.close(); } }
From source file:MainClass.java
public static void main(String[] args) throws IOException { int port = 2345; ServerSocket ss = new ServerSocket(port); while (true) { try {/* w w w . j av a2s. com*/ Socket s = ss.accept(); String response = "Hello " + s.getInetAddress() + " on port " + s.getPort() + "\r\n"; response += "This is " + s.getLocalAddress() + " on port " + s.getLocalPort() + "\r\n"; OutputStream out = s.getOutputStream(); out.write(response.getBytes("US-ASCII")); out.flush(); s.close(); } catch (IOException ex) { } } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault(); Socket s = sf.createSocket(HOST, PORT); OutputStream out = s.getOutputStream(); out.write("\nConnection established.\n\n".getBytes()); out.flush(); int theCharacter = 0; theCharacter = System.in.read(); while (theCharacter != '~') // The '~' is an escape character to exit {/* w w w.j av a 2 s . c o m*/ out.write(theCharacter); out.flush(); theCharacter = System.in.read(); } out.close(); s.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { ServerSocket servsock = new ServerSocket(123456); File myFile = new File("s.pdf"); while (true) {/*from ww w.j a va2 s .com*/ Socket sock = servsock.accept(); byte[] mybytearray = new byte[(int) myFile.length()]; BufferedInputStream bis = new BufferedInputStream(new FileInputStream(myFile)); bis.read(mybytearray, 0, mybytearray.length); OutputStream os = sock.getOutputStream(); os.write(mybytearray, 0, mybytearray.length); os.flush(); sock.close(); } }
From source file:MainClass.java
public static void main(String[] args) { try {/*from w w w . ja v a 2s. c o m*/ URL u = new URL("http://www.java2s.com"); OutputStream out = new FileOutputStream("test.htm"); InputStream in = u.openStream(); DTD html = DTD.getDTD("html"); System.out.println(html.getName()); in.close(); out.flush(); out.close(); } catch (Exception e) { System.err.println("Usage: java PageSaver url local_file"); } }
From source file:Main.java
public static void main(String[] args) { try {//from ww w .j av a2 s. c o m OutputStream os = new FileOutputStream("test.txt"); InputStream is = new FileInputStream("test.txt"); // write something os.write('A'); // flush the stream os.flush(); // close the stream but it does nothing os.close(); // read what we wrote System.out.println((char) is.read()); is.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {//from w ww. ja va 2 s .c o m OutputStream os = new FileOutputStream("test.txt"); InputStream is = new FileInputStream("test.txt"); // write something os.write('A'); // flush the stream but it does nothing os.flush(); // write something else os.write('B'); // read what we wrote System.out.println(is.available()); os.close(); is.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { char[] passphrase = "sasquatch".toCharArray(); KeyStore keystore = KeyStore.getInstance("JKS"); keystore.load(new FileInputStream(".keystore"), passphrase); TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); tmf.init(keystore);// w ww . j a va 2 s .c o m SSLContext context = SSLContext.getInstance("TLS"); TrustManager[] trustManagers = tmf.getTrustManagers(); context.init(null, trustManagers, null); SSLSocketFactory sf = context.getSocketFactory(); Socket s = sf.createSocket(HOST, PORT); OutputStream out = s.getOutputStream(); out.write("\nConnection established.\n\n".getBytes()); int theCharacter = 0; theCharacter = System.in.read(); while (theCharacter != '~') // The '~' is an escape character to exit { out.write(theCharacter); out.flush(); theCharacter = System.in.read(); } out.close(); s.close(); }
From source file:de.fischer.thotti.core.distbuilder.CommonsCompressTest.java
public static void main(String[] args) throws IOException, ArchiveException { File output = new File("C:\\projekte\\thotti.master\\test.zip"); File file1 = new File("C:\\projekte\\thotti.master\\pom.xml"); File file2 = new File("C:\\projekte\\thotti.master\\todo.txt"); final OutputStream out = new FileOutputStream(output); ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("zip", out); os.putArchiveEntry(new ZipArchiveEntry("testdata/test1.xml")); IOUtils.copy(new FileInputStream(file1), os); os.closeArchiveEntry();//from ww w . j ava2 s. c o m os.putArchiveEntry(new ZipArchiveEntry("testdata/test2.xml")); IOUtils.copy(new FileInputStream(file2), os); os.closeArchiveEntry(); out.flush(); os.close(); }
From source file:com.boundary.zoocreeper.Backup.java
public static void main(String[] args) throws IOException, InterruptedException, KeeperException { BackupOptions options = new BackupOptions(); CmdLineParser parser = new CmdLineParser(options); try {/*from w w w . j a v a2s .co m*/ parser.parseArgument(args); if (options.help) { usage(parser, 0); } } catch (CmdLineException e) { if (!options.help) { System.err.println(e.getLocalizedMessage()); } usage(parser, options.help ? 0 : 1); } if (options.verbose) { LoggingUtils.enableDebugLogging(Backup.class.getPackage().getName()); } Backup backup = new Backup(options); OutputStream os; if ("-".equals(options.outputFile)) { os = System.out; } else { os = new BufferedOutputStream(new FileOutputStream(options.outputFile)); } try { if (options.compress) { os = new GZIPOutputStream(os); } backup.backup(os); } finally { os.flush(); Closeables.close(os, true); } }