List of usage examples for java.io BufferedOutputStream BufferedOutputStream
public BufferedOutputStream(OutputStream out)
From source file:WriteBinaryFile.java
private static DataOutputStream openOutputStream(String name) throws Exception { DataOutputStream out = null;//from w w w . j av a 2 s . c o m File file = new File(name); out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); return out; }
From source file:Main.java
public static boolean upZipFile(File zipFile, String folderPath) throws ZipException, IOException { ZipFile zfile = new ZipFile(zipFile); Enumeration<? extends ZipEntry> zList = zfile.entries(); ZipEntry ze = null;//from w w w.j a v a 2 s . c om byte[] buf = new byte[1024]; while (zList.hasMoreElements()) { ze = (ZipEntry) zList.nextElement(); if (ze.isDirectory()) { continue; } Log.d(TAG, "ze.getName() = " + ze.getName()); OutputStream os = new BufferedOutputStream( new FileOutputStream(getRealFileName(folderPath, ze.getName()))); InputStream is = new BufferedInputStream(zfile.getInputStream(ze)); int readLen = 0; while ((readLen = is.read(buf, 0, 1024)) != -1) { os.write(buf, 0, readLen); } is.close(); os.close(); } zfile.close(); return true; }
From source file:Main.java
public static void copyFile(File in, File out) throws IOException { // avoids copying a file to itself if (in.equals(out)) { return;/* ww w . j a v a2 s . c o m*/ } // ensure the output file location exists out.getCanonicalFile().getParentFile().mkdirs(); BufferedInputStream fis = new BufferedInputStream(new FileInputStream(in)); BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(out)); // a temporary buffer to read into byte[] tmpBuffer = new byte[8192]; int len = 0; while ((len = fis.read(tmpBuffer)) != -1) { // add the temp data to the output fos.write(tmpBuffer, 0, len); } // close the input stream fis.close(); // close the output stream fos.flush(); fos.close(); }
From source file:com.mayalogy.mayu.io.FileAppender.java
private static OutputStream outStream(final File f) throws IOException { return new BufferedOutputStream(new FileOutputStream(f, true)); }
From source file:Main.java
public static String zip(String filename) throws IOException { BufferedInputStream origin = null; Integer BUFFER_SIZE = 20480;//from w w w . j a v a 2 s. com if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) { File flockedFilesFolder = new File( Environment.getExternalStorageDirectory() + File.separator + "FlockLoad"); System.out.println("FlockedFileDir: " + flockedFilesFolder); String uncompressedFile = flockedFilesFolder.toString() + "/" + filename; String compressedFile = flockedFilesFolder.toString() + "/" + "flockZip.zip"; ZipOutputStream out = new ZipOutputStream( new BufferedOutputStream(new FileOutputStream(compressedFile))); out.setLevel(9); try { byte data[] = new byte[BUFFER_SIZE]; FileInputStream fi = new FileInputStream(uncompressedFile); System.out.println("Filename: " + uncompressedFile); System.out.println("Zipfile: " + compressedFile); origin = new BufferedInputStream(fi, BUFFER_SIZE); try { ZipEntry entry = new ZipEntry( uncompressedFile.substring(uncompressedFile.lastIndexOf("/") + 1)); out.putNextEntry(entry); int count; while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) { out.write(data, 0, count); } } finally { origin.close(); } } finally { out.close(); } return "flockZip.zip"; } return null; }
From source file:Main.java
/** * Method to save audio file to SD card/*from www. j a v a2s .co m*/ * @param course_title, title of course * @param format, the file format, for example .mp3, .txt */ public static boolean copyToStorage(File source_file, String course_title, String format) { File output_file = getEmptyFileWithStructuredPath(course_title, format); try { byte[] buffer = new byte[4096]; int bytesToHold; BufferedInputStream bis = new BufferedInputStream(new FileInputStream(source_file)); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(output_file)); while ((bytesToHold = bis.read(buffer)) != -1) { bos.write(buffer, 0, bytesToHold); } bos.flush(); bos.close(); return true; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return false; }
From source file:hr.softwarecity.osijek.utility.Multimedia.java
/** * Method for uploading files// w w w . j a va 2s .com * @param path path to put file * @param file file to upload * @return path to file or Failed keyword on fail * @throws java.nio.file.FileSystemException * @throws java.io.FileNotFoundException */ public static String handleFileUpload(String path, MultipartFile file) throws IOException { Logger.getLogger("Multimedia.java").log(Logger.Level.INFO, "Initiating file upload"); if (!file.isEmpty()) { byte[] bytes = file.getBytes(); BufferedOutputStream stream = new BufferedOutputStream( new FileOutputStream(new File(path, file.getOriginalFilename()))); stream.write(bytes); stream.close(); Logger.getLogger("Multimedia.java").log(Logger.Level.INFO, "File uploaded"); return path; } else { Logger.getLogger("Multimedia.java").log(Logger.Level.ERROR, "File size 0! "); return null; } }
From source file:Main.java
public static int upZipFile(File zipFile, String folderPath) throws IOException { ZipFile zfile = new ZipFile(zipFile); Enumeration zList = zfile.entries(); ZipEntry ze = null;//from ww w. ja v a2 s . com byte[] buf = new byte[1024]; while (zList.hasMoreElements()) { ze = (ZipEntry) zList.nextElement(); if (ze.isDirectory()) { String dirstr = folderPath + ze.getName(); dirstr = new String(dirstr.getBytes("8859_1"), "GB2312"); File f = new File(dirstr); f.mkdirs(); continue; } OutputStream os = new BufferedOutputStream( new FileOutputStream(getRealFileName(folderPath, ze.getName()))); InputStream is = new BufferedInputStream(zfile.getInputStream(ze)); int readLen = 0; while ((readLen = is.read(buf, 0, 1024)) != -1) { os.write(buf, 0, readLen); } is.close(); os.close(); } zfile.close(); return 0; }
From source file:Main.java
public static File saveBmpFile(Bitmap bmp, String filePath, String fileName) { File dirFile = new File(filePath); if (!dirFile.exists()) { dirFile.mkdir();//from w w w . j a va 2 s .co m } File wantSaveFile = new File(filePath + "/" + fileName); try { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(wantSaveFile)); if (fileName.contains(".jpg")) { bmp.compress(Bitmap.CompressFormat.JPEG, 100, bos); } else { bmp.compress(Bitmap.CompressFormat.PNG, 100, bos); } bos.flush(); bos.close(); } catch (IOException e) { e.printStackTrace(); } return wantSaveFile; }
From source file:ZipHelper.java
public static void fileToZip(File file, File zipFile, int compressionLevel) throws Exception { zipFile.createNewFile();/*w w w . java 2 s . com*/ FileOutputStream fout = new FileOutputStream(zipFile); ZipOutputStream zout = null; try { zout = new ZipOutputStream(new BufferedOutputStream(fout)); zout.setLevel(compressionLevel); if (file.isDirectory()) { File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) fileToZip(files[i], zout, file); } else if (file.isFile()) { fileToZip(file, zout, file.getParentFile()); } } finally { if (zout != null) zout.close(); } }