List of utility methods to do File Read via ByteBuffer
int | readInt(InputStream inputStream) read Int byte[] bytesToRead = new byte[4]; int readBytes = inputStream.read(bytesToRead); if (readBytes == -1) { return -1; ByteBuffer buffer = ByteBuffer.wrap(bytesToRead); buffer.order(ByteOrder.LITTLE_ENDIAN); return buffer.getInt(); ... |
int | readInt(ReadableByteChannel channel) Read an integer value from a channel. ByteBuffer buf = ByteBuffer.allocate(4); int count = 0; while (count < 4) { int n = 0; while (n == 0) n = channel.read(buf); if (n < 0) throw new ClosedChannelException(); ... |
int | readInt(ReadableByteChannel channel) read Int ByteBuffer buf = ByteBuffer.allocate(4); if (fillBuffer(channel, buf, true)) { buf.rewind(); return buf.getInt(); return -1; |
int | readInt16(DataInput di) Read a 16-bit big-endian signed integer final byte[] buf = { 0x00, 0x00 }; di.readFully(buf, 0, 2); final int i = ByteBuffer.wrap(buf).getShort(); return i; |
int[] | readIntArray(DataInput input) read Int Array int length = input.readInt(); byte[] bytes = new byte[length * 4]; input.readFully(bytes); int[] data = new int[length]; ByteBuffer.wrap(bytes).asIntBuffer().get(data); return data; |
int | readIntLittleEndian(InputStream in) read Int Little Endian int ch1 = in.read(); int ch2 = in.read(); int ch3 = in.read(); int ch4 = in.read(); if ((ch1 | ch2 | ch3 | ch4) < 0) { throw new EOFException(); return ((ch4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1 << 0)); ... |
ByteBuffer | readIntoBuffer(RandomAccessFile file, int offset, int size) Reading bytes from a file into a ByteBuffer ByteBuffer buffer = ByteBuffer.allocate(size);
buffer.order(BYTE_ORDER);
file.seek(offset);
file.read(buffer.array());
return buffer;
|
JSONObject | readJsonFromFile(String path) Reads JSON object (in string format) from specified file. return new JSONObject(readStringFromFile(path)); |
String | readLargeFile(File file) Read large > 5Mb text files to String. FileChannel channel = new FileInputStream(file).getChannel(); ByteBuffer buffer = ByteBuffer.allocate((int) channel.size()); channel.read(buffer); channel.close(); return new String(buffer.array()); |
long | readLong(byte[] src, int pointer) read Long return ByteBuffer.wrap(src, pointer, 8).getLong();
|