Almighty Bus Error

Loading search...

Snippet.Java: Dump InputStream to OutputStream

This piece of code keeps reading 1024 bytes from the InputStream and writing to the OutStream until the read function returns an error value (-1) which means there is not anything else to read.

protected void dumpStream( InputStream in, OutputStream out )
throws IOException {
	byte[] arr = new byte[1024];
	int n;
	do {
		n = in.read( arr );
		out.write( arr, 0, n );
	} while (n != -1);
}
Tags:  Snippet Java