Skip to content

Instantly share code, notes, and snippets.

@bluepapa32
Created January 11, 2010 04:00
Show Gist options
  • Save bluepapa32/273989 to your computer and use it in GitHub Desktop.
Save bluepapa32/273989 to your computer and use it in GitHub Desktop.
Copy InputStream to OutputStream
public class CopyStream implements Runnable {
private InputStream in;
private OutputStream out;
public CopyStream(InputStream in, OutputStream out) {
this.in = new BufferedInputStream(in);
this.out = new BufferedOutputStream(out);
}
public void run() {
try {
byte[] buf = new byte[2048];
int n = 0;
while ((n = in.read(buf)) > -1) {
out.write(buf, 0, n);
out.flush();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment