Class BoundedInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class BoundedInputStream
    extends InputStream
    This is a stream that will only supply bytes up to a certain length - if its position goes above that, it will stop.

    This is useful to wrap ServletInputStreams. The ServletInputStream will block if you try to read content from it that isn't there, because it doesn't know whether the content hasn't arrived yet or whether the content has finished. So, one of these, initialized with the Content-length sent in the ServletInputStream's header, will stop it blocking, providing it's been sent with a correct content length.

    Author:
    InigoSurguy