Home / Class/ BoundedInputStream Class — netty Architecture

BoundedInputStream Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  3aec0f93_110d_60bf_b686_6b9c301f7005["BoundedInputStream"]
  b0af0499_3543_f265_3b70_9788095075b2["BoundedInputStream.java"]
  3aec0f93_110d_60bf_b686_6b9c301f7005 -->|defined in| b0af0499_3543_f265_3b70_9788095075b2
  2c4cadde_1c8c_445b_f946_b4a96521b3b5["BoundedInputStream()"]
  3aec0f93_110d_60bf_b686_6b9c301f7005 -->|method| 2c4cadde_1c8c_445b_f946_b4a96521b3b5
  5c7f5e69_7f63_1260_b1b5_77c0775da80a["read()"]
  3aec0f93_110d_60bf_b686_6b9c301f7005 -->|method| 5c7f5e69_7f63_1260_b1b5_77c0775da80a
  443fa760_babe_f7dc_6b47_05cd437efecc["checkMaxBytesRead()"]
  3aec0f93_110d_60bf_b686_6b9c301f7005 -->|method| 443fa760_babe_f7dc_6b47_05cd437efecc

Relationship Graph

Source Code

common/src/main/java/io/netty/util/internal/BoundedInputStream.java lines 24–69

public final class BoundedInputStream extends FilterInputStream {

    private final int maxBytesRead;
    private int numRead;

    public BoundedInputStream(@NotNull InputStream in, int maxBytesRead) {
        super(in);
        this.maxBytesRead = ObjectUtil.checkPositive(maxBytesRead, "maxRead");
    }

    public BoundedInputStream(@NotNull InputStream in) {
        this(in, 8 * 1024);
    }

    @Override
    public int read() throws IOException {
        checkMaxBytesRead();

        int b = super.read();
        if (b != -1) {
            numRead++;
        }
        return b;
    }

    @Override
    public int read(byte[] buf, int off, int len) throws IOException {
        checkMaxBytesRead();

        // Calculate the maximum number of bytes that we should try to read.
        int num = Math.min(len, maxBytesRead - numRead + 1);

        int b = super.read(buf, off, num);

        if (b != -1) {
            numRead += b;
        }
        return b;
    }

    private void checkMaxBytesRead() throws IOException {
        if (numRead > maxBytesRead) {
            throw new IOException("Maximum number of bytes read: " + numRead);
        }
    }
}

Frequently Asked Questions

What is the BoundedInputStream class?
BoundedInputStream is a class in the netty codebase, defined in common/src/main/java/io/netty/util/internal/BoundedInputStream.java.
Where is BoundedInputStream defined?
BoundedInputStream is defined in common/src/main/java/io/netty/util/internal/BoundedInputStream.java at line 24.

Analyze Your Own Codebase

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

Try Supermodel Free