Class PlaybackInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.htmlunit.cyberneko.io.PlaybackInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public final class PlaybackInputStream extends java.io.InputStreamA playback input stream. This class has the ability to save the bytes read from the underlying input stream and play the bytes back later. This class is used by the HTML scanner to switch encodings when a <meta> tag is detected that specifies a different encoding.If the encoding is changed, then the scanner calls the
playbackmethod 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
clearmethod. 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.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]byteBuffer_Byte buffer.private intbyteLength_Length of bytes read into byte buffer.private intbyteOffset_Offset into byte buffer during playback.private booleancleared_Buffer cleared.private static booleanDEBUG_PLAYBACKSet to true to debug playback.private booleandetected_Encoding detected.private java.io.InputStreamin_Our inputstreamprivate booleanplayback_Playback mode.private intpushbackLength_Pushback length.private intpushbackOffset_Pushback offset.
-
Constructor Summary
Constructors Constructor Description PlaybackInputStream(java.io.InputStream inputStream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears the buffer.voiddetectEncoding(java.lang.String[] encodings)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.
-
-
-
Field Detail
-
DEBUG_PLAYBACK
private static final boolean DEBUG_PLAYBACK
Set to true to debug playback.- See Also:
- Constant Field Values
-
playback_
private boolean playback_
Playback mode.
-
cleared_
private boolean cleared_
Buffer cleared.
-
detected_
private boolean detected_
Encoding detected.
-
byteBuffer_
private byte[] byteBuffer_
Byte buffer.
-
byteOffset_
private int byteOffset_
Offset into byte buffer during playback.
-
byteLength_
private int byteLength_
Length of bytes read into byte buffer.
-
pushbackOffset_
private int pushbackOffset_
Pushback offset.
-
pushbackLength_
private int pushbackLength_
Pushback length.
-
in_
private final java.io.InputStream in_
Our inputstream
-
-
Method Detail
-
detectEncoding
public void detectEncoding(java.lang.String[] encodings) throws java.io.IOException- Throws:
java.io.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
public int read() throws java.io.IOExceptionRead a byte.- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] array) throws java.io.IOExceptionRead an array of bytes.- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] array, int offset, int length) throws java.io.IOExceptionRead an array of bytes.- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
-