Java Utililty Methods InputStream to OutputStream

List of utility methods to do InputStream to OutputStream

Description

The list of methods to do InputStream to OutputStream are organized into topic(s).

Method

voidcopyStream(InputStream in, OutputStream out)
copy Stream
byte[] buf = new byte[4 * 1024]; 
int bytesRead;
while ((bytesRead = in.read(buf)) != -1) {
    out.write(buf, 0, bytesRead);
voidcopyStream(InputStream in, OutputStream out)
copy Stream
BufferedReader reader = null;
PrintWriter outPrint = null;
try {
    reader = new BufferedReader(new InputStreamReader(in));
    outPrint = new PrintWriter(out);
    String line;
    while ((line = reader.readLine()) != null) {
        outPrint.println(line);
...
voidcopyStream(InputStream in, OutputStream out)
copy Stream
byte[] buffer = new byte[1024 * 1024];
int len;
while ((len = in.read(buffer)) != -1) {
    out.write(buffer, 0, len);
voidcopyStream(InputStream in, OutputStream out)
Copies bytes from input stream into the output stream.
if (in == null || out == null)
    throw new NullPointerException();
int el;
byte[] buffer = new byte[1 << 15];
while ((el = in.read(buffer)) != -1) {
    out.write(buffer, 0, el);
voidcopyStream(InputStream in, OutputStream out)
copy Stream
copyStream(in, out, DEFAULT_CHUNKSIZE);
longcopyStream(InputStream in, OutputStream out)
copy Stream
return copyStream(in, 0, out);
intcopyStream(InputStream in, OutputStream out, boolean closeIn, boolean closeOut)
Copy all bytes from in to out.
int totalBytes = 0;
try {
    byte[] buff = new byte[1024 * 4];
    int bytesRead = 0;
    while ((bytesRead = in.read(buff)) != -1) {
        if (bytesRead > 0) {
            out.write(buff, 0, bytesRead);
            totalBytes += bytesRead;
...
voidcopyStream(InputStream in, OutputStream out, boolean closeOut)
Reads an InputStream and copy all data to an OutputStream.
byte b[] = new byte[BUFFER_SIZE];
int n;
try {
    while ((n = in.read(b)) != -1) {
        out.write(b, 0, n);
} finally {
    try {
...
voidcopyStream(InputStream in, OutputStream out, int bufferSize)
Copies the input stream bytes into the output stream bytes, using the specified buffer size when transfering the bytes.
byte[] buffer = new byte[bufferSize];
int read = 0;
while ((read = in.read(buffer)) >= 0) {
    out.write(buffer, 0, read);
voidcopyStream(InputStream in, OutputStream out, int bufsize)
Copies everything from in to out
byte[] buffer = new byte[bufsize];
int len;
while ((len = in.read(buffer)) != -1)
    out.write(buffer, 0, len);