Home / Class/ ChunkedNioStream Class — netty Architecture

ChunkedNioStream Class — netty Architecture

Architecture documentation for the ChunkedNioStream class in ChunkedNioStream.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  f7b60d34_9e23_4cf6_d410_944cfb4f6ba4["ChunkedNioStream"]
  31bee9d8_6e75_a174_7406_89e182a6b924["ChunkedNioStream.java"]
  f7b60d34_9e23_4cf6_d410_944cfb4f6ba4 -->|defined in| 31bee9d8_6e75_a174_7406_89e182a6b924
  b0bf09a4_f427_bec9_a22e_5917dabe2834["ChunkedNioStream()"]
  f7b60d34_9e23_4cf6_d410_944cfb4f6ba4 -->|method| b0bf09a4_f427_bec9_a22e_5917dabe2834
  0fd1d2d4_f14a_e396_2883_8112225cb54b["transferredBytes()"]
  f7b60d34_9e23_4cf6_d410_944cfb4f6ba4 -->|method| 0fd1d2d4_f14a_e396_2883_8112225cb54b
  62d1c324_2b97_fc63_4537_3a918503ed04["isEndOfInput()"]
  f7b60d34_9e23_4cf6_d410_944cfb4f6ba4 -->|method| 62d1c324_2b97_fc63_4537_3a918503ed04
  42813a38_b2d3_9285_b8a9_9910f1d6e7b3["close()"]
  f7b60d34_9e23_4cf6_d410_944cfb4f6ba4 -->|method| 42813a38_b2d3_9285_b8a9_9910f1d6e7b3
  22eb6ccb_411b_e7bb_0574_dfe1ee306e23["ByteBuf()"]
  f7b60d34_9e23_4cf6_d410_944cfb4f6ba4 -->|method| 22eb6ccb_411b_e7bb_0574_dfe1ee306e23
  8d9c0150_867a_38f6_0b81_258ee37d4ffd["length()"]
  f7b60d34_9e23_4cf6_d410_944cfb4f6ba4 -->|method| 8d9c0150_867a_38f6_0b81_258ee37d4ffd
  9e4f6198_1088_2dec_7380_0fa6f3567dc8["progress()"]
  f7b60d34_9e23_4cf6_d410_944cfb4f6ba4 -->|method| 9e4f6198_1088_2dec_7380_0fa6f3567dc8

Relationship Graph

Source Code

handler/src/main/java/io/netty/handler/stream/ChunkedNioStream.java lines 33–143

public class ChunkedNioStream implements ChunkedInput<ByteBuf> {

    private final ReadableByteChannel in;

    private final int chunkSize;
    private long offset;

    /**
     * Associated ByteBuffer
     */
    private final ByteBuffer byteBuffer;

    /**
     * Creates a new instance that fetches data from the specified channel.
     */
    public ChunkedNioStream(ReadableByteChannel in) {
        this(in, ChunkedStream.DEFAULT_CHUNK_SIZE);
    }

    /**
     * Creates a new instance that fetches data from the specified channel.
     *
     * @param chunkSize the number of bytes to fetch on each
     *                  {@link #readChunk(ChannelHandlerContext)} call
     */
    public ChunkedNioStream(ReadableByteChannel in, int chunkSize) {
        this.in = checkNotNull(in, "in");
        this.chunkSize = checkPositive(chunkSize, "chunkSize");
        byteBuffer = ByteBuffer.allocate(chunkSize);
    }

    /**
     * Returns the number of transferred bytes.
     */
    public long transferredBytes() {
        return offset;
    }

    @Override
    public boolean isEndOfInput() throws Exception {
        if (byteBuffer.position() > 0) {
            // A previous read was not over, so there is a next chunk in the buffer at least
            return false;
        }
        if (in.isOpen()) {
            // Try to read a new part, and keep this part (no rewind)
            int b = in.read(byteBuffer);
            if (b < 0) {
                return true;
            } else {
                offset += b;
                return false;
            }
        }
        return true;
    }

    @Override
    public void close() throws Exception {
        in.close();
    }

    @Deprecated
    @Override
    public ByteBuf readChunk(ChannelHandlerContext ctx) throws Exception {
        return readChunk(ctx.alloc());
    }

    @Override
    public ByteBuf readChunk(ByteBufAllocator allocator) throws Exception {
        if (isEndOfInput()) {
            return null;
        }
        // buffer cannot be not be empty from there
        int readBytes = byteBuffer.position();
        for (;;) {
            int localReadBytes = in.read(byteBuffer);
            if (localReadBytes < 0) {
                break;
            }
            readBytes += localReadBytes;

Frequently Asked Questions

What is the ChunkedNioStream class?
ChunkedNioStream is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/stream/ChunkedNioStream.java.
Where is ChunkedNioStream defined?
ChunkedNioStream is defined in handler/src/main/java/io/netty/handler/stream/ChunkedNioStream.java at line 33.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free