Package org.htmlparser.lexer
Class Stream
java.lang.Object
java.io.InputStream
org.htmlparser.lexer.Stream
- All Implemented Interfaces:
Closeable,AutoCloseable,Runnable
Provides for asynchronous fetching from a stream.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intAn initial buffer size.protected static final intReturn value when no more characters are left.intThe number of calls to fill.byte[]The bytes read so far.protected intThe content length from the HTTP header.protected InputStreamThe underlying stream.intThe number of valid bytes in the buffer.protected intThe bookmark.protected intThe offset of the next byte returned by read().intThe number of reallocations.intThe number of synchronous (blocking) fills. -
Constructor Summary
ConstructorsConstructorDescriptionStream(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
Modifier and TypeMethodDescriptionintReturns 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.booleanTests if this input stream supports themarkandresetmethods.intread()Reads the next byte of data from the input stream.voidreset()Repositions this stream to the position at the time themarkmethod was last called on this input stream.voidrun()Continually read the underlying stream untill exhausted.Methods inherited from class java.io.InputStream
nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, skip, skipNBytes, transferTo
-
Field Details
-
fills
public int fillsThe number of calls to fill. Note: to be removed. -
reallocations
public int reallocationsThe number of reallocations. Note: to be removed. -
synchronous
public int synchronousThe number of synchronous (blocking) fills. Note: to be removed. -
BUFFER_SIZE
protected static final int BUFFER_SIZEAn initial buffer size.- See Also:
-
EOF
protected static final int EOFReturn value when no more characters are left.- See Also:
-
mIn
The underlying stream. -
mBuffer
public volatile byte[] mBufferThe bytes read so far. -
mLevel
public volatile int mLevelThe number of valid bytes in the buffer. -
mOffset
protected int mOffsetThe offset of the next byte returned by read(). -
mContentLength
protected int mContentLengthThe content length from the HTTP header. -
mMark
protected int mMarkThe bookmark.
-
-
Constructor Details
-
Stream
Construct a stream with no assumptions about the number of bytes available.- Parameters:
in- The input stream to use.
-
Stream
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 Details
-
fill
Fetch more bytes from the underlying stream. Has no effect if the underlying stream has been drained.- Parameters:
force- Iftrue, an attempt is made to read from the underlying stream, even if bytes are available, Iffalse, a read of the underlying stream will not occur if there are already bytes available.- Returns:
trueif not at the end of the input stream.- Throws:
IOException- If the underlying stream read() or available() throws one.
-
run
public void run()Continually read the underlying stream untill exhausted. -
read
Reads the next byte of data from the input stream. The value byte is returned as anintin the range0to255. If no byte is available because the end of the stream has been reached, the value-1is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.- Specified by:
readin classInputStream- Returns:
- The next byte of data, or
-1if the end of the stream is reached. - Throws:
IOException- If an I/O error occurs.
-
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.- Overrides:
availablein classInputStream- Returns:
- The number of bytes that can be read from this input stream without blocking.
- Throws:
IOException- If an I/O error occurs.
-
close
Closes this input stream and releases any system resources associated with the stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException- If an I/O error occurs.
-
reset
Repositions this stream to the position at the time themarkmethod was last called on this input stream.The general contract of
resetis:- If the method
markSupportedreturnstrue, then:- If the method
markhas not been called since the stream was created, or the number of bytes read from the stream sincemarkwas last called is larger than the argument tomarkat that last call, then anIOExceptionmight be thrown. - If such an
IOExceptionis not thrown, then the stream is reset to a state such that all the bytes read since the most recent call tomark(or since the start of the file, ifmarkhas not been called) will be resupplied to subsequent callers of thereadmethod, followed by any bytes that otherwise would have been the next input data as of the time of the call toreset.
- If the method
- If the method
markSupportedreturnsfalse, then:- The call to
resetmay throw anIOException. - If an
IOExceptionis not thrown, then the stream is reset to a fixed state that depends on the particular type of the input stream and how it was created. The bytes that will be supplied to subsequent callers of thereadmethod depend on the particular type of the input stream.
- The call to
- Overrides:
resetin classInputStream- Throws:
IOException- Never thrown. Just for subclassers.- See Also:
- If the method
-
markSupported
public boolean markSupported()Tests if this input stream supports themarkandresetmethods. Whether or notmarkandresetare supported is an invariant property of a particular input stream instance. ThemarkSupportedmethod ofInputStreamreturnsfalse.- Overrides:
markSupportedin classInputStream- Returns:
true.- See Also:
-
mark
public void mark(int readlimit) Marks the current position in this input stream. A subsequent call to theresetmethod repositions this stream at the last marked position so that subsequent reads re-read the same bytes.The
readlimitarguments tells this input stream to allow that many bytes to be read before the mark position gets invalidated.The general contract of
markis that, if the methodmarkSupportedreturnstrue, the stream somehow remembers all the bytes read after the call tomarkand stands ready to supply those same bytes again if and whenever the methodresetis called. However, the stream is not required to remember any data at all if more thanreadlimitbytes are read from the stream beforeresetis called.- Overrides:
markin classInputStream- Parameters:
readlimit- Not used.- See Also:
-