Methods Summary |
---|
public int | available()return the number of bytes available to be read without blocking
if (in == null) return 0;
// return buffered + available from the stream
return (numbytes-offset) + in.available();
|
public void | close()disassociate from the underlying input stream
setInputStream(null);
|
public int | peek()Just like read except byte is not removed from the buffer.
the data is buffered for efficiency.
Was added to support multiline http headers. ;-)
if (in == null) return -1;
if (offset >= numbytes) refillBuffer();
if (offset >= numbytes) return -1;
return buffer[offset] & 0xFF;
|
public int | read()Read a byte from the input stream, blocking if necessary. Internally
the data is buffered for efficiency.
if (in == null) return -1;
if (offset >= numbytes) refillBuffer();
if (offset >= numbytes) return -1;
return buffer[offset++] & 0xFF;
|
public int | read(byte[] dest)Read bytes from the input stream. This is guaranteed to return at
least one byte or throw an exception. When possible, it will return
more bytes, up to the length of the array, as long as doing so would
not require waiting on bytes from the input stream.
return read(dest, 0, dest.length);
|
public int | read(byte[] dest, int off, int len)Read a specified number of bytes from the input stream. This is
guaranteed to return at least one byte or throw an execption. When
possible, it will return more bytes, up to the length specified,
as long as doing so would not require waiting on bytes from the
input stream.
int ready = numbytes - offset;
if (ready >= len) {
System.arraycopy(buffer, offset, dest, off, len);
offset += len;
return len;
} else if (ready>0) {
System.arraycopy(buffer, offset, dest, off, ready);
offset = numbytes;
return ready;
} else {
if (in == null) return -1;
refillBuffer();
if (offset >= numbytes) return -1;
return read(dest,off,len);
}
|
private void | refillBuffer()Replenish the buffer with data from the input stream. This is
guaranteed to read atleast one byte or throw an exception. When
possible, it will read up to the length of the buffer
the data is buffered for efficiency.
if (remainingContent <= 0 || in == null) return;
// determine number of bytes to read
numbytes = in.available();
if (numbytes > remainingContent) numbytes=remainingContent;
if (numbytes > buffer.length) numbytes=buffer.length;
if (numbytes <= 0) numbytes = 1;
// actually attempt to read those bytes
numbytes = in.read(buffer, 0, numbytes);
// update internal state to reflect this read
remainingContent -= numbytes;
offset = 0;
|
public void | setContentLength(int value)set the maximum number of bytes allowed to be read from this input
stream.
if (in != null) this.remainingContent = value - (numbytes-offset);
|
public void | setInputStream(java.io.InputStream in)set the input stream to be used for subsequent reads // number of valid bytes in this buffer
this.in = in;
numbytes = 0;
offset = 0;
remainingContent = (in==null)? 0 : Integer.MAX_VALUE;
|
public int | skip(int len)skip over (and discard) a specified number of bytes in this input
stream
int count = 0;
while (len-->0 && read()>=0) count++;
return count;
|