List of usage examples for java.io OutputStream write
public void write(byte b[], int off, int len) throws IOException
len
bytes from the specified byte array starting at offset off
to this output stream. From source file:Main.java
static private void copyFile(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int read;//from www.j av a 2s.co m // Copy from input stream to output stream while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } }
From source file:Main.java
public static void copyStream(InputStream is, OutputStream os) { try {// w w w . j a v a 2 s . c om final byte[] bytes = new byte[BUFFER_SIZE]; int count = is.read(bytes, 0, BUFFER_SIZE); while (count > -1) { os.write(bytes, 0, count); count = is.read(bytes, 0, BUFFER_SIZE); } os.flush(); } catch (Exception ex) { Log.e("", "", ex); } }
From source file:Main.java
/** * Copy file from source to destination. * * @param source/*from ww w.j a v a 2 s.com*/ * @param destination * @throws Exception */ public static void copyFile(String source, String destination) throws Exception { try { File f1 = new File(source); File f2 = new File(destination); InputStream in = new FileInputStream(f1); OutputStream out = new FileOutputStream(f2); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } catch (Exception ex) { ex.printStackTrace(); throw ex; } }
From source file:Main.java
public static void byteArrayToFile(byte[] bytes, String filePath) throws Exception { InputStream in = new ByteArrayInputStream(bytes); File destFile = new File(filePath); if (!destFile.getParentFile().exists()) { destFile.getParentFile().mkdirs(); }/*from w ww. j a v a 2s. co m*/ destFile.createNewFile(); OutputStream out = new FileOutputStream(destFile); byte[] cache = new byte[CACHE_SIZE]; int nRead = 0; while ((nRead = in.read(cache)) != -1) { out.write(cache, 0, nRead); out.flush(); } out.close(); in.close(); }
From source file:Main.java
public static void fileCopy(File src, File dst) throws IOException { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst); // Transfer bytes from in to out byte[] buf = new byte[1024]; int len;/* w ww . j a va 2s . c om*/ while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:Main.java
public static void transfer(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = in.read(buffer)) != -1) { out.write(buffer, 0, bytesRead); }//from w w w.j av a 2 s. c om }
From source file:Main.java
public static void copyFile(File src, File dst) throws IOException { if (src.isDirectory()) throw new IOException("Source is a directory"); InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst); // Transfer bytes from in to out byte[] buf = new byte[1024]; int len;/*from ww w. jav a 2 s. c o m*/ while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:Main.java
public static OutputStream loadInputStreamToOutputStream(InputStream input, OutputStream output) { int BUFFER_SIZE = 1024 * 4; byte[] buffer = new byte[BUFFER_SIZE]; int n = 0;/*from ww w .ja va2s . c o m*/ try { while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); } } catch (Exception e) { } return output; }
From source file:Bzip2Uncompress.java
/** * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>. *///from ww w . j a v a2 s. c o m private static void copy(final InputStream input, final OutputStream output) throws IOException { final byte[] buffer = new byte[8024]; int n = 0; while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); } }
From source file:com.stealthyone.mcb.stbukkitlib.utils.FileUtils.java
public static File copyFileFromJar(JavaPlugin plugin, String fileName, File destination) throws IOException { Validate.notNull(plugin, "Plugin cannot be null."); Validate.notNull(fileName, "File name cannot be null."); Validate.notNull(destination, "Destination cannot be null."); InputStream in = plugin.getResource(fileName); if (in == null) throw new FileNotFoundException( "Unable to find file '" + fileName + "' in jar for plugin: '" + plugin.getName() + "'"); OutputStream out = new FileOutputStream(destination); byte[] buf = new byte[1024]; int len;//from w w w .ja v a 2 s . c o m while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.close(); in.close(); return destination; }