if (!buffer.isReadable()) { return 0; } else { int result = tmp & 127; if (!buffer.isReadable()) { buffer.resetReaderIndex(); return 0; } else { result |= (tmp & 127) << 7; if (!buffer.isReadable()) { buffer.resetReaderIndex(); return 0; } else { result |= (tmp & 127) << 14; if (!buffer.isReadable()) { buffer.resetReaderIndex(); return 0; } else { result |= (tmp & 127) << 21; if (!buffer.isReadable()) { buffer.resetReaderIndex(); return 0;
@Override public int compareTo(ByteBuf buffer) { return buffer.isReadable()? -1 : 0; }
@Override public final boolean isReadable() { return buf.isReadable(); }
@Override public final boolean isReadable(int size) { return buf.isReadable(size); }
@Override public boolean isReadable(int size) { return buf.isReadable(size); }
/** * Checks that at least one bit is available for reading. * @return {@code true} if one bit is available for reading, otherwise {@code false} */ boolean isReadable() { return bitCount > 0 || in.isReadable(); }
@Override public boolean equals(Object obj) { return obj instanceof ByteBuf && !((ByteBuf) obj).isReadable(); }
@Override public boolean isReadable(int size) { return terminated? buffer.isReadable(size) : true; }
private static void validateDelimiter(ByteBuf delimiter) { if (delimiter == null) { throw new NullPointerException("delimiter"); } if (!delimiter.isReadable()) { throw new IllegalArgumentException("empty delimiter"); } }
/** * Encode the key. * * @param buf the {@link ByteBuf} to write into. * @param key the key to encode. */ private static void encodeKey(ByteBuf buf, ByteBuf key) { if (key == null || !key.isReadable()) { return; } buf.writeBytes(key); }
@Override public int read() throws IOException { if (!buffer.isReadable()) { return -1; } return buffer.readByte() & 0xff; }
@Override public byte readByte() throws IOException { if (!buffer.isReadable()) { throw new EOFException(); } return buffer.readByte(); }
/** * @see ByteToMessageDecoder#decodeLast(ChannelHandlerContext, ByteBuf, List) */ protected void decodeLast(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.isReadable()) { // Only call decode() if there is something left in the buffer to decode. // See https://github.com/netty/netty/issues/4386 decode(ctx, in, out); } }
@Override public int read() throws IOException { if (buffer.isReadable()) { return buffer.readByte() & 0xff; } return -1; }
private static void appendPartialContent(CompositeByteBuf content, ByteBuf partialContent) { if (partialContent.isReadable()) { content.addComponent(true, partialContent.retain()); } }
private void fetchEncoderOutput(List<Object> out) { for (;;) { ByteBuf buf = encoder.readOutbound(); if (buf == null) { break; } if (!buf.isReadable()) { buf.release(); continue; } out.add(new DefaultHttpContent(buf)); } }
private boolean decodeType(ByteBuf in) throws Exception { if (!in.isReadable()) { return false; } type = RedisMessageType.valueOf(in.readByte()); state = type.isInline() ? State.DECODE_INLINE : State.DECODE_LENGTH; return true; }
private static ByteBuf readLine(ByteBuf in) { if (!in.isReadable(RedisConstants.EOL_LENGTH)) { return null; } final int lfIndex = in.forEachByte(ByteProcessor.FIND_LF); if (lfIndex < 0) { return null; } ByteBuf data = in.readSlice(lfIndex - in.readerIndex() - 1); // `-1` is for CR readEndOfLine(in); // validate CR LF return data; }
@Override public void flush(final ChannelHandlerContext ctx) throws Exception { if (buffer != null && buffer.isReadable()) { final ByteBuf buf = allocateBuffer(ctx, Unpooled.EMPTY_BUFFER, isPreferDirect(), false); flushBufferedData(buf); ctx.write(buf); } ctx.flush(); }
private void encodeLastContent(LastHttpContent last, List<Object> out) { boolean needFiller = !(last instanceof FullHttpMessage) && last.trailingHeaders().isEmpty(); if (last.content().isReadable() || needFiller) { out.add(new DefaultHttp2DataFrame(last.content().retain(), last.trailingHeaders().isEmpty())); } if (!last.trailingHeaders().isEmpty()) { Http2Headers headers = HttpConversionUtil.toHttp2Headers(last.trailingHeaders(), validateHeaders); out.add(new DefaultHttp2HeadersFrame(headers, true)); } }