@Override public void writerIndex(int writerIndex) { buffer.writerIndex(writerIndex); }
@Override public int writerIndex() { return buffer.writerIndex(); }
@Override public int writerIndex() { return buffer.writerIndex(); }
@Override public void writerIndex(int writerIndex) { buffer.writerIndex(writerIndex); }
/** * Returns the number of written bytes by this stream so far. */ public int writtenBytes() { return buffer.writerIndex() - startIndex; }
/** * Creates a new stream which writes data to the specified {@code buffer}. */ public ChannelBufferOutputStream(ChannelBuffer buffer) { if (buffer == null) { throw new NullPointerException("buffer"); } this.buffer = buffer; startIndex = buffer.writerIndex(); }
public Request setContent(String contentType, ChannelBuffer content) { if (contentType != null) { setHeader(HttpHeaders.Names.CONTENT_TYPE, contentType); } this.content = content; setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(content.writerIndex())); return this; }
private void checkIndex(int index, int length) { if (index + length > buf().writerIndex()) { throw REPLAY; } }
public void getBytes(int index, ChannelBuffer dst, int length) { if (length > dst.writableBytes()) { throw new IndexOutOfBoundsException("Too many bytes to be read: Need " + length + ", maximum is " + dst.writableBytes()); } getBytes(index, dst, dst.writerIndex(), length); dst.writerIndex(dst.writerIndex() + length); }
public void readBytes(ChannelBuffer dst, int length) { if (length > dst.writableBytes()) { throw new IndexOutOfBoundsException("Too many bytes to be read: Need " + length + ", maximum is " + dst.writableBytes()); } readBytes(dst, dst.writerIndex(), length); dst.writerIndex(dst.writerIndex() + length); }
private boolean compressInto(ChannelBuffer compressed) { byte[] out = compressed.array(); int off = compressed.arrayOffset() + compressed.writerIndex(); int toWrite = compressed.writableBytes(); int numBytes = compressor.deflate(out, off, toWrite, Deflater.SYNC_FLUSH); compressed.writerIndex(compressed.writerIndex() + numBytes); return numBytes == toWrite; }
public int writerIndex() { return buf().writerIndex(); }
private static ChannelBuffer copiedBuffer(ByteOrder endianness, CharBuffer buffer, Charset charset) { CharBuffer src = buffer; ByteBuffer dst = encodeString(src, charset); ChannelBuffer result = wrappedBuffer(endianness, dst.array()); result.writerIndex(dst.remaining()); return result; }
public DuplicatedChannelBuffer(ChannelBuffer buffer) { if (buffer == null) { throw new NullPointerException("buffer"); } this.buffer = buffer; setIndex(buffer.readerIndex(), buffer.writerIndex()); }
public ReadOnlyChannelBuffer(ChannelBuffer buffer) { if (buffer == null) { throw new NullPointerException("buffer"); } this.buffer = buffer; setIndex(buffer.readerIndex(), buffer.writerIndex()); }
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()); }
public static ChannelBuffer encode( ChannelBuffer src, boolean breakLines, Base64Dialect dialect, ChannelBufferFactory bufferFactory) { if (src == null) { throw new NullPointerException("src"); } ChannelBuffer dest = encode( src, src.readerIndex(), src.readableBytes(), breakLines, dialect, bufferFactory); src.readerIndex(src.writerIndex()); return dest; }
public static ChannelBuffer decode(ChannelBuffer src, Base64Dialect dialect, ChannelBufferFactory bufferFactory) { if (src == null) { throw new NullPointerException("src"); } ChannelBuffer dest = decode(src, src.readerIndex(), src.readableBytes(), dialect, bufferFactory); src.readerIndex(src.writerIndex()); return dest; }
SeekAheadOptimize(ChannelBuffer buffer) throws SeekAheadNoBackArrayException { if (!buffer.hasArray()) { throw new SeekAheadNoBackArrayException(); } this.buffer = buffer; bytes = buffer.array(); readerIndex = buffer.readerIndex(); origPos = pos = buffer.arrayOffset() + readerIndex; limit = buffer.arrayOffset() + buffer.writerIndex(); }
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { Marshaller marshaller = provider.getMarshaller(ctx); ChannelBufferByteOutput output = new ChannelBufferByteOutput( ctx.getChannel().getConfig().getBufferFactory(), estimatedLength); output.getBuffer().writeBytes(LENGTH_PLACEHOLDER); marshaller.start(output); marshaller.writeObject(msg); marshaller.finish(); marshaller.close(); ChannelBuffer encoded = output.getBuffer(); encoded.setInt(0, encoded.writerIndex() - 4); return encoded; }