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

longreadLong(InputStream input)
read Long
byte[] longBytes = new byte[LONG_LEN];
int r = input.read(longBytes, 0, LONG_LEN);
if (r != LONG_LEN) {
    throw new IOException("Bytes missing: read " + r + ", expected " + LONG_LEN);
return ByteBuffer.wrap(longBytes).getLong();
longreadLong(InputStream is)
read Long
byte[] b = new byte[8];
is.read(b);
return ByteBuffer.wrap(b).getLong();
longreadLong(InputStream is, ByteOrder bo)
Read a single long from the InputStream using given ByteOrder pointer respectively.
byte[] bbuf = new byte[Long.SIZE / 8];
int read = is.read(bbuf);
if (read < bbuf.length)
    throw new IOException("could not read required bytes");
ByteBuffer bb = ByteBuffer.wrap(bbuf);
bb.order(bo);
return bb.getLong();
longreadLong(RandomAccessFile raFile)
read Long
byte[] theBytes = new byte[8];
int count = raFile.read(theBytes);
if (8 == count) {
    return ByteBuffer.wrap(theBytes).getLong();
} else {
    throw new EOFException("not enough data to satisfy read of long value");
intreadLTriad(byte[] triad)
read L Triad
return triad[0] + (triad[1] << 8) + (triad[2] << 16);
byte[]readNByte(ReadableByteChannel channel, int n)
read N Byte
byte[] result = new byte[n];
channel.read(ByteBuffer.wrap(result));
return result;
ListreadNIOFile(String filePath)
read NIO File
List<String> lineList = new ArrayList<String>();
RandomAccessFile aFile = new RandomAccessFile(filePath, "r");
FileChannel inChannel = aFile.getChannel();
MappedByteBuffer buffer = inChannel.map(FileChannel.MapMode.READ_ONLY, 0, inChannel.size());
buffer.load();
char c = '0';
StringBuffer lineStr = new StringBuffer();
for (int i = 0; i < buffer.limit(); i++) {
...
shortreadShort(byte[] bytes, int start)
Reads a short from the bytes array start position.
ByteBuffer bb = shortBuffer.get();
bb.clear();
bb.put(bytes[start + 0]);
bb.put(bytes[start + 1]);
return bb.getShort(0);
shortreadShort(DataInput input)
read Short
byte[] buf = new byte[2];
input.readFully(buf);
ByteBuffer bb = ByteBuffer.wrap(buf).order(ByteOrder.LITTLE_ENDIAN);
return bb.getShort(0);
ByteBufferreadShortBuffer(DataInputStream input)
read Short Buffer
short size = input.readShort();
if (size < 0) {
    return null;
ByteBuffer buffer = ByteBuffer.allocate(size);
int read = 0;
while (read < size) {
    int readBytes = input.read(buffer.array());
...