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
public static long copy(InputStream input, OutputStream output) throws IOException { byte[] buffer = new byte[1024 * 4]; long count = 0; int n;/*w w w. java2 s . c o m*/ while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); count += n; } return count; }
From source file:Main.java
public static long copy(InputStream input, OutputStream output) throws IOException { byte[] buffer = new byte[1024]; long count = 0; int n = 0;//from w ww. j ava 2 s . c o m while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); count += n; } return count; }
From source file:Main.java
public static void copy(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;/*from w ww . ja v a2 s.c o m*/ while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:Main.java
/** * Transfers all bytes that can be read from <tt>in</tt> to <tt>out</tt>. * * @param in The InputStream to read data from. * @param out The OutputStream to write data to. * @return The total number of bytes transfered. *///from w w w .j a v a 2s. c o m public static final long transfer(InputStream in, OutputStream out) throws IOException { long totalBytes = 0; int bytesInBuf = 0; byte[] buf = new byte[4096]; while ((bytesInBuf = in.read(buf)) != -1) { out.write(buf, 0, bytesInBuf); totalBytes += bytesInBuf; } return totalBytes; }
From source file:Main.java
public static void fileCopy(String srcStr, String dstStr) throws IOException { File src = new File(srcStr); File dst = new File(dstStr); InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst); // Transfer bytes from in to out byte[] buf = new byte[1024]; int len;/*from w w w . j a v 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 void copyFile(InputStream in, OutputStream out) { try {//ww w . ja v a 2s . c o m byte[] b = new byte[2 * 1024 * 1024]; //2M memory int len = -1; while ((len = in.read(b)) > 0) { out.write(b, 0, len); out.flush(); } } catch (IOException e) { e.printStackTrace(); } finally { closeIO(in, out); } }
From source file:Main.java
private static void copyAssetFile(AssetManager assetManager, String assetFilePath, String destinationFilePath) throws IOException { InputStream in = assetManager.open(assetFilePath); OutputStream out = new FileOutputStream(destinationFilePath); // Transfer bytes from in to out byte[] buf = new byte[8192]; int len;/* w ww.j av a 2 s . co m*/ while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:Main.java
static void copy(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[0xFFFF]; int len;//from w ww .ja v a 2 s . c o m while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); } }
From source file:Main.java
public static void copyStream(InputStream in, OutputStream out) { try {// www .j a v a 2 s. co m // Transfer bytes from in to out byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
/** * Copies the contents of one stream to the other. * @param in not null/*from w w w. ja v a 2 s.c o m*/ * @param out not null * @throws IOException */ public static void copy(final InputStream in, final OutputStream out) throws IOException { final byte[] buffer = new byte[DEFAULT_ENCODING_BUFFER_SIZE]; int inputLength; while (-1 != (inputLength = in.read(buffer))) { out.write(buffer, 0, inputLength); } }