List of utility methods to do ByteBuffer Shift
ByteBuffer | leftShift(final ByteBuffer buffer, int shift) left Shift final BigInteger bigInt = new BigInteger(buffer.array()); final byte[] shiftedBytes = bigInt.shiftLeft(shift).and(allOnes((buffer.remaining()) * BYTE_LENGTH)) .toByteArray(); final int resultLength = buffer.capacity(); final int sourceOffset = resultLength >= shiftedBytes.length ? 0 : 1; final int destinationOffset = resultLength - shiftedBytes.length > 0 ? resultLength - shiftedBytes.length : 0; Arrays.fill(buffer.array(), (byte) 0); ... |
boolean | shift(ByteBuffer buffer, int distance) shift if (distance <= 0) { throw new IllegalArgumentException("Negative distance: " + distance); int limit = buffer.limit(); int position = buffer.position() + distance; if (position > limit) { buffer.position(limit); return false; ... |