Package org.apache.jackrabbit.server.io
Class BoundedInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.jackrabbit.server.io.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
-
-
Constructor Summary
Constructors Constructor Description BoundedInputStream(InputStream in)BoundedInputStream(InputStream in, long size)Creates a newBoundedInputStreamthat wraps the given input stream and limits it to a certain size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()booleanisPropagateClose()voidmark(int readlimit)booleanmarkSupported()intread()intread(byte[] b)intread(byte[] b, int off, int len)voidreset()voidsetPropagateClose(boolean propagateClose)longskip(long n)StringtoString()-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
BoundedInputStream
public BoundedInputStream(InputStream in, long size)
Creates a newBoundedInputStreamthat wraps the given input stream and limits it to a certain size.- Parameters:
in- The wrapped input streamsize- The maximum number of bytes to return
-
BoundedInputStream
public BoundedInputStream(InputStream in)
-
-
Method Detail
-
read
public int read() throws IOException- Specified by:
readin classInputStream- Throws:
IOException
-
read
public int read(byte[] b) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
skip
public long skip(long n) throws IOException- Overrides:
skipin classInputStream- Throws:
IOException
-
available
public int available() throws IOException- Overrides:
availablein classInputStream- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
reset
public void reset() throws IOException- Overrides:
resetin classInputStream- Throws:
IOException
-
mark
public void mark(int readlimit)
- Overrides:
markin classInputStream
-
markSupported
public boolean markSupported()
- Overrides:
markSupportedin classInputStream
-
isPropagateClose
public boolean isPropagateClose()
-
setPropagateClose
public void setPropagateClose(boolean propagateClose)
-
-