Java Utililty Methods File Read via ByteBuffer

List of utility methods to do File Read via ByteBuffer

Description

The list of methods to do File Read via ByteBuffer are organized into topic(s).

Method

byte[]readFullyAndClose(InputStream input)
read Fully And Close
ByteBuffer result = ByteBuffer.wrap(new byte[Math.min(512, input.available())]);
while (true) {
    if (result.remaining() == 0) {
        result = ByteBuffer.wrap(Arrays.copyOf(result.array(), result.capacity() * 2));
    int actuallyRead = input.read(result.array(), result.position(), result.remaining());
    if (actuallyRead == -1) {
        break;
...
byte[]readHeaderArea(InputStream in)
read Header Area
int input = 0;
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ByteBuffer last4Chars = ByteBuffer.wrap(new byte[4]);
while ((input = in.read()) != -1) {
    byte inputByte = (byte) input;
    buffer.write(inputByte);
    last4Chars.put(inputByte);
    if (emptyLine(last4Chars)) {
...
ByteBufferreadInputStream(InputStream input)
read Input Stream
byte[] buf = new byte[BUFFER_SIZE];
int idx = 0;
for (;;) {
    int rd = input.read(buf, idx, buf.length - idx);
    if (rd < 0)
        break;
    idx += rd;
    if (idx == buf.length) {
...
StringreadInputStreamToString(InputStream inputStream)
read Input Stream To String
return readInputStreamToString(inputStream, "UTF-8");
intreadInt(byte[] bytes, int index)
read Int
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
return byteBuffer.getInt(index);
intreadInt(byte[] bytes, int offset, java.nio.ByteOrder byteorder)
read Int
return java.nio.ByteBuffer.wrap(bytes, offset, 4).order(byteorder).getInt();
intreadInt(byte[] in)
read Int
return ByteBuffer.wrap(in).getInt();
intreadInt(ByteArrayInputStream bin)
Reads the next 4 bytes from the stream as integer.
byte[] buffer = new byte[4];
bin.read(buffer);
return ByteBuffer.wrap(buffer).getInt();
intreadInt(InputStream in, ByteOrder order)
read Int
ByteBuffer buf = ByteBuffer.allocate(4);
buf.order(order);
readFully(in, buf);
return buf.getInt();
intreadInt(InputStream input)
read Int
byte[] szBytes = new byte[4];
int read = input.read(szBytes);
if (read <= 0) {
    return 0;
return ByteBuffer.wrap(szBytes).getInt();