private ByteBuf tryDecodeChallenge(ByteBuf in, int offset, int readableBytes) throws IOException { if (readableBytes < 4) { return null; } int len = in.getInt(offset); if (len <= 0) { // fall back to simple in.readerIndex(offset + 4); return in.retainedSlice(offset, 4); } if (len > MAX_CHALLENGE_SIZE) { throw new IOException( "Sasl challenge too large(" + len + "), max allowed is " + MAX_CHALLENGE_SIZE); } int totalLen = 4 + len; if (readableBytes < totalLen) { return null; } in.readerIndex(offset + totalLen); return in.retainedSlice(offset, totalLen); }
private ByteBuf tryDecodeChallenge(ByteBuf in, int offset, int readableBytes) throws IOException { if (readableBytes < 4) { return null; } int len = in.getInt(offset); if (len <= 0) { // fall back to simple in.readerIndex(offset + 4); return in.retainedSlice(offset, 4); } if (len > MAX_CHALLENGE_SIZE) { throw new IOException( "Sasl challenge too large(" + len + "), max allowed is " + MAX_CHALLENGE_SIZE); } int totalLen = 4 + len; if (readableBytes < totalLen) { return null; } in.readerIndex(offset + totalLen); return in.retainedSlice(offset, totalLen); }
/** * Override this method if you want to filter the json objects/arrays that get passed through the pipeline. */ @SuppressWarnings("UnusedParameters") protected ByteBuf extractObject(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) { return buffer.retainedSlice(index, length); }
@Override public ByteBuf retainedSlice() { return buf.retainedSlice(); }
@Override public ByteBuf retainedSlice(int index, int length) { return buf.retainedSlice(index, length); }
/** * Extract the sub-region of the specified buffer. * <p> * If you are sure that the frame and its content are not accessed after * the current {@link #decode(ChannelHandlerContext, ByteBuf)} * call returns, you can even avoid memory copy by returning the sliced * sub-region (i.e. <tt>return buffer.slice(index, length)</tt>). * It's often useful when you convert the extracted frame into an object. * Refer to the source code of {@link ObjectDecoder} to see how this method * is overridden to avoid memory copy. */ protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) { return buffer.retainedSlice(index, length); }
@Override public ByteBuf retainedSlice(int index, int length) { return buf.retainedSlice(index, length).order(order); }
@Override public ByteBuf retainedSlice() { return buf.retainedSlice().order(order); }
private ByteBuf tryDecodeChallenge(ByteBuf in, int offset, int readableBytes) throws IOException { if (readableBytes < 4) { return null; } int len = in.getInt(offset); if (len <= 0) { // fall back to simple in.readerIndex(offset + 4); return in.retainedSlice(offset, 4); } if (len > MAX_CHALLENGE_SIZE) { throw new IOException( "Sasl challenge too large(" + len + "), max allowed is " + MAX_CHALLENGE_SIZE); } int totalLen = 4 + len; if (readableBytes < totalLen) { return null; } in.readerIndex(offset + totalLen); return in.retainedSlice(offset, totalLen); }
@Override public ByteBuf getChunk(int length) throws IOException { if (byteBuf == null || length == 0 || byteBuf.readableBytes() == 0) { chunkPosition = 0; return EMPTY_BUFFER; } int sizeLeft = byteBuf.readableBytes() - chunkPosition; if (sizeLeft == 0) { chunkPosition = 0; return EMPTY_BUFFER; } int sliceLength = length; if (sizeLeft < length) { sliceLength = sizeLeft; } ByteBuf chunk = byteBuf.retainedSlice(chunkPosition, sliceLength); chunkPosition += sliceLength; return chunk; }
@Override public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { // Send an ack back to the remote client. // Need to retain the buffer here since it will be released after the write completes. encoder.writePing(ctx, true, data.retainedSlice(), ctx.newPromise()); listener.onPingRead(ctx, data); }
static long toBIO(ByteBufAllocator allocator, PemEncoded pem) throws Exception { try { // We can turn direct buffers straight into BIOs. No need to // make a yet another copy. ByteBuf content = pem.content(); if (content.isDirect()) { return newBIO(content.retainedSlice()); } ByteBuf buffer = allocator.directBuffer(content.readableBytes()); try { buffer.writeBytes(content, content.readerIndex(), content.readableBytes()); return newBIO(buffer.retainedSlice()); } finally { try { // If the contents of the ByteBuf is sensitive (e.g. a PrivateKey) we // need to zero out the bytes of the copy before we're releasing it. if (pem.isSensitive()) { SslUtils.zeroout(buffer); } } finally { buffer.release(); } } } finally { pem.release(); } }
switch (type) { case PP2_TYPE_SSL: final ByteBuf rawContent = header.retainedSlice(header.readerIndex(), length); final ByteBuf byteBuf = header.readSlice(length); final byte client = byteBuf.readByte();
uncompressed = in.retainedSlice(in.readerIndex(), decompressedLength); break; case BLOCK_TYPE_COMPRESSED: