public class HttpInputStream
extends java.io.FilterInputStream
The underlying assumption of this class is that when reading the result
of an HTTP request, each byte in the input stream represents an 8-bit
ASCII character, and as such, it is perfectly valid to treat each byte
as a character. Locale-based conversion is not appropriate in this
circumstance, so the java.io.BufferedReader.readLine
method
should not be used.
Modifier and Type | Field and Description |
---|---|
static int |
defaultBufsize
The default size of the temporary buffer used when copying from an
input stream to an output stream.
|
Constructor and Description |
---|
HttpInputStream(java.io.InputStream in)
Creates a new HttpInputStream that reads its input from the
specified input stream.
|
Modifier and Type | Method and Description |
---|---|
int |
copyTo(java.io.OutputStream out)
Copies bytes from this input stream to the specified output stream
until end of the input stream is reached.
|
int |
copyTo(java.io.OutputStream out,
int len)
Copies bytes from this input stream to the specified output stream
until the specified number of bytes are copied or the end of the
input stream is reached.
|
int |
copyTo(java.io.OutputStream out,
int len,
byte[] buf)
Copies bytes from this input stream to the specified output stream
until the specified number of bytes are copied or the end of the
input stream is reached.
|
int |
readFully(byte[] buf)
Reads
buf.length bytes from the input stream. |
int |
readFully(byte[] buf,
int off,
int len)
Reads the specified number of bytes from the input stream.
|
java.lang.String |
readLine()
Reads the next line of text from the input stream.
|
java.lang.String |
readLine(int limit)
Reads the next line of text from the input stream, up to the
limit specified.
|
public static int defaultBufsize
copyTo(OutputStream, int, byte[])
public HttpInputStream(java.io.InputStream in)
in
- The underlying input stream.public java.lang.String readLine() throws java.io.IOException
A line is terminated by "\r", "\n", "\r\n", or the end of the input stream. The line-terminating characters are discarded.
null
if the end of the input stream is reached and no bytes
were found.java.io.IOException
- if the underlying input stream throws an
IOException while being read.public java.lang.String readLine(int limit) throws java.io.IOException
A line is terminated by "\r", "\n", "\r\n", the end of the input
stream, or when the specified number of characters have been read.
The line-terminating characters are discarded. It is not possible
to distinguish, based on the result, between a line that was
exactly limit
characters long and a line that was
terminated because limit
characters were read.
null
if the end of the input stream is reached and no bytes
were found.java.io.IOException
- if the underlying input stream throws an
IOException while being read.public int readFully(byte[] buf) throws java.io.IOException
buf.length
bytes from the input stream. This
method reads repeatedly from the input stream until the specified
number of bytes have been read or the end of the input stream
is reached.
The standard InputStream.read
method will generally
return less than the specified number of bytes if the underlying
input stream is "bursty", such as from a network source. Sometimes
it is important to read the exact number of bytes desired.
buf
- Buffer in which the data is stored. If buffer is of
length 0, this method will return immediately.buf.length
if the end of the input stream was
reached.java.io.IOException
- if the underlying input stream throws an
IOException while being read.public int readFully(byte[] buf, int off, int len) throws java.io.IOException
The standard InputStream.read
method will generally
return less than the specified number of bytes if the underlying
input stream is "bursty", such as from a network source. Sometimes
it is important to read the exact number of bytes desired.
buf
- Buffer in which the data is stored.off
- The starting offset into the buffer.len
- The number of bytes to read.len
if the end of the input stream was reached.java.io.IOException
- if the underlying input stream throws an
IOException while being read.public int copyTo(java.io.OutputStream out) throws java.io.IOException
out
- The output stream to copy the data to.java.io.IOException
- if the underlying input stream throws an
IOException while being read or if the output stream
throws an IOException while being written. It may not be
possible to distinguish amongst the two conditions.public int copyTo(java.io.OutputStream out, int len) throws java.io.IOException
out
- The output stream to copy the data to.len
- The number of bytes to copy, or < 0 to copy until the end
of this stream.java.io.IOException
- if the underlying input stream throws an
IOException while being read or if the output stream
throws an IOException while being written. It may not be
possible to distinguish amongst the two conditions.public int copyTo(java.io.OutputStream out, int len, byte[] buf) throws java.io.IOException
out
- The output stream to copy the data to.len
- The number of bytes to copy, or < 0 to copy until the end
of this stream.buf
- The buffer used to for holding the temporary results while
copying data from this input stream to the output stream.
May be null
to allow this method copy in
chunks of length defaultBufsize
.java.io.IOException
- if the underlying input stream throws an
IOException while being read.