Class PlaybackInputStream

java.lang.Object
java.io.InputStream
org.htmlunit.cyberneko.io.PlaybackInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public final class PlaybackInputStream extends InputStream
A 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 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
  • Constructor Details

    • PlaybackInputStream

      public PlaybackInputStream(InputStream inputStream)
  • Method Details

    • detectEncoding

      public void detectEncoding(String[] encodings) throws IOException
      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

      public int read() throws IOException
      Read a byte.
      Specified by:
      read in class InputStream
      Throws:
      IOException
    • read

      public int read(byte[] array) throws IOException
      Read an array of bytes.
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • read

      public int read(byte[] array, int offset, int length) throws IOException
      Read an array of bytes.
      Overrides:
      read in class InputStream
      Throws:
      IOException