Refine search
private byte[] getContentBytes(ChannelBuffer content) { byte[] contentBytes = new byte[content.readableBytes()]; content.readBytes(contentBytes); return contentBytes; } }
public long skip(long bytes) throws IOException { int readable = buffer.readableBytes(); if (readable < bytes) { bytes = readable; } buffer.readerIndex((int) (buffer.readerIndex() + bytes)); return bytes; }
int idx = buffer.readerIndex(); buffer.readerIndex(0); if (buffer.readableBytes() > 0) { byte[] b = new byte[buffer.readableBytes()]; buffer.readBytes(b); try { Utf8Validator validator = new Utf8Validator(); buffer.readerIndex(idx);
public void writeBytes(ChannelBuffer src, int length) { if (length > src.readableBytes()) { throw new IndexOutOfBoundsException("Too many bytes to write - Need " + length + ", maximum is " + src.readableBytes()); } writeBytes(src, src.readerIndex(), length); src.readerIndex(src.readerIndex() + length); }
private byte[] getContentBytes(ChannelBuffer content) { byte[] contentBytes = new byte[content.readableBytes()]; content.readBytes(contentBytes); return contentBytes; } }
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { // Will use the first bytes to detect a protocol. if (buffer.readableBytes() < bytesForProtocolCheck) { return null; } ChannelPipeline pipeline = ctx.getPipeline(); if (!loginProtocol.applyProtocol(buffer, pipeline)) { byte[] headerBytes = new byte[bytesForProtocolCheck]; buffer.getBytes(buffer.readerIndex(), headerBytes, 0, bytesForProtocolCheck); LOG.error( "Unknown protocol, discard everything and close the connection {}. Incoming Bytes {}", ctx.getChannel().getId(), BinaryUtils.getHexString(headerBytes)); close(buffer, channel); return null; } else { pipeline.remove(this); } // Forward the current read buffer as is to the new handlers. return buffer.readBytes(buffer.readableBytes()); }
public void setBytes(int index, ChannelBuffer src, int length) { if (length > src.readableBytes()) { throw new IndexOutOfBoundsException("Too many bytes to write: Need " + length + ", maximum is " + src.readableBytes()); } setBytes(index, src, src.readerIndex(), length); src.readerIndex(src.readerIndex() + length); }
private void setInput(ChannelBuffer decompressed) { byte[] in = new byte[decompressed.readableBytes()]; decompressed.readBytes(in); z.next_in = in; z.next_in_index = 0; z.avail_in = in.length; }
switch(state) { case READ_COMMON_HEADER: if (buffer.readableBytes() < SPDY_HEADER_SIZE) { return; if (buffer.readableBytes() < dataLength) { return; if (buffer.readableBytes() < 10) { return; if (buffer.readableBytes() < 4) { return; if (buffer.readableBytes() < 8) { return; if (buffer.readableBytes() < 4) { return; if (buffer.readableBytes() < 8) { return; if (buffer.readableBytes() < 4) { return; if (buffer.readableBytes() < 8) { return;
public byte[] get() { if (channelBuffer == null) { return new byte[0]; } byte[] array = new byte[channelBuffer.readableBytes()]; channelBuffer.getBytes(channelBuffer.readerIndex(), array); return array; }
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { ChannelBuffer buffer = (ChannelBuffer) e.getMessage(); synchronized (this) { buffer.readBytes(out, buffer.readableBytes()); out.flush(); } }
public int writeTo(OutputStream outputStream) throws IOException { ChannelBuffer b = getChannelBuffer(); int read = b.readableBytes(); int index = b.readerIndex(); if (read > 0) { b.readBytes(outputStream, read); } b.readerIndex(index); return read; }
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof ChannelBuffer)) { return msg; } ChannelBuffer src = (ChannelBuffer) msg; return Base64.encode( src, src.readerIndex(), src.readableBytes(), breakLines, dialect); } }
public final PacketWithHeaderPacket assembleBodyPacketWithHeader(ChannelBuffer buffer, HeaderPacket header, PacketWithHeaderPacket body) throws IOException { if (body.getHeader() == null) { body.setHeader(header); } logger.debug("body packet type:{}", body.getClass()); logger.debug("read body packet with packet length: {} ", header.getPacketBodyLength()); byte[] packetBytes = new byte[header.getPacketBodyLength()]; logger.debug("readable bytes before reading body:{}", buffer.readableBytes()); buffer.readBytes(packetBytes); body.fromBytes(packetBytes); logger.debug("body packet: {}", body); return body; }
public int writeTo(OutputStream outputStream) throws IOException { ChannelBuffer b = getChannelBuffer(); int read = b.readableBytes(); int index = b.readerIndex(); if (read > 0) { b.readBytes(outputStream, read); } b.readerIndex(index); return read; }
/** * Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a> * of the specified buffer's readable bytes. */ public static String hexDump(ChannelBuffer buffer) { return hexDump(buffer, buffer.readerIndex(), buffer.readableBytes()); }
@Override protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, VoidEnum state) { ChannelBuffer data = buffer.readBytes(requestBuffer.readableBytes()); if (data.equals(requestBuffer)) { return data; } channel.close(); return null; } }
public int writeTo(OutputStream outputStream) throws IOException { ChannelBuffer b = getChannelBuffer(); int read = b.readableBytes(); int index = b.readerIndex(); if (read > 0) { b.readBytes(outputStream, read); } b.readerIndex(index); return read; }
/** * Creates a new stream which reads data from the specified {@code buffer} * starting at the current {@code readerIndex} and ending at * {@code readerIndex + length}. * * @throws IndexOutOfBoundsException * if {@code readerIndex + length} is greater than * {@code writerIndex} */ public ChannelBufferInputStream(ChannelBuffer buffer, int length) { if (buffer == null) { throw new NullPointerException("buffer"); } if (length < 0) { throw new IllegalArgumentException("length: " + length); } if (length > buffer.readableBytes()) { throw new IndexOutOfBoundsException("Too many bytes to be read - Needs " + length + ", maximum is " + buffer.readableBytes()); } this.buffer = buffer; startIndex = buffer.readerIndex(); endIndex = startIndex + length; buffer.markReaderIndex(); }
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if(null == msg) { LOG.warn("Incoming message is null"); return msg; } ChannelBuffer buffer = (ChannelBuffer)msg; // buffer.array() will ignore the readerIndex. Hence readBytes is used // and then .array is called ByteArrayInputStream bis = new ByteArrayInputStream(buffer.readBytes( buffer.readableBytes()).array()); return deSerializeObjectFromStream(bis); }