static int readUnsignedShort(final ByteBuffer buffer) { int length = buffer.get() & 0xff; switch (length) { case 0: return 0; case 1: return buffer.get() & 0xff; case 2: return buffer.getShort() & 0xffff; default: Buffers.skip(buffer, length - 2); return buffer.getShort() & 0xffff; } }
static int readIntData(final ByteBuffer buffer, final int length) { switch (length) { case 0: return 0; case 1: return buffer.get() & 0xff; case 2: return buffer.getShort() & 0xffff; case 3: return ((buffer.get() & 0xff) << 16) + (buffer.getShort() & 0xffff); case 4: return buffer.getInt(); default: Buffers.skip(buffer, length - 4); return buffer.getInt(); } }
static long readLong(final ByteBuffer buffer) { int length = buffer.get() & 0xff; switch (length) { case 0: return 0; case 1: return buffer.get() & 0xffL; case 2: return buffer.getShort() & 0xffffL; case 3: return ((buffer.get() & 0xffL) << 16) + (buffer.getShort() & 0xffffL); case 4: return buffer.getInt() & 0xffffffffL; case 5: return ((buffer.get() & 0xffL) << 32) + (buffer.getInt() & 0xffffffffL); case 6: return ((buffer.getShort() & 0xffffL) << 32) + (buffer.getInt() & 0xffffffffL); case 7: return ((buffer.get() & 0xffL) << 48) + ((buffer.getShort() & 0xffffL) << 32) + (buffer.getInt() & 0xffffffffL); case 8: return buffer.getLong(); default: Buffers.skip(buffer, length - 8); return buffer.getLong(); } }
/** {@inheritDoc} */ public long skip(long n) throws IOException { final ByteBuffer byteBuffer = this.byteBuffer; int cnt = 0; while (n > 0) { final int r = byteBuffer.remaining(); if (r == 0) { if (! fill()) return cnt; continue; } final int c = Math.min(r, n > (long) Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) n); Buffers.skip(byteBuffer, c); cnt += c; n -= c; } return cnt; }
/** * Fill a buffer with a repeated value. * * @param buffer the buffer to fill * @param value the value to fill * @param count the number of bytes to fill * @return the buffer instance */ public static ByteBuffer fill(ByteBuffer buffer, int value, int count) { if (count > buffer.remaining()) { throw msg.bufferUnderflow(); } if (buffer.hasArray()) { final int offs = buffer.arrayOffset(); Arrays.fill(buffer.array(), offs + buffer.position(), offs + buffer.limit(), (byte) value); skip(buffer, count); } else { for (int i = count; i > 0; i--) { buffer.put((byte)value); } } return buffer; }
/** * Fill a buffer with a repeated value. * * @param buffer the buffer to fill * @param value the value to fill * @param count the number of chars to fill * @return the buffer instance */ public static CharBuffer fill(CharBuffer buffer, int value, int count) { if (count > buffer.remaining()) { throw msg.bufferUnderflow(); } if (buffer.hasArray()) { final int offs = buffer.arrayOffset(); Arrays.fill(buffer.array(), offs + buffer.position(), offs + buffer.limit(), (char) value); skip(buffer, count); } else { for (int i = count; i > 0; i--) { buffer.put((char)value); } } return buffer; }
return Buffers.copy(length, dst, receiveBuffer); } else { Buffers.skip(receiveBuffer, length); return 0;
return Buffers.copy(length, dsts, offs, len, receiveBuffer); } else { Buffers.skip(receiveBuffer, length); return 0;
/** * Fill a buffer with a repeated value. * * @param buffer the buffer to fill * @param value the value to fill * @param count the number of ints to fill * @return the buffer instance */ public static IntBuffer fill(IntBuffer buffer, int value, int count) { if (count > buffer.remaining()) { throw msg.bufferUnderflow(); } if (buffer.hasArray()) { final int offs = buffer.arrayOffset(); Arrays.fill(buffer.array(), offs + buffer.position(), offs + buffer.limit(), value); skip(buffer, count); } else { for (int i = count; i > 0; i--) { buffer.put(value); } } return buffer; }
if (buffer.hasRemaining()) { final int cnt = (int) min(buffer.remaining(), n); Buffers.skip(buffer, cnt); total += cnt; n -= cnt;
ByteBuffer createBuffer() { synchronized (this) { // avoid a storm of mass-population by only allowing one thread to split a parent buffer at a time ByteBuffer appearing = getMasterQueue().poll(); if (appearing != null) { return appearing; } ByteBuffer parentBuffer = parent.allocate(); final int size = getSize(); ByteBuffer result = Buffers.slice(parentBuffer, size); while (parentBuffer.hasRemaining()) { // avoid false sharing between buffers if (size < CACHE_LINE_SIZE) { Buffers.skip(parentBuffer, CACHE_LINE_SIZE - size); } super.doFree(Buffers.slice(parentBuffer, size)); } return result; } } };
/** * Fill a buffer with a repeated value. * * @param buffer the buffer to fill * @param value the value to fill * @param count the number of shorts to fill * @return the buffer instance */ public static ShortBuffer fill(ShortBuffer buffer, int value, int count) { if (count > buffer.remaining()) { throw msg.bufferUnderflow(); } if (buffer.hasArray()) { final int offs = buffer.arrayOffset(); Arrays.fill(buffer.array(), offs + buffer.position(), offs + buffer.limit(), (short) value); skip(buffer, count); } else { for (int i = count; i > 0; i--) { buffer.put((short)value); } } return buffer; }
} else { log.tracef("Not copying message from %s into full buffer %s", receiveBuffer, buffer); Buffers.skip(receiveBuffer, length);
} else { log.tracef("Not copying message from %s into multiple full buffers", receiveBuffer); Buffers.skip(receiveBuffer, length);
/** * Fill a buffer with a repeated value. * * @param buffer the buffer to fill * @param value the value to fill * @param count the number of longs to fill * @return the buffer instance */ public static LongBuffer fill(LongBuffer buffer, long value, int count) { if (count > buffer.remaining()) { throw msg.bufferUnderflow(); } if (buffer.hasArray()) { final int offs = buffer.arrayOffset(); Arrays.fill(buffer.array(), offs + buffer.position(), offs + buffer.limit(), value); skip(buffer, count); } else { for (int i = count; i > 0; i--) { buffer.put(value); } } return buffer; }
static int readUnsignedShort(final ByteBuffer buffer) { int length = buffer.get() & 0xff; switch (length) { case 0: return 0; case 1: return buffer.get() & 0xff; case 2: return buffer.getShort() & 0xffff; default: Buffers.skip(buffer, length - 2); return buffer.getShort() & 0xffff; } }
static int readUnsignedShort(final ByteBuffer buffer) { int length = buffer.get() & 0xff; switch (length) { case 0: return 0; case 1: return buffer.get() & 0xff; case 2: return buffer.getShort() & 0xffff; default: Buffers.skip(buffer, length - 2); return buffer.getShort() & 0xffff; } }
static int readIntData(final ByteBuffer buffer, final int length) { switch (length) { case 0: return 0; case 1: return buffer.get() & 0xff; case 2: return buffer.getShort() & 0xffff; case 3: return ((buffer.get() & 0xff) << 16) + (buffer.getShort() & 0xffff); case 4: return buffer.getInt(); default: Buffers.skip(buffer, length - 4); return buffer.getInt(); } }
static int readIntData(final ByteBuffer buffer, final int length) { switch (length) { case 0: return 0; case 1: return buffer.get() & 0xff; case 2: return buffer.getShort() & 0xffff; case 3: return ((buffer.get() & 0xff) << 16) + (buffer.getShort() & 0xffff); case 4: return buffer.getInt(); default: Buffers.skip(buffer, length - 4); return buffer.getInt(); } }