Class DetachableInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class DetachableInputStream
    extends FilterInputStream
    FilterInputStream that delegates to the original InputStream. When detach() is called, the original InputStream is consumed, and closed. The unread bytes are stored in a local stream. Subsequent requests are serviced by the local stream. Rationale: The detached stream can be closed and its resources freed, but the consumer of the stream can continue to receive data. Cons: If there are a lot of bytes remaining, these are buffered. Currently they are buffered incore (this could be improved to buffer in a file).