Class HTMLScanner.PlaybackInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
- Enclosing class:
- HTMLScanner
If the encoding is changed, then the scanner calls the
playback method and re-scans the beginning of the HTML
document again. This should not be too much of a performance problem
because the <meta> tag appears at the beginning of the document.
If the <body> tag is reached without playing back the bytes,
then the buffer can be cleared by calling the clear
method. This stops the buffering of bytes and allows the memory used
by the buffer to be reclaimed.
Note: If the buffer is never played back or cleared, this input stream will continue to buffer the entire stream. Therefore, it is very important to use this stream correctly.
- Author:
- Andy Clark
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]Byte buffer.protected intLength of bytes read into byte buffer.protected intOffset into byte buffer during playback.protected booleanBuffer cleared.protected booleanEncoding detected.protected booleanPlayback mode.intPushback length.intPushback offset.Fields inherited from class java.io.FilterInputStream
in -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the buffer.voiddetectEncoding(String[] encodings) Detect encoding.voidplayback()Playback buffer contents.intread()Read a byte.intread(byte[] array) Read an array of bytes.intread(byte[] array, int offset, int length) Read an array of bytes.Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, reset, skipMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
fPlayback
protected boolean fPlaybackPlayback mode. -
fCleared
protected boolean fClearedBuffer cleared. -
fDetected
protected boolean fDetectedEncoding detected. -
fByteBuffer
protected byte[] fByteBufferByte buffer. -
fByteOffset
protected int fByteOffsetOffset into byte buffer during playback. -
fByteLength
protected int fByteLengthLength of bytes read into byte buffer. -
fPushbackOffset
public int fPushbackOffsetPushback offset. -
fPushbackLength
public int fPushbackLengthPushback length.
-
-
Constructor Details
-
PlaybackInputStream
Constructor.
-
-
Method Details
-
detectEncoding
Detect encoding.- Throws:
IOException
-
playback
public void playback()Playback buffer contents. -
clear
public void clear()Clears the buffer.Note: The buffer cannot be cleared during playback. Therefore, calling this method during playback will not do anything. However, the buffer will be cleared automatically at the end of playback.
-
read
Read a byte.- Overrides:
readin classFilterInputStream- Throws:
IOException
-
read
Read an array of bytes.- Overrides:
readin classFilterInputStream- Throws:
IOException
-
read
Read an array of bytes.- Overrides:
readin classFilterInputStream- Throws:
IOException
-