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 newBoundedInputStream
that 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 int
available()
void
close()
boolean
isPropagateClose()
void
mark(int readlimit)
boolean
markSupported()
int
read()
int
read(byte[] b)
int
read(byte[] b, int off, int len)
void
reset()
void
setPropagateClose(boolean propagateClose)
long
skip(long n)
String
toString()
-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
BoundedInputStream
public BoundedInputStream(InputStream in, long size)
Creates a newBoundedInputStream
that 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:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] b) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
skip
public long skip(long n) throws IOException
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
available
public int available() throws IOException
- Overrides:
available
in classInputStream
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
reset
public void reset() throws IOException
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
mark
public void mark(int readlimit)
- Overrides:
mark
in classInputStream
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classInputStream
-
isPropagateClose
public boolean isPropagateClose()
-
setPropagateClose
public void setPropagateClose(boolean propagateClose)
-
-