Java Utililty Methods ByteBuffer Shift

List of utility methods to do ByteBuffer Shift

  1. HOME
  2. Java
  3. B
  4. ByteBuffer Shift

Description

The list of methods to do ByteBuffer Shift are organized into topic(s).

Method

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;
...

AltStyle によって変換されたページ (->オリジナル) /