Java InputStream Read Bytes readBytes(InputStream inputStream, int bufSize)

Here you can find the source of readBytes(InputStream inputStream, int bufSize)

Description

read Bytes

License

Apache License

Declaration

public static byte[] readBytes(InputStream inputStream, int bufSize) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static byte[] readBytes(InputStream inputStream, int bufSize) throws IOException {
        byte[] buf = new byte[bufSize];
        byte[] data = new byte[0];
        int length = 0;
        while ((length = inputStream.read(buf)) > 0) {
            int oldLength = data.length;
            byte[] temp = new byte[oldLength];
            System.arraycopy(data, 0, temp, 0, oldLength);
            data = new byte[length + oldLength];
            System.arraycopy(temp, 0, data, 0, oldLength);
            System.arraycopy(buf, 0, data, oldLength, length);
        }/* w  w  w.  ja v  a 2  s  .  c  o  m*/
        return data;
    }
}

Related

  1. readBytes(InputStream inputStream)
  2. readBytes(InputStream inputStream)
  3. readBytes(InputStream inputStream)
  4. readBytes(InputStream inputStream, boolean close)
  5. readBytes(InputStream inputStream, byte[] buffer, int offset, int length)
  6. readBytes(InputStream inputStream, int length)
  7. readBytes(InputStream inputStream, int numberOfBytes)
  8. readBytes(InputStream inputStream, int numberOfBytes)
  9. readBytes(InputStream ins, byte[] buf, int size)