Android InputStream Copy writeStream(InputStream input, OutputStream output)

Here you can find the source of writeStream(InputStream input, OutputStream output)

Description

write Stream

Declaration

public static void writeStream(InputStream input, OutputStream output) 

Method Source Code

import java.io.*;
import java.nio.channels.*;

public class Main{
    public static void writeStream(InputStream input, OutputStream output) {
        try {/*  w w  w .j a v  a2 s. c  om*/
            append(input, output);
            Closeable zCloseable = output;
            output = null;
            close(zCloseable);
        } finally {
            dispose(output);
        }
    }
    public static void append(InputStream input, OutputStream output) {
        assertNotNull("input", input);
        assertNotNull("output", output);
        byte[] buf = new byte[1024];
        try {
            for (int len; (len = input.read(buf)) > -1;) {
                if (len != 0) {
                    output.write(buf, 0, len);
                }
            }
        } catch (IOException e) {
            throw new WrappedIOException(e);
        }
    }
    public static void close(Closeable pCloseable) {
        if (pCloseable != null) {
            try {
                pCloseable.close();
            } catch (IOException e) {
                throw new WrappedIOException(e);
            }
        }
    }
    public static Closeable dispose(Closeable pCloseable) {
        if (pCloseable != null) {
            try {
                pCloseable.close();
            } catch (IOException ignore) {
                // Whatever!
            }
            pCloseable = null;
        }
        return pCloseable;
    }
}

Related

  1. copyFile(InputStream from, String target)
  2. copyFile(InputStream in, File out)
  3. copyFile(InputStream in, OutputStream out)
  4. copyFile(InputStream input, OutputStream output)
  5. copyStream(InputStream in, OutputStream out)
  6. CopyStream(InputStream is, OutputStream os)
  7. CopyStream(InputStream is, OutputStream os)
  8. copyStream(InputStream src, OutputStream dest)
  9. copyAllBytes(InputStream in, OutputStream out)