Home / Class/ ChunkedStream Class — netty Architecture

ChunkedStream Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  b4d9d424_2691_8f68_9a66_5c464afa8fb8["ChunkedStream"]
  23ca58d5_4473_727b_5737_371c4bfa833d["ChunkedStream.java"]
  b4d9d424_2691_8f68_9a66_5c464afa8fb8 -->|defined in| 23ca58d5_4473_727b_5737_371c4bfa833d
  39f31c3d_b4fd_402b_0930_fcd5ec35738f["ChunkedStream()"]
  b4d9d424_2691_8f68_9a66_5c464afa8fb8 -->|method| 39f31c3d_b4fd_402b_0930_fcd5ec35738f
  6cd00194_1c49_b400_36eb_2526e24afbb2["transferredBytes()"]
  b4d9d424_2691_8f68_9a66_5c464afa8fb8 -->|method| 6cd00194_1c49_b400_36eb_2526e24afbb2
  9b83dcca_0832_88ba_fade_f60a77bed9eb["isEndOfInput()"]
  b4d9d424_2691_8f68_9a66_5c464afa8fb8 -->|method| 9b83dcca_0832_88ba_fade_f60a77bed9eb
  768ab311_e48c_8979_bbf9_882556855551["close()"]
  b4d9d424_2691_8f68_9a66_5c464afa8fb8 -->|method| 768ab311_e48c_8979_bbf9_882556855551
  2593cc8f_8866_9865_5ccf_a242b9a1f0a6["ByteBuf()"]
  b4d9d424_2691_8f68_9a66_5c464afa8fb8 -->|method| 2593cc8f_8866_9865_5ccf_a242b9a1f0a6
  929a7df8_d96a_0511_e380_589afbf5557d["length()"]
  b4d9d424_2691_8f68_9a66_5c464afa8fb8 -->|method| 929a7df8_d96a_0511_e380_589afbf5557d
  c953fb39_ff20_f486_66bb_aec9274acd80["progress()"]
  b4d9d424_2691_8f68_9a66_5c464afa8fb8 -->|method| c953fb39_ff20_f486_66bb_aec9274acd80

Relationship Graph

Source Code

handler/src/main/java/io/netty/handler/stream/ChunkedStream.java lines 36–148

public class ChunkedStream implements ChunkedInput<ByteBuf> {

    static final int DEFAULT_CHUNK_SIZE = 8192;

    private final PushbackInputStream in;
    private final int chunkSize;
    private long offset;
    private boolean closed;

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

    /**
     * Creates a new instance that fetches data from the specified stream.
     *
     * @param chunkSize the number of bytes to fetch on each
     *                  {@link #readChunk(ChannelHandlerContext)} call
     */
    public ChunkedStream(InputStream in, int chunkSize) {
        ObjectUtil.checkNotNull(in, "in");
        ObjectUtil.checkPositive(chunkSize, "chunkSize");

        if (in instanceof PushbackInputStream) {
            this.in = (PushbackInputStream) in;
        } else {
            this.in = new PushbackInputStream(in);
        }
        this.chunkSize = chunkSize;
    }

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

    @Override
    public boolean isEndOfInput() throws Exception {
        if (closed) {
            return true;
        }
        if (in.available() > 0) {
            return false;
        }

        int b = in.read();
        if (b < 0) {
            return true;
        } else {
            in.unread(b);
            return false;
        }
    }

    @Override
    public void close() throws Exception {
        closed = true;
        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;
        }

        final int availableBytes = in.available();
        final int chunkSize;
        if (availableBytes <= 0) {
            chunkSize = this.chunkSize;

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free