List of usage examples for java.io OutputStreamWriter flush
public void flush() throws IOException
From source file:Main.java
public static void main(String[] argv) throws Exception { String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8"); data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8"); URL url = new URL("http://server.com:80/cgi"); URLConnection conn = url.openConnection(); conn.setDoOutput(true);// www. j a v a 2 s . c om OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { System.out.println(line); } wr.close(); rd.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { OutputStream stream = System.out; XMLOutputFactory xof = XMLOutputFactory.newFactory(); XMLStreamWriter xsw = xof.createXMLStreamWriter(stream); xsw.writeStartDocument();//from w ww .ja v a 2 s . c o m xsw.writeStartElement("foo"); xsw.writeStartElement("bar"); xsw.writeCharacters(""); xsw.flush(); OutputStreamWriter osw = new OutputStreamWriter(stream); osw.write("<baz>Hello World<baz>"); osw.flush(); xsw.writeEndElement(); xsw.writeEndElement(); xsw.writeEndDocument(); xsw.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://www.java2s.com"); URLConnection conn = url.openConnection(); conn.setDoOutput(true);/* ww w. j a v a 2 s . c o m*/ OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write("value=1&anotherValue=1"); writer.flush(); String line; BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); while ((line = reader.readLine()) != null) { System.out.println(line); } writer.close(); reader.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String pageAddr = "http://www.google.com/index.htm"; URL url = new URL(pageAddr); String websiteAddress = url.getHost(); String file = url.getFile();/* ww w. j a va 2s . c o m*/ Socket clientSocket = new Socket(websiteAddress, 80); BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); OutputStreamWriter outWriter = new OutputStreamWriter(clientSocket.getOutputStream()); outWriter.write("GET " + file + " HTTP/1.0\r\n\n"); outWriter.flush(); BufferedWriter out = new BufferedWriter(new FileWriter(file)); boolean more = true; String input; while (more) { input = inFromServer.readLine(); if (input == null) more = false; else { out.write(input); } } out.close(); clientSocket.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com!"; try {//from w w w .j ava2 s. c om OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os); FileInputStream in = new FileInputStream("test.txt"); writer.write(s, 0, 5); writer.flush(); for (int i = 0; i < 5; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com!"; try {//w ww. j av a 2 s .co m OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os, Charset.defaultCharset()); FileInputStream in = new FileInputStream("test.txt"); writer.write(s, 0, 5); writer.flush(); for (int i = 0; i < 5; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com!"; try {//from w w w . j av a 2 s .c om OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os, Charset.defaultCharset().newEncoder()); FileInputStream in = new FileInputStream("test.txt"); writer.write(s, 0, 5); writer.flush(); for (int i = 0; i < 5; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Base64Stuff.java
public static void main(String[] args) { //Random random = new Random(); try {/*from w ww. j ava2 s .c o m*/ File file1 = new File("C:\\\\Program Files\\\\ImageJ\\\\images\\\\confocal-series-10001.tif"); //File file2 = new File("C:\\Program Files\\ImageJ\\images\\confocal-series-10000.tif"); ImagePlus image1 = new ImagePlus( "C:\\\\Program Files\\\\ImageJ\\\\images\\\\confocal-series-10001.tif"); //ImagePlus image2 = new ImagePlus("C:\\Program Files\\ImageJ\\images\\two.tif"); byte[] myBytes1 = org.apache.commons.io.FileUtils.readFileToByteArray(file1); //byte[] myBytes2 = org.apache.commons.io.FileUtils.readFileToByteArray(file2); //random.nextBytes(randomBytes); //String internalVersion1 = com.sun.org.apache.xerces.internal.impl.dv.util.Base64.encode(myBytes1); //String internalVersion2 = com.sun.org.apache.xerces.internal.impl.dv.util.Base64.encode(myBytes2); byte[] apacheBytes1 = org.apache.commons.codec.binary.Base64.encodeBase64(myBytes1); //byte[] apacheBytes2 = org.apache.commons.codec.binary.Base64.encodeBase64(myBytes2); String string1 = new String(apacheBytes1); //String string2 = new String(apacheBytes2); System.out.println("File1 length:" + string1.length()); //System.out.println("File2 length:" + string2.length()); System.out.println(string1); //System.out.println(string2); System.out.println("Image1 size: (" + image1.getWidth() + "," + image1.getHeight() + ")"); //System.out.println("Image2 size: (" + image2.getWidth() + "," + image2.getHeight() + ")"); String urlParameters = "data=" + string1 + "&size=1000x1000"; URL url = new URL("http://api.qrserver.com/v1/create-qr-code/"); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(urlParameters); writer.flush(); //byte buf[] = new byte[700000000]; BufferedInputStream reader = new BufferedInputStream(conn.getInputStream()); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream("C:\\Users\\expertoweb\\Desktop\\qrcode2.png")); int data; while ((data = reader.read()) != -1) { bos.write(data); } writer.close(); reader.close(); bos.close(); } catch (IOException e) { } }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com!"; try {/*from w w w.j ava 2s . co m*/ OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os, java.nio.charset.StandardCharsets.UTF_8); FileInputStream in = new FileInputStream("test.txt"); writer.write(s, 0, 5); writer.flush(); for (int i = 0; i < 5; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.apiwatch.cli.APIScan.java
public static void main(String[] argv) { try {/*from www. ja va 2 s . c om*/ Namespace args = parseArgs(argv); Logger log = Logger.getLogger(APIDiff.class.getName()); log.trace("Finding files to analyse..."); DirectoryWalker walker = new DirectoryWalker(args.<String>getList(Args.EXCLUDES_OPTION), args.<String>getList(Args.INCLUDES_OPTION)); Set<String> files = walker.walk(args.<String>getList(INPUT_PATHS)); APIScope scope = Analyser.analyse(files, args.getAttrs()); if (args.get(OUTPUT_LOCATION) != null) { IO.putAPIData(scope, args.getString(Args.OUTPUT_FORMAT_OPTION), args.getString(Analyser.ENCODING_OPTION), args.getString(OUTPUT_LOCATION), args.getString(Args.USERNAME_OPTION), args.getString(Args.PASSWORD_OPTION)); } else { OutputStreamWriter writer = new OutputStreamWriter(System.out); Serializers.dumpAPIScope(scope, writer, args.getString(Args.OUTPUT_FORMAT_OPTION)); writer.flush(); writer.close(); } } catch (HttpException e) { Logger.getLogger(APIDiff.class.getName()).error(e.getMessage()); System.exit(1); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }