@Override public int capacity() { return buffer.capacity(); }
@Override public int capacity() { return buffer.capacity(); }
public int capacity() { return buffer.capacity(); } }
public int capacity() { return buffer.capacity(); }
public int capacity() { return buffer.capacity(); }
public SlicedChannelBuffer(ChannelBuffer buffer, int index, int length) { if (index < 0 || index > buffer.capacity()) { throw new IndexOutOfBoundsException("Invalid index of " + index + ", maximum is " + buffer.capacity()); } if (index + length > buffer.capacity()) { throw new IndexOutOfBoundsException("Invalid combined index of " + (index + length) + ", maximum is " + buffer.capacity()); } this.buffer = buffer; adjustment = index; this.length = length; writerIndex(length); }
private static int lastIndexOf(ChannelBuffer buffer, int fromIndex, int toIndex, byte value) { fromIndex = Math.min(fromIndex, buffer.capacity()); if (fromIndex < 0 || buffer.capacity() == 0) { return -1; } for (int i = fromIndex - 1; i >= toIndex; i --) { if (buffer.getByte(i) == value) { return i; } } return -1; }
private static int lastIndexOf( ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) { fromIndex = Math.min(fromIndex, buffer.capacity()); if (fromIndex < 0 || buffer.capacity() == 0) { return -1; } for (int i = fromIndex - 1; i >= toIndex; i --) { if (indexFinder.find(buffer, i)) { return i; } } return -1; }
/** Returns true if the delimiters are "\n" and "\r\n". */ private static boolean isLineBased(final ChannelBuffer[] delimiters) { if (delimiters.length != 2) { return false; } ChannelBuffer a = delimiters[0]; ChannelBuffer b = delimiters[1]; if (a.capacity() < b.capacity()) { a = delimiters[1]; b = delimiters[0]; } return a.capacity() == 2 && b.capacity() == 1 && a.getByte(0) == '\r' && a.getByte(1) == '\n' && b.getByte(0) == '\n'; }
private static int firstIndexOf(ChannelBuffer buffer, int fromIndex, int toIndex, byte value) { fromIndex = Math.max(fromIndex, 0); if (fromIndex >= toIndex || buffer.capacity() == 0) { return -1; } for (int i = fromIndex; i < toIndex; i ++) { if (buffer.getByte(i) == value) { return i; } } return -1; }
public int capacity() { if (terminated) { return buf().capacity(); } else { return Integer.MAX_VALUE; } }
private static int firstIndexOf( ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) { fromIndex = Math.max(fromIndex, 0); if (fromIndex >= toIndex || buffer.capacity() == 0) { return -1; } for (int i = fromIndex; i < toIndex; i ++) { if (indexFinder.find(buffer, i)) { return i; } } return -1; }
private void copyTo(int index, int length, int componentId, ChannelBuffer dst) { int dstIndex = 0; int i = componentId; while (length > 0) { ChannelBuffer s = components[i]; int adjustment = indices[i]; int localLength = Math.min(length, s.capacity() - (index - adjustment)); s.getBytes(index - adjustment, dst, dstIndex, localLength); index += localLength; dstIndex += localLength; length -= localLength; i ++; } dst.writerIndex(dst.capacity()); }
/** * Retrieve the value from the REST request body. * * TODO: REST-Server value cannot be null ( null/empty string ?) */ private void parseValue() { ChannelBuffer content = this.request.getContent(); this.parsedValue = new byte[content.capacity()]; content.readBytes(parsedValue); } }
private void encode(ChannelBuffer compressed) { while (compressInto(compressed)) { // Although unlikely, it's possible that the compressed size is larger than the decompressed size compressed.ensureWritableBytes(compressed.capacity() << 1); } }
/** * Returns the closing status code as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a>. If * a status code is set, -1 is returned. */ public int getStatusCode() { ChannelBuffer binaryData = getBinaryData(); if (binaryData == null || binaryData.capacity() == 0) { return -1; } binaryData.readerIndex(0); int statusCode = binaryData.readShort(); binaryData.readerIndex(0); return statusCode; }
/** * Returns the reason text as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a> If a reason * text is not supplied, an empty string is returned. */ public String getReasonText() { ChannelBuffer binaryData = getBinaryData(); if (binaryData == null || binaryData.capacity() <= 2) { return ""; } binaryData.readerIndex(2); String reasonText = binaryData.toString(CharsetUtil.UTF_8); binaryData.readerIndex(0); return reasonText; }
private ChannelBuffer allocateBigEndianBuffer(int capacity) { ChannelBuffer slice; synchronized (bigEndianLock) { if (preallocatedBEBuf == null) { preallocatedBEBuf = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity); slice = preallocatedBEBuf.slice(0, capacity); preallocatedBEBufPos = capacity; } else if (preallocatedBEBuf.capacity() - preallocatedBEBufPos >= capacity) { slice = preallocatedBEBuf.slice(preallocatedBEBufPos, capacity); preallocatedBEBufPos += capacity; } else { preallocatedBEBuf = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity); slice = preallocatedBEBuf.slice(0, capacity); preallocatedBEBufPos = capacity; } } return slice; }
private ChannelBuffer allocateLittleEndianBuffer(int capacity) { ChannelBuffer slice; synchronized (littleEndianLock) { if (preallocatedLEBuf == null) { preallocatedLEBuf = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity); slice = preallocatedLEBuf.slice(0, capacity); preallocatedLEBufPos = capacity; } else if (preallocatedLEBuf.capacity() - preallocatedLEBufPos >= capacity) { slice = preallocatedLEBuf.slice(preallocatedLEBufPos, capacity); preallocatedLEBufPos += capacity; } else { preallocatedLEBuf = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity); slice = preallocatedLEBuf.slice(0, capacity); preallocatedLEBufPos = capacity; } } return slice; } }