Created
January 11, 2010 04:00
-
-
Save bluepapa32/273989 to your computer and use it in GitHub Desktop.
Copy InputStream to OutputStream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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