Java InputStream Read Bytes readBytes(InputStream input)

Here you can find the source of readBytes(InputStream input)

Description

read Bytes

License

Open Source License

Declaration

public static byte[] readBytes(InputStream input) throws IOException 

Method Source Code


//package com.java2s;
import java.io.ByteArrayOutputStream;

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

public class Main {

    public static byte[] readBytes(InputStream input) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        load(input, output);/*ww w .  j  a  v  a  2  s .  co m*/
        return output.toByteArray();
    }

    public static long load(InputStream inputStream, OutputStream outputStream) throws IOException {
        return load(inputStream, outputStream, 1024);
    }

    public static long load(InputStream inputStream, OutputStream outputStream, int buffSize) throws IOException {
        long size = 0L;

        int c;
        byte[] bytes = new byte[buffSize];
        while ((c = inputStream.read(bytes, 0, bytes.length)) != -1) {
            outputStream.write(bytes, 0, c);
            size = size + c;
        }
        outputStream.flush();
        //      close(outputStream);
        //      close(inputStream);

        return size;
    }
}

Related

  1. readBytes(InputStream in, int expectedBytes, long timeoutMs)
  2. readBytes(InputStream in, int len, boolean isLE)
  3. readBytes(InputStream in, int length)
  4. readBytes(InputStream in, int maxLeng)
  5. readBytes(InputStream in, long len)
  6. readBytes(InputStream input, byte[] data, int capacity)
  7. readBytes(InputStream input, Class type)
  8. readbytes(InputStream input, int n)
  9. readBytes(InputStream input, int size, byte[] buffer)