public int available() { if (released) { return 0; } else { synchronized (mutex) { return buf.remaining(); } } }
public static int remaining(final Collection<ByteBuffer> buffers) { int remaining = 0; for (final ByteBuffer buf : buffers) { remaining += buf.remaining(); } return remaining; }
@Override public int available() { return ByteBuffer.this.remaining(); }
/** * @see java.nio.Buffer#hasRemaining() */ public boolean hasRemaining() { return remaining() > 0; }
public int available() { if (m_released) { return 0; } else { synchronized (m_mutex) { return m_buf.remaining(); } } }
public int remaining() { return buf.remaining(); }
public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception { if (message instanceof ByteBuffer) { release(session, ((ByteBuffer) message).remaining()); } nextFilter.messageReceived(session, message); } }
/** * Copies the specified buffer to a byte array. * * @param buf The buffer to copy. * @return The byte array. */ public static byte[] toByteArray(final ByteBuffer buf) { final byte[] bytes = new byte[buf.remaining()]; buf.get(bytes); return bytes; }
@Override public int read(byte[] b, int off, int len) { int remaining = ByteBuffer.this.remaining(); if (remaining > 0) { int readBytes = Math.min(remaining, len); ByteBuffer.this.get(b, off, readBytes); return readBytes; } else { return -1; } }
public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception { if (message instanceof ByteBuffer) { add(session, ((ByteBuffer) message).remaining()); } nextFilter.messageReceived(session, message); } }
public int compareTo(ByteBuffer that) { int n = this.position() + Math.min(this.remaining(), that.remaining()); for (int i = this.position(), j = that.position(); i < n; i++, j++) { byte v1 = this.get(i); byte v2 = that.get(j); if (v1 == v2) { continue; } if (v1 < v2) { return -1; } return +1; } return this.remaining() - that.remaining(); }
/** * Clears this buffer and fills its content with <tt>NUL</tt>. * The position is set to zero, the limit is set to the capacity, * and the mark is discarded. */ public ByteBuffer sweep() { clear(); return fillAndReset(remaining()); }
/** * Clears this buffer and fills its content with <tt>value</tt>. * The position is set to zero, the limit is set to the capacity, * and the mark is discarded. */ public ByteBuffer sweep(byte value) { clear(); return fillAndReset(value, remaining()); }
public DecodingState decode(final ByteBuffer in, final ProtocolDecoderOutput out) throws Exception { if (in.remaining() > 1) { final int decoded = in.getUnsignedShort(); return finishDecode(decoded, out); } else { return this; } }
public DecodingState decode(final ByteBuffer in, final ProtocolDecoderOutput out) throws Exception { if (in.remaining() > 3) { final long decoded = in.getUnsignedInt(); return finishDecode(decoded, out); } else { return this; } }
@Override public boolean equals(Object o) { if (!(o instanceof ByteBuffer)) { return false; } ByteBuffer that = (ByteBuffer) o; if (this.remaining() != that.remaining()) { return false; } int p = this.position(); for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--) { byte v1 = this.get(i); byte v2 = that.get(j); if (v1 != v2) { return false; } } return true; }
public void append(ByteBuffer in) { if (overflowPosition != 0) { discard(in); } else if (buf.position() > maxLineLength - in.remaining()) { overflowPosition = buf.position(); buf.clear(); discard(in); } else { getBuffer().put(in); } }