@Test public void copyStream_withMaxBytes_belowThreshold_shouldCopyContentsOfOneStreamToAnother() throws Exception { File inFile = new File("etc/expectedFile.jpg"); FileInputStream in = new FileInputStream(inFile); File tempFile = File.createTempFile("foo", "bar"); FileOutputStream out = new FileOutputStream(tempFile); Streams.copyContent(in, out, 1000000); assertThat(inFile.length()).isEqualTo(tempFile.length()); }
public static void copyContent(final InputStream inputStream, final OutputStream outputStream) throws IOException { if (inputStream == null || outputStream == null) { throw new IOException("Unable to copy from or to a null stream."); } byte[] buffer = new byte[16384]; int length; while ((length = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, length); } }
Streams { public static void copyContent(final InputStream inputStream, final OutputStream outputStream) throws IOException { if (inputStream == null || outputStream == null) { throw new IOException("Unable to copy from or to a null stream."); } byte[] buffer = new byte[16384]; int length; while ((length = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, length); } } }
Streams { public static void copyContent(final InputStream inputStream, final OutputStream outputStream) throws IOException { if (inputStream == null || outputStream == null) { throw new IOException("Unable to copy from or to a null stream."); } byte[] buffer = new byte[16384]; int length; while ((length = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, length); } }  }
Streams { public static void copyContent(final InputStream inputStream, final OutputStream outputStream) throws IOException { if (inputStream == null || outputStream == null) { throw new IOException("Unable to copy from or to a null stream."); } byte[] buffer = new byte[16384]; int length; while ((length = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, length); } }  static void copyContent(final InputStream inputStream, final OutputStream outputStream); static void copyContent(final InputStream inputStream, final OutputStream outputStream, final long maxBytes); static void readStream(final InputStream inputStream, byte[] buffer); static void closeStream(Closeable stream); }
Streams { public static void copyContent(final InputStream inputStream, final OutputStream outputStream) throws IOException { if (inputStream == null || outputStream == null) { throw new IOException("Unable to copy from or to a null stream."); } byte[] buffer = new byte[16384]; int length; while ((length = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, length); } }  static void copyContent(final InputStream inputStream, final OutputStream outputStream); static void copyContent(final InputStream inputStream, final OutputStream outputStream, final long maxBytes); static void readStream(final InputStream inputStream, byte[] buffer); static void closeStream(Closeable stream);  }