@Override public byte[] array() { return buffer.array(); }
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 public byte[] array() { return buffer.array(); }
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; }
@Override public byte[] array() { return buffer.array(); }
private int setInput(ChannelBuffer compressed) { int len = compressed.readableBytes(); if (compressed.hasArray()) { decompressor.setInput(compressed.array(), compressed.arrayOffset() + compressed.readerIndex(), len); } else { byte[] in = new byte[len]; compressed.getBytes(compressed.readerIndex(), in); decompressor.setInput(in, 0, in.length); } return len; }
@Override public byte[] array() { return buffer.array(); }
private int setInput(ChannelBuffer decompressed) { int len = decompressed.readableBytes(); if (decompressed.hasArray()) { compressor.setInput(decompressed.array(), decompressed.arrayOffset() + decompressed.readerIndex(), len); } else { byte[] in = new byte[len]; decompressed.getBytes(decompressed.readerIndex(), in); compressor.setInput(in, 0, in.length); } return len; }
public byte[] array() { return buffer.array(); }
private void deflate(ChannelBuffer out) { int numBytes; if (out.hasArray()) { do { int writerIndex = out.writerIndex(); numBytes = deflater.deflate( out.array(), out.arrayOffset() + writerIndex, out.writableBytes(), Deflater.SYNC_FLUSH); out.writerIndex(writerIndex + numBytes); } while (numBytes > 0); } else { byte[] tmpOut = this.out; if (tmpOut == null) { tmpOut = this.out = new byte[8192]; } do { numBytes = deflater.deflate(tmpOut, 0, tmpOut.length, Deflater.SYNC_FLUSH); out.writeBytes(tmpOut, 0, numBytes); } while (numBytes > 0); } }
public byte[] array() { return buffer.array(); }
private int decompress(SpdyHeadersFrame frame) throws Exception { ensureBuffer(); byte[] out = decompressed.array(); int off = decompressed.arrayOffset() + decompressed.writerIndex(); try { int numBytes = decompressor.inflate(out, off, decompressed.writableBytes()); if (numBytes == 0 && decompressor.needsDictionary()) { try { decompressor.setDictionary(SPDY_DICT); } catch (IllegalArgumentException e) { throw INVALID_HEADER_BLOCK; } numBytes = decompressor.inflate(out, off, decompressed.writableBytes()); } decompressed.writerIndex(decompressed.writerIndex() + numBytes); super.decodeHeaderBlock(decompressed, frame); decompressed.discardReadBytes(); return numBytes; } catch (DataFormatException e) { throw INVALID_HEADER_BLOCK; } }
public byte[] array() { return buffer.array(); }
public byte[] array() { return buffer.array(); }
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if ((null == msg) || !(msg instanceof ChannelBuffer)) { // TODO add an exception handler to the pipeline to deal with this // scenario. LOG.error("Incoming message not of ChannelBuffer type {}",msg); return msg; } ChannelBuffer buffer = (ChannelBuffer) msg; // TODO return this instead of byte array. This maybe more useful protocol. //buffer.toByteBuffer(); return buffer.array(); } }
@Override public Object convert(ChannelBuffer buffer) throws Exception { ByteArrayInputStream bis = new ByteArrayInputStream(buffer.array()); return deSerializeObjectFromStream(bis); }
@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); }
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if ((null == msg)) { LOG.error("Incoming message is null"); return msg; } Event event = (Event)msg; if(event.getType() == Events.SESSION_MESSAGE) { ChannelBuffer buffer = (ChannelBuffer)event.getSource(); LOG.trace("BinaryArray with size:{} Received.", buffer.readableBytes()); ByteArrayInputStream bis = new ByteArrayInputStream(buffer.array()); event.setSource(bis); } return event; }
private void unmask(ChannelBuffer frame) { byte[] bytes = frame.array(); for (int i = 0; i < bytes.length; i++) { frame.setByte(i, frame.getByte(i) ^ maskingKey.getByte(i % 4)); } }
try { List<DataSegmentChangeRequest> changeRequests = ServerTestHelper.MAPPER.readValue( request.getContent().array(), new TypeReference<List<DataSegmentChangeRequest>>()