List of usage examples for java.io BufferedOutputStream BufferedOutputStream
public BufferedOutputStream(OutputStream out)
From source file:Main.java
public static String parseObj2Xml(Object object) throws Exception { XMLEncoder encoder = null;/*from w w w .j a v a 2 s. c o m*/ String str = null; BufferedOutputStream bufOut = null; ByteArrayOutputStream out = null; try { out = new ByteArrayOutputStream(); bufOut = new BufferedOutputStream(out); encoder = new XMLEncoder(bufOut); encoder.writeObject(object); encoder.close(); str = new String(out.toByteArray()); } catch (Exception ex) { throw ex; } finally { if (out != null) out.close(); if (bufOut != null) bufOut.close(); } return str; }
From source file:Main.java
public static void saveBArrToFile(String fileName, byte[] barr) throws IOException { File file = new File(fileName); file.getParentFile().mkdirs();//from w ww . ja v a 2 s . co m File tempFile = new File(fileName + ".tmp"); FileOutputStream fos = new FileOutputStream(tempFile); BufferedOutputStream bos = new BufferedOutputStream(fos); bos.write(barr, 0, barr.length); bos.flush(); fos.flush(); bos.close(); fos.close(); file.delete(); tempFile.renameTo(file); }
From source file:Main.java
public static void saveISToFile(InputStream is, String fileName) throws IOException { File file = new File(fileName); file.getParentFile().mkdirs();/*from w w w. j a va 2 s . c om*/ File tempFile = new File(fileName + ".tmp"); FileOutputStream fos = new FileOutputStream(tempFile); BufferedOutputStream bos = new BufferedOutputStream(fos); BufferedInputStream bis = new BufferedInputStream(is); byte[] barr = new byte[32768]; int read = 0; while ((read = bis.read(barr)) > 0) { bos.write(barr, 0, read); } bis.close(); bos.flush(); fos.flush(); bos.close(); fos.close(); file.delete(); tempFile.renameTo(file); }
From source file:PipedBytes.java
public static void writeStuff(OutputStream rawOut) { try {// w w w . ja va 2s . c o m DataOutputStream out = new DataOutputStream(new BufferedOutputStream(rawOut)); int[] data = { 82, 105, 99, 104, 97, 114, 100, 32, 72, 121, 100, 101 }; for (int i = 0; i < data.length; i++) { out.writeInt(data[i]); } out.flush(); out.close(); } catch (IOException x) { x.printStackTrace(); } }
From source file:Main.java
public static void copy(InputStream in, OutputStream out) throws IOException { if (!(in instanceof BufferedInputStream)) { in = new BufferedInputStream(in); }/*from www .j a v a2 s . c o m*/ if (!(out instanceof BufferedOutputStream)) { out = new BufferedOutputStream(out); } int len = 0; byte[] buffer = new byte[1024]; while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); } out.flush(); }
From source file:MainClass.java
public static void copy(InputStream in, OutputStream out) throws IOException { BufferedInputStream bin = new BufferedInputStream(in); BufferedOutputStream bout = new BufferedOutputStream(out); while (true) { int datum = bin.read(); if (datum == -1) break; bout.write(datum);/*from w w w . ja v a2 s . co m*/ } bout.flush(); }
From source file:Main.java
public static void writeFile(byte[] data, File file) { try {// w w w . ja v a2s .c o m BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, false)); bos.write(data); bos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void serializeObjectToFile(final String filePath, final Serializable objectToSeralize) throws FileNotFoundException, IOException { try (OutputStream file = new FileOutputStream(filePath); OutputStream buffer = new BufferedOutputStream(file); XMLEncoder output = new XMLEncoder(buffer);) { output.writeObject(objectToSeralize); }// ww w . ja v a 2 s .co m }
From source file:Main.java
/** * Convert Object to Byte Array/*from ww w .jav a 2 s. c o m*/ * * @param obj * @return * @throws IOException */ public static byte[] convertObjectToByteArray(Object obj) throws IOException { ObjectOutputStream os = null; ByteArrayOutputStream byteStream = new ByteArrayOutputStream(5000); os = new ObjectOutputStream(new BufferedOutputStream(byteStream)); os.flush(); os.writeObject(obj); os.flush(); byte[] sendBuf = byteStream.toByteArray(); os.close(); return sendBuf; }
From source file:Main.java
public static void saveFile(Bitmap bm, String path, String fileName) throws IOException { String uri = path;//from w w w . ja va2 s . c om if (!uri.endsWith("/")) { uri = uri + "/"; } uri = uri + fileName; File dirFile = new File(path); if (!dirFile.exists()) { dirFile.mkdir(); } File myCaptureFile = new File(uri); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile)); bm.compress(Bitmap.CompressFormat.JPEG, 80, bos); bos.flush(); bos.close(); // SharedPreferences sp= }