-
Notifications
You must be signed in to change notification settings - Fork 0
NoCloseInputStream
A decorator InputStream that prevents close() from propagating to the wrapped stream.
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.
| Class | Location | Purpose |
|---|---|---|
NoCloseInputStream |
core/src/core/org/jnode/boot/NoCloseInputStream.java |
Decorator that suppresses close() |
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();
}
}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.
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.
- 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.
- Boot-Sequence — Where this class lives in the boot package
- InitialNaming-Service-Registry — Service registration pattern used during boot
- Boot-Log — Other boot utilities in the same package