Created
January 24, 2015 00:11
-
-
Save subinkrishna/a20a463cc965b05b1aa3 to your computer and use it in GitHub Desktop.
copyStream() - copies contents from one stream to other
This file contains hidden or 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 static void copy(final InputStream in, | |
final OutputStream out, | |
final boolean closeStreams) throws IOException { | |
final int kilobyte = 1024; | |
byte[] buffer = null; | |
int count = -1; | |
if ((null != in) && (null != out)) { | |
try { | |
buffer = new byte[kilobyte]; | |
while (-1 != (count = in.read(buffer))) { | |
out.write(buffer, 0, count); | |
} | |
} finally { | |
buffer = null; | |
// Close streams | |
if (closeStreams) { | |
try { | |
in.close(); | |
out.close(); | |
} catch (Throwable t) { | |
t.printStackTrace(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment