public class FixedLengthInputStream
extends java.io.InputStream
FixedLengthInputStream provides a stream for reading a body of a http message that has a
Content-Length header.
This class is a decorator: it wraps the input stream of the connection, reads from it, and adds the length check. Closing this stream closes the underlying stream.
The stream ends after Content-Length bytes, even if the server sends more bytes. If the underlying
stream ends before Content-Length bytes, for example because the connection closed too early, the read
throws an IOException instead of returning the end of the stream.
| Constructor and Description |
|---|
FixedLengthInputStream(java.io.InputStream in,
long length)
Creates a stream that reads a body of the given length from the given stream.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
close() |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
long |
skip(long n) |
public FixedLengthInputStream(java.io.InputStream in,
long length)
in - the underlying stream, positioned at the start of the bodylength - the value of the Content-Length headerpublic int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] b,
int off,
int len)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic long skip(long n)
throws java.io.IOException
skip in class java.io.InputStreamjava.io.IOExceptionpublic int available()
throws java.io.IOException
available in class java.io.InputStreamjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOException