Android InputStream Read readAllBytesToOutput(InputStream is, OutputStream output)

Here you can find the source of readAllBytesToOutput(InputStream is, OutputStream output)

Description

read All Bytes To Output

License

Open Source License

Declaration

private static int readAllBytesToOutput(InputStream is,
            OutputStream output) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    private static final int TEMP_BUFFER_DEFAULT_LENGTH = 2048;

    private static int readAllBytesToOutput(InputStream is,
            OutputStream output) throws IOException {
        //ByteArrayOutputStream output = new ByteArrayOutputStream();
        byte[] tempBuffer = new byte[TEMP_BUFFER_DEFAULT_LENGTH];
        int readed;
        int totalRead = 0;

        while (true) {
            readed = is.read(tempBuffer, 0, TEMP_BUFFER_DEFAULT_LENGTH);
            if (readed < 0) {
                //no more to read
                break;
            }/*  w w w. j  a v  a2  s. c  o  m*/

            totalRead += readed;

            if (readed != 0) {
                output.write(tempBuffer, 0, readed);
                output.flush();
            }
        }

        return totalRead;
    }
}

Related

  1. readStream(InputStream in)
  2. readStream(InputStream in)
  3. readToFile(InputStream in, File localFile)
  4. readAllAndClose(InputStream is)
  5. readAllBytes(InputStream in)
  6. readAllNoClose(InputStream is)
  7. readBSInt(InputStream is)
  8. readFully(InputStream inputStream)
  9. readFullyAndClose(InputStream is)