Java Utililty Methods InputStream Read Bytes

List of utility methods to do InputStream Read Bytes

Description

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

Method

byte[]readBytes(InputStream in, int len, boolean isLE)
Read bytes from input stream.
if (len == 0) {
    return new byte[0];
byte[] bytes = new byte[len];
int rlen = in.read(bytes);
if (rlen != len) {
    throw new IOException("readBytes length is not match." + len + " which is " + rlen);
if (isLE) {
    bytes = reverseBytes(bytes);
return bytes;
byte[]readBytes(InputStream in, int length)
simple method to read some bytes
byte[] data = new byte[length];
readFully(in, data, 0, length);
return data;
byte[]readBytes(InputStream in, int maxLeng)
Reads a number of bytes from a stream.
byte[] buf = new byte[maxLeng];
int pos = 0;
while (maxLeng - pos > 0) {
    int ngot = in.read(buf, pos, maxLeng - pos);
    if (ngot > 0) {
        pos += ngot;
    } else {
        break;
...
byte[]readBytes(InputStream in, long len)
read Bytes
ByteArrayOutputStream out = new ByteArrayOutputStream();
copyRaw(in, out, DEFAULT_BUFFER_SIZE, len);
return out.toByteArray();
byte[]readBytes(InputStream input)
read Bytes
ByteArrayOutputStream output = new ByteArrayOutputStream();
load(input, output);
return output.toByteArray();
intreadBytes(InputStream input, byte[] data, int capacity)
Read bytes up to capacity from the input stream into the given array.
int bytes = 0;
while (bytes < capacity) {
    int size = input.read(data, bytes, capacity - bytes);
    if (size < 0) {
        break;
    bytes = bytes + size;
return bytes;
TreadBytes(InputStream input, Class type)
read Bytes
try {
    try (ObjectInputStream in = new ObjectInputStream(input)) {
        return (T) in.readObject();
} catch (IOException | ClassNotFoundException e) {
    throw new RuntimeException(e);
byte[]readbytes(InputStream input, int n)
read a number of signed bytes
byte[] buffer = new byte[n];
readbytes_into(input, buffer, 0, n);
return buffer;
voidreadBytes(InputStream input, int size, byte[] buffer)
Reads a sequency of bytes into a byte array.
int totalRead = input.read(buffer, 0, size);
while (totalRead < size) {
    int read = input.read(buffer, totalRead, size - totalRead);
    if (read < 0) {
        throw new IOException("Unexpected EOF while reading bytes.");
    totalRead += read;
byte[]readBytes(InputStream inputStream)
read Bytes
byte[] stringBytes = new byte[0];
byte[] bytes = new byte[1024];
int len = 0;
while ((len = inputStream.read(bytes)) > 0) {
    byte[] tempStringBytes = new byte[stringBytes.length + len];
    System.arraycopy(stringBytes, 0, tempStringBytes, 0, stringBytes.length);
    System.arraycopy(bytes, 0, tempStringBytes, stringBytes.length, len);
    stringBytes = tempStringBytes;
...