org.htmlparser.lexer

Class Stream

public class Stream extends InputStream implements Runnable

Provides for asynchronous fetching from a stream.
Field Summary
protected static intBUFFER_SIZE
An initial buffer size.
protected static intEOF
Return value when no more characters are left.
intfills
The number of calls to fill.
byte[]mBuffer
The bytes read so far.
protected intmContentLength
The content length from the HTTP header.
protected InputStreammIn
The underlying stream.
intmLevel
The number of valid bytes in the buffer.
protected intmMark
The bookmark.
protected intmOffset
The offset of the next byte returned by read().
intreallocations
The number of reallocations.
intsynchronous
The number of synchronous (blocking) fills.
Constructor Summary
Stream(InputStream in)
Construct a stream with no assumptions about the number of bytes available.
Stream(InputStream in, int bytes)
Construct a stream to read the given number of bytes.
Method Summary
intavailable()
Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.
voidclose()
Closes this input stream and releases any system resources associated with the stream.
protected booleanfill(boolean force)
Fetch more bytes from the underlying stream.
voidmark(int readlimit)
Marks the current position in this input stream.
booleanmarkSupported()
Tests if this input stream supports the mark and reset methods.
intread()
Reads the next byte of data from the input stream.
voidreset()
Repositions this stream to the position at the time the mark method was last called on this input stream.
voidrun()
Continually read the underlying stream untill exhausted.

Field Detail

BUFFER_SIZE

protected static final int BUFFER_SIZE
An initial buffer size.

EOF

protected static final int EOF
Return value when no more characters are left.

fills

public int fills
The number of calls to fill. Note: to be removed.

mBuffer

public volatile byte[] mBuffer
The bytes read so far.

mContentLength

protected int mContentLength
The content length from the HTTP header.

mIn

protected volatile InputStream mIn
The underlying stream.

mLevel

public volatile int mLevel
The number of valid bytes in the buffer.

mMark

protected int mMark
The bookmark.

mOffset

protected int mOffset
The offset of the next byte returned by read().

reallocations

public int reallocations
The number of reallocations. Note: to be removed.

synchronous

public int synchronous
The number of synchronous (blocking) fills. Note: to be removed.

Constructor Detail

Stream

public Stream(InputStream in)
Construct a stream with no assumptions about the number of bytes available.

Parameters: in The input stream to use.

Stream

public Stream(InputStream in, int bytes)
Construct a stream to read the given number of bytes.

Parameters: in The input stream to use. bytes The maximum number of bytes to read. This should be set to the ContentLength from the HTTP header. A negative or zero value indicates an unknown number of bytes.

Method Detail

available

public int available()
Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. The next caller might be the same thread or or another thread.

Returns: The number of bytes that can be read from this input stream without blocking.

Throws: IOException If an I/O error occurs.

close

public void close()
Closes this input stream and releases any system resources associated with the stream.

Throws: IOException If an I/O error occurs.

fill

protected boolean fill(boolean force)
Fetch more bytes from the underlying stream. Has no effect if the underlying stream has been drained.

Parameters: force If true, an attempt is made to read from the underlying stream, even if bytes are available, If false, a read of the underlying stream will not occur if there are already bytes available.

Returns: true if not at the end of the input stream.

Throws: IOException If the underlying stream read() or available() throws one.

mark

public void mark(int readlimit)
Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

The readlimit arguments tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

The general contract of mark is that, if the method markSupported returns true, the stream somehow remembers all the bytes read after the call to mark and stands ready to supply those same bytes again if and whenever the method reset is called. However, the stream is not required to remember any data at all if more than readlimit bytes are read from the stream before reset is called.

Parameters: readlimit Not used.

See Also: java.io.InputStream#reset()

markSupported

public boolean markSupported()
Tests if this input stream supports the mark and reset methods. Whether or not mark and reset are supported is an invariant property of a particular input stream instance. The markSupported method of InputStream returns false.

Returns: true.

See Also: java.io.InputStream#mark(int) java.io.InputStream#reset()

read

public int read()
Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns: The next byte of data, or -1 if the end of the stream is reached.

Throws: IOException If an I/O error occurs.

reset

public void reset()
Repositions this stream to the position at the time the mark method was last called on this input stream.

The general contract of reset is:

Throws: IOException Never thrown. Just for subclassers.

See Also: java.io.InputStream#mark(int) java.io.IOException

run

public void run()
Continually read the underlying stream untill exhausted.

See Also: java.lang.Thread#run()

HTML Parser is an open source library released under LGPL. SourceForge.net