Encapsulate the logic to read an entire byte array from the input stream.

@param in
@param len
@return new array read from stream
@throws IOException
547456
static public byte[] readValue(ObjectInput in, int len) throws IOException {
        int bytesRead = 0;
        byte[] data = new byte[len];
        for (int offset = 0; offset < len; offset += bytesRead) {
            bytesRead = in.read(data, offset, len - offset);
            if (bytesRead == -1) {
                throw new IOException("Could not retrieve ");
            }
        }
        return data;
    }
432365
public static byte[] readStream(InputStream in) {
        if(in == null){
            return null;
        }
        ByteArrayOutputStream out = null;
        try {
            out = new ByteArrayOutputStream();
            byte[] buf = new byte[1024 * 8];
            int length = 0;
            while((length = in.read(buf)) != -1){
                out.write(buf, 0, length);
            }
            return out.toByteArray();

        } catch (IOException e) {
            throw new IORuntimeException(e);

        } finally {
            closeQuietly(in);
            closeQuietly(out);
        }
    }
460481
public static byte[] readFullyNoClose(InputStream in) throws IOException {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int count;
        while ((count = in.read(buffer)) != -1) {
            bytes.write(buffer, 0, count);
        }
        return bytes.toByteArray();
    }
1221476
public static byte[][] split(byte[] array, int len) {
		int x = array.length / len;
		int y = array.length % len;
		int z = 0;
		if (y != 0) {
			z = 1;
		}
		byte[][] arrays = new byte[x + z][];
		byte[] arr;
		for (int i = 0; i < x + z; i++) {
			arr = new byte[len];
			if (i == x + z - 1 && y != 0) {
				System.arraycopy(array, i * len, arr, 0, y);
			} else {
				System.arraycopy(array, i * len, arr, 0, len);
			}
			arrays[i] = arr;
		}
		return arrays;
	}
82375
public byte[] readVarArray() throws IOException {
    int len = (int) readVarLong();
    byte[] result = new byte[len];
    in.read(result);
    return result;
  }
1369338
public byte []
readByteArray(int len) throws WireParseException {
	require(len);
	byte [] out = new byte[len];
	System.arraycopy(array, pos, out, 0, len);
	pos += len;
	return out;
}
484437
public static byte[] unmarshallByteArray(ObjectInput in) throws IOException {
      final int size = unmarshallSize(in);
      if (size == NULL_VALUE) {
         return null;
      } else if (size == 0) {
         return Util.EMPTY_BYTE_ARRAY;
      }
      byte[] array = new byte[size];
      in.readFully(array);
      return array;
   }
655634
public static byte[] bytes(InputStream in) throws IOException {
        if (in == null) {
            throw new IllegalArgumentException("input stream cannot be null");
        }
        ByteArrayOutputStream os = null;
        try {
            os = new ByteArrayOutputStream(1024);
            byte[] bytes = new byte[1024];
            int len;
            while ((len = in.read(bytes)) != -1) {
                os.write(bytes, 0, len);
            }
            return os.toByteArray();
        } finally {
            closeQuietly(os);
        }
    }
1113930
public static void readFully(InputStream in, byte[] b) throws IOException, EOFException {
        final int length = b.length;
        int total = 0;
        while (total < length) {
            int amt = in.read(b, total, length - total);
            if (amt < 0) {
                throw new EOFException();
            }
            total += amt;
        }
    }
1358191
public static BufferedImage read (InputStream in)
        throws IOException
    {
        return read(ByteBuffer.wrap(StreamUtil.toByteArray(in)));
    }
666317
public static int copyAllBytes(InputStream in, OutputStream out) throws IOException {
        int byteCount = 0;
        byte[] buffer = new byte[BUFFER_SIZE];
        while (true) {
            int read = in.read(buffer);
            if (read == -1) {
                break;
            }
            out.write(buffer, 0, read);
            byteCount += read;
        }
        return byteCount;
    }
829766
public void readAll(InputStream in) throws IOException {
    int read = 0;
    do {
      grow(length);
      read = data.setBytes(length, in, data.length() - length);
      if (read > 0) {
        length += read;
      }
    } while (in.available() > 0);
  }
1150402
public byte[] readByteArray(int length) throws IOException {
        byte buf[] = new byte[length];
        for (int i = 0; i < length; i++) {
            buf[i] = (byte) read();
        }
        return buf;
    }
290959
public static byte[] readStream(final InputStream inStream) {
		try {
			return IOUtils.toByteArray(inStream);
		} catch (IOException e) {
			throw new JKException(e);
		}
		//
		// try {
		// DataInputStream in = null;
		// try {
		// in = new DataInputStream(inStream);
		// int ch;
		//
		// List<Byte> bytes=new ArrayList<>();
		// while((ch=in.read())!=-1){
		// bytes.add(ch);
		// }
		// return arr;
		// } finally {
		// if (in != null) {
		// in.close();
		// }
		// }
		// } catch (final IOException e) {
		// throw new RuntimeException(e);
		// }
	}
578562
protected int readFully(InputStream in, byte buffer[])
        throws java.io.IOException {
        for (int i = 0; i < buffer.length; i++) {
            int q = in.read();
            if (q == -1)
                return i;
            buffer[i] = (byte)q;
        }
        return buffer.length;
    }
743459
public static int readInt(DataInput in) throws IOException {
        byte len=in.readByte();
        if(len == 0)
            return 0;
        return makeInt(in, len);
    }
1301019
public void read(InputStream in, int lengthToRead) throws IOException {
    int read = 0;
    do {
      grow(length);
      read = data.setBytes(length, in, Math.min(lengthToRead, data.length() - length));
      length += read;
      lengthToRead -= read;
    } while (lengthToRead > 0);
  }