List of utility methods to do ByteBuffer Set
void | memset(ByteBuffer dstBuffer, int dstByteOffset, byte value, int length) memset for (int ii = dstByteOffset; ii < dstByteOffset + length; ++ii) { dstBuffer.put(ii, value); |
String | parseContent(ByteBuffer buffer, int offset, int length) parse Content byte[] chunk = new byte[length]; char[] start = new char[length]; try { buffer.get(chunk, offset, length); return new String(chunk, StandardCharsets.ISO_8859_1); } finally { buffer.rewind(); |
ByteBuffer | parseToByteBuffer(Object value) parse To Byte Buffer if (value == null) { return null; if (value instanceof ByteBuffer) { return (ByteBuffer) value; } else { return ByteBuffer.wrap(value.toString().getBytes()); |
int | pourBufferToArray(ByteBuffer source, byte[] destination, int offset, int sizeRequested) Assumes source is ready to be read. int numberToRead = Math.min(source.remaining(), sizeRequested); source.get(destination, offset, numberToRead); return numberToRead; |
BitSet | readBitset(ByteBuffer bb, int numbytes) Reads a series of bytes from the given buffer, turning them into a little-endian bit-set. byte[] barr = new byte[numbytes]; bb.get(barr); BitSet ret = new BitSet(numbytes * 8); for (int i_byte = 0; i_byte < barr.length; i_byte++) { for (int i = 0; i < 8; i++) { int idx = i_byte * 8 + i; boolean isSet = (barr[i_byte] & (1 << i)) > 0; ret.set(idx, isSet); ... |
BitSet | readBitSet(ByteBuffer buf, int len) read Bit Set BitSet bs = new BitSet((len + 7) >>> 3); int i; int b = 0; int leftBit = 0x01; int bitMask = 0; for (i = 0; i < len; i++) { if (i % 8 == 0) { b = buf.get(); ... |
int | readBlock(ByteBuffer buffer, String fileName, long startOffset, Logger log) Read one block from data file. File file = new File(fileName); if (!file.exists()) { if (log != null) log.log(Level.WARNING, "Cannot read file {0}, that does not exist", fileName); return 0; if (startOffset + buffer.remaining() > file.length()) { int length = (int) (file.length() - startOffset); ... |
void | readFromChannel(FileChannel fc, ByteBuffer buffer, int bufferOffset, int num) read From Channel buffer.position(bufferOffset); if (buffer.remaining() < num) { throw new BufferUnderflowException(); buffer.limit(bufferOffset + num); int numRead = 0; int t = 0; while (numRead < num) { ... |
byte[] | readKey(ByteBuffer index, int indexByteOffset, byte[] foundKey) read Key index.position(indexByteOffset);
index.get(foundKey);
return foundKey;
|
String | readPackageName(ByteBuffer buffer, int offset) Reads the package name from the buffer and repositions the buffer to point directly after the package name. Charset utf16 = Charset.forName("UTF-16LE"); String str = new String(buffer.array(), offset, PACKAGE_NAME_SIZE, utf16); buffer.position(offset + PACKAGE_NAME_SIZE); return str; |