List of usage examples for java.io OutputStream flush
public void flush() throws IOException
From source file:cltestgrid.Upload2.java
private static void saveBlob(String blobName, String contentType, byte[] data) throws IOException { log.info("saving blob " + blobName); FileWriteChannel blobChannel = newBlobChannel(blobName, contentType); OutputStream ostream = Channels.newOutputStream(blobChannel); ostream.write(data);//from w w w .j ava2s .c om ostream.flush(); blobChannel.closeFinally(); }
From source file:de.qaware.chronix.converter.common.Compression.java
/*** * Compressed the given stream using gzip. * * @param stream the input stream// w w w . j av a 2 s . co m * @return an byte[] with the compressed data from the stream */ public static byte[] compressFromStream(InputStream stream) { if (stream == null) { LOGGER.debug("Stream is null. Returning null."); return null; } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); OutputStream zippedStream = null; try { zippedStream = new GZIPOutputStream(byteArrayOutputStream); int nRead; byte[] data = new byte[16384]; while ((nRead = stream.read(data, 0, data.length)) != -1) { zippedStream.write(data, 0, nRead); } zippedStream.flush(); byteArrayOutputStream.flush(); } catch (IOException e) { LOGGER.error("Exception occurred while compressing gzip stream.", e); return null; } finally { IOUtils.closeQuietly(zippedStream); IOUtils.closeQuietly(byteArrayOutputStream); } return byteArrayOutputStream.toByteArray(); }
From source file:com.tohours.imo.util.TohoursUtils.java
/** * // www. j a v a 2 s .c om * @param path * @param charsetName * @param param * @return * @throws IOException */ public static String httpPost(String path, String param, String charsetName) throws IOException { String rv = null; URL url = null; HttpURLConnection conn = null; InputStream input = null; try { url = new URL(path); conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "plain/text"); conn.setRequestProperty("User-Agent", "Tohours Shake Project"); OutputStream os = conn.getOutputStream(); os.write(param.getBytes(charsetName)); os.flush(); os.close(); input = conn.getInputStream(); rv = TohoursUtils.inputStream2String(input, charsetName); } finally { if (input != null) { input.close(); } } return rv; }
From source file:com.tohours.imo.util.TohoursUtils.java
/** * //from w w w . ja va 2s.co m * @param path * @param charsetName * @param param * @return * @throws IOException */ public static String httpsPost(String path, String param, String charsetName) throws IOException { String rv = null; URL url = null; HttpsURLConnection conn = null; InputStream input = null; try { url = new URL(path); conn = (HttpsURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "plain/text"); conn.setRequestProperty("User-Agent", "Tohours Project"); OutputStream os = conn.getOutputStream(); os.write(param.getBytes(charsetName)); os.flush(); os.close(); input = conn.getInputStream(); rv = TohoursUtils.inputStream2String(input, charsetName); } finally { if (input != null) { input.close(); } } return rv; }
From source file:collabedit.Telnet.java
public static void post(String text) { text = text + "\n"; OutputStream outstr = tc.getOutputStream(); byte[] b = new byte[text.length()]; for (int i = 0; i < text.length(); i++) { b[i] = (byte) text.charAt(i); }//from ww w. j a v a 2 s . c o m try { outstr.write(b, 0, text.length()); outstr.flush(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:examples.IOUtil.java
public static final void readWrite(final InputStream remoteInput, final OutputStream remoteOutput, final InputStream localInput, final OutputStream localOutput) { Thread reader, writer;// ww w .ja v a 2 s . c o m reader = new Thread() { public void run() { int ch; try { while (!interrupted() && (ch = localInput.read()) != -1) { remoteOutput.write(ch); remoteOutput.flush(); } } catch (IOException e) { //e.printStackTrace(); } } }; writer = new Thread() { public void run() { try { Util.copyStream(remoteInput, localOutput); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } }; writer.setPriority(Thread.currentThread().getPriority() + 1); writer.start(); reader.setDaemon(true); reader.start(); try { writer.join(); reader.interrupt(); } catch (InterruptedException e) { } }
From source file:Main.java
public static void execute(final String templateDirName, final String templateFileName, final Map param, final OutputStream out) throws IOException, TemplateException { // create configuration Configuration cfg = new Configuration(); cfg.setDirectoryForTemplateLoading(new File(templateDirName)); // get template Template temp = cfg.getTemplate(templateFileName); // execute//from w ww . j ava 2 s .co m temp.process(param, new OutputStreamWriter(out)); // temp.process(new SampleBean(), new OutputStreamWriter(out)); // flush out out.flush(); }
From source file:niclients.main.getni.java
/** * Writes a copy of the content to STDOUT received in inputStream. * /*from w ww .ja va 2s . c om*/ * @param data the inputStream * * @throws IOException */ public static void writeCacheCopyToStdOut(InputStream data) throws IOException { OutputStream out = System.out; int nextChar; System.out.println("Content =>"); while ((nextChar = data.read()) != -1) out.write((char) nextChar); out.write('\n'); out.flush(); System.out.println("<= Content"); }
From source file:Main.java
static public void copyDataBase() throws IOException { OutputStream databaseOutputStream = new FileOutputStream("/mnt/sdcard/jwdroid.db"); InputStream databaseInputStream = new FileInputStream("/data/data/com.jwdroid/databases/jwdroid"); byte[] buffer = new byte[1]; int length;// w w w. ja va2 s . c o m while ((length = databaseInputStream.read(buffer)) > 0) { databaseOutputStream.write(buffer); Log.w("Bytes: ", ((Integer) length).toString()); Log.w("value", buffer.toString()); } databaseOutputStream.flush(); databaseOutputStream.close(); databaseInputStream.close(); }
From source file:com.chen.emailcommon.utility.AttachmentUtilities.java
private static long copyFile(InputStream in, OutputStream out) throws IOException { long size = IOUtils.copy(in, out); in.close();/*from w w w.j a v a 2s. c om*/ out.flush(); out.close(); return size; }