Android Utililty Methods InputStream Copy

List of utility methods to do InputStream Copy

Description

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

Method

voidcopy(InputStream pSourceStream, OutputStream pTargetStream, boolean closeSource)
destination is not closed on exit of method !
final int buffSize = 1024;
final byte[] lBuf = new byte[buffSize];
int lBytesRead = 0;
while ((lBytesRead = pSourceStream.read(lBuf, 0, buffSize)) != -1) {
    pTargetStream.write(lBuf, 0, lBytesRead);
if (closeSource) {
    pSourceStream.close();
...
voidcopyContents(InputStream in, OutputStream out)
Just copies all bytes from in to out.
byte[] buf = new byte[BUFFER_SIZE];
int bytesRead = 0;
while ((bytesRead = in.read(buf)) > 0) {
    out.write(buf, 0, bytesRead);
out.flush();
voidcopyFile(InputStream from, String target)
copy File
FileUtil.makeParent(target);
BufferedInputStream input = new BufferedInputStream(from);
BufferedOutputStream out = new BufferedOutputStream(
        new FileOutputStream(target));
try {
    byte[] buff = new byte[2048];
    int size = 0;
    while ((size = input.read(buff)) != -1) {
...
booleancopyFile(InputStream in, File out)
copy File
try {
    return copyFile(in, new FileOutputStream(out));
} catch (Exception e) {
    e.printStackTrace();
    return false;
voidcopyFile(InputStream in, OutputStream out)
copy File
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
    out.write(buffer, 0, read);
out.flush();
booleancopyFile(InputStream input, OutputStream output)
copy File
try {
    byte[] buf = new byte[1024];
    int len;
    while ((len = input.read(buf)) > 0) {
        output.write(buf, 0, len);
} catch (Exception e) {
    e.printStackTrace();
...
longcopyStream(InputStream in, OutputStream out)
Copies data from one stream to another, until the input stream ends.
long total = 0;
int len;
byte[] buffer = new byte[DEFAULT_READ_BUFFER_SIZE];
while ((len = in.read(buffer)) >= 0) {
    out.write(buffer, 0, len);
    total += len;
return total;
...
voidwriteStream(InputStream input, OutputStream output)
write Stream
try {
    append(input, output);
    Closeable zCloseable = output;
    output = null;
    close(zCloseable);
} finally {
    dispose(output);
voidCopyStream(InputStream is, OutputStream os)
Copy Stream
final int buffer_size = 1024;
try {
    byte[] bytes = new byte[buffer_size];
    for (;;) {
        int count = is.read(bytes, 0, buffer_size);
        if (count == -1)
            break;
        os.write(bytes, 0, count);
...
voidCopyStream(InputStream is, OutputStream os)
Copy Stream
final int buffer_size = 1024;
try {
    byte[] bytes = new byte[buffer_size];
    for (;;) {
        int count = is.read(bytes, 0, buffer_size);
        if (count == -1)
            break;
        os.write(bytes, 0, count);
...