Skip to content

NoCloseInputStream

opencode-agent[bot] edited this page May 11, 2026 · 1 revision

NoCloseInputStream

A decorator InputStream that prevents close() from propagating to the wrapped stream.

Overview

NoCloseInputStream is a simple wrapper in org.jnode.boot that delegates all InputStream operations to a wrapped stream, except for close() which is a no-op. This allows multiple consumers to read from the same underlying stream without any of them accidentally closing it.

Key Components

Class Location Purpose
NoCloseInputStream core/src/core/org/jnode/boot/NoCloseInputStream.java Decorator that suppresses close()

How It Works

Delegation Pattern

NoCloseInputStream wraps an InputStream and delegates all read operations directly to it:

public class NoCloseInputStream extends InputStream {
    private final InputStream is;

    public NoCloseInputStream(InputStream is) {
        this.is = is;
    }

    public int read() throws IOException {
        return this.is.read();
    }

    public int read(byte[] b) throws IOException {
        return this.is.read(b);
    }

    public int read(byte[] b, int off, int len) throws IOException {
        return this.is.read(b, off, len);
    }

    public int available() throws IOException {
        return this.is.available();
    }

    public long skip(long n) throws IOException {
        return this.is.skip(n);
    }

    public void mark(int readLimit) {
        this.is.mark(readLimit);
    }

    public void reset() throws IOException {
        this.is.reset();
    }

    public boolean markSupported() {
        return this.is.markSupported();
    }
}

No-Op Close

The critical behavior is the overridden close() method:

public void close() throws IOException {
    // Do not close!
}

This prevents the wrapped stream from being closed, allowing other code to continue using it.

Usage Context

During JNode's boot sequence, NoCloseInputStream is used when sharing an InputStream among multiple consumers where closing should be deferred to a single owner. For example, reading plugin descriptors or configuration data that needs to be accessible to multiple subsystems.

Gotchas

  • No ownership semantics — The decorator doesn't track which consumer last read from the stream. The underlying stream remains open indefinitely.
  • Silent suppression — No exception or warning is raised when close() is called. Callers may not realize the stream wasn't actually closed.
  • Available in org.jnode.boot — The package location links this class to the boot subsystem, but it can be used anywhere a shared stream is needed.

Related Pages

Clone this wiki locally