List of usage examples for java.io BufferedOutputStream BufferedOutputStream
public BufferedOutputStream(OutputStream out)
From source file:Main.java
/** * Compress a String to a zip file that has only one entry like zipName * The name shouldn't have .zip//w ww . j a va2s . c o m * * @param content * @param fName * @throws IOException */ public static void zipAContentAsFileName(String fName, String content, String charset) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(content.getBytes(charset)); BufferedInputStream bis = new BufferedInputStream(bais); File f = new File(fName); File parentFile = f.getParentFile(); if (!parentFile.exists()) { parentFile.mkdirs(); } ZipOutputStream zf = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(f + ".zip"))); ZipEntry entry = new ZipEntry(f.getName()); zf.putNextEntry(entry); byte[] barr = new byte[8192]; int len = 0; while ((len = bis.read(barr)) != -1) { zf.write(barr, 0, len); } zf.flush(); zf.close(); bis.close(); bais.close(); }
From source file:Main.java
public static void saveImageToSD(Context ctx, String filePath, Bitmap bitmap, int quality) throws IOException { if (bitmap != null) { File file = new File(filePath.substring(0, filePath.lastIndexOf(File.separator))); if (!file.exists()) { file.mkdirs();//from w w w. ja va2 s .co m } file = new File(filePath); if (!file.exists()) { file.createNewFile(); } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); bitmap.compress(CompressFormat.JPEG, quality, bos); bos.flush(); bos.close(); if (ctx != null) { scanPhoto(ctx, filePath); } } }
From source file:Main.java
private static void fileUnZip(ZipInputStream zis, File file) throws FileNotFoundException, IOException { java.util.zip.ZipEntry zip = null; while ((zip = zis.getNextEntry()) != null) { String name = zip.getName(); File f = new File(file.getAbsolutePath() + File.separator + name); if (zip.isDirectory()) { f.mkdirs();/* w w w . java 2 s . c om*/ } else { f.getParentFile().mkdirs(); f.createNewFile(); BufferedOutputStream bos = null; try { bos = new BufferedOutputStream(new FileOutputStream(f)); byte b[] = new byte[2048]; int aa = 0; while ((aa = zis.read(b)) != -1) { bos.write(b, 0, aa); } bos.flush(); } finally { bos.close(); } bos.close(); } } }
From source file:Main.java
public static boolean saveBitmapToSDCard(Bitmap bitmap, String filePath, String fileName) { boolean flag = false; if (null != bitmap) { try {/* www . j av a2s .c om*/ fileName = fileName + ".jpg"; File file = new File(filePath); if (!file.exists()) { file.mkdirs(); } File f = new File(filePath + fileName); if (f.exists()) { f.delete(); } BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(f)); bitmap.compress(CompressFormat.JPEG, 100, outputStream); outputStream.flush(); outputStream.close(); flag = true; } catch (FileNotFoundException e) { flag = false; } catch (IOException e) { flag = false; } } return flag; }
From source file:Main.java
public static BufferedOutputStream toBufferedOutputStream(OutputStream outputStream) { return outputStream instanceof BufferedOutputStream ? (BufferedOutputStream) outputStream : new BufferedOutputStream(outputStream); }
From source file:Main.java
public static File saveBitmap2file(Bitmap bmp) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] byteArray = stream.toByteArray(); File imageFile = null;/*from ww w . j av a 2 s.com*/ try { imageFile = File.createTempFile("tempImage" + System.currentTimeMillis(), ".png"); } catch (IOException e) { e.printStackTrace(); } FileOutputStream fstream = null; try { fstream = new FileOutputStream(imageFile); BufferedOutputStream bStream = new BufferedOutputStream(fstream); bStream.write(byteArray); if (bStream != null) { bStream.close(); } } catch (IOException e) { e.printStackTrace(); } return imageFile; }
From source file:Main.java
public static boolean copyFile2(File src, File dst) { FileInputStream i;//ww w.j ava2 s. c o m try { i = new FileInputStream(src); BufferedInputStream in = new BufferedInputStream(i); FileOutputStream o = new FileOutputStream(dst); BufferedOutputStream out = new BufferedOutputStream(o); byte[] b = new byte[1024 * 5]; int len; while ((len = in.read(b)) != -1) { out.write(b, 0, len); } out.flush(); in.close(); out.close(); o.close(); i.close(); return true; } catch (IOException e) { e.printStackTrace(); return false; } }
From source file:MainClass.java
public static void desEncrypt(String f1, String f2) throws Exception { SecretKey key = null;//from w ww . j av a2 s . c om ObjectInputStream keyFile = new ObjectInputStream(new FileInputStream("DESKey.ser")); key = (SecretKey) keyFile.readObject(); keyFile.close(); Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, key); CipherInputStream in = new CipherInputStream(new BufferedInputStream(new FileInputStream(f1)), cipher); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f2)); int i; do { i = in.read(); if (i != -1) out.write(i); } while (i > 0); in.close(); out.close(); }
From source file:Main.java
public static void saveRgb2Bitmap(IntBuffer buf, String filePath, int width, int height) { final int[] pixelMirroredArray = new int[width * height]; Log.d("TryOpenGL", "Creating " + filePath); BufferedOutputStream bos = null; try {//from ww w. j a v a2 s . c om int[] pixelArray = buf.array(); // rotate 180 deg with x axis because y is reversed for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { pixelMirroredArray[(height - i - 1) * width + j] = pixelArray[i * width + j]; } } bos = new BufferedOutputStream(new FileOutputStream(filePath)); Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bmp.copyPixelsFromBuffer(IntBuffer.wrap(pixelMirroredArray)); bmp.compress(Bitmap.CompressFormat.JPEG, 90, bos); bmp.recycle(); } catch (IOException e) { e.printStackTrace(); } finally { if (bos != null) { try { bos.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:MainClass.java
public static void blowfishEncrypt(String f1, String f2) throws Exception { SecretKey key = null;//from w ww . jav a 2s .com ObjectInputStream keyFile = new ObjectInputStream(new FileInputStream("BlowfishKey.ser")); key = (SecretKey) keyFile.readObject(); keyFile.close(); Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, key); CipherInputStream in = new CipherInputStream(new BufferedInputStream(new FileInputStream(f1)), cipher); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f2)); int i; do { i = in.read(); if (i != -1) out.write(i); } while (i > 0); in.close(); out.close(); }