Class GenericReplayCharSequence

java.lang.Object
org.archive.io.GenericReplayCharSequence
All Implemented Interfaces:
Closeable, AutoCloseable, CharSequence, ReplayCharSequence

public class GenericReplayCharSequence extends Object implements ReplayCharSequence
(Replay)CharSequence view on recorded streams.

Call close() on this class when done to clean up resources.

Version:
$Revision$, $Date$
Author:
stack, nlevitt
  • Field Details

    • logger

      protected static Logger logger
    • WRITE_ENCODING

      public static final Charset WRITE_ENCODING
      Name of the encoding we use writing out concatenated decoded prefix buffer and decoded backing file.

      This define is also used as suffix for the file that holds the decodings. The name of the file that holds the decoding is the name of the backing file w/ this encoding for a suffix.

      See Encoding.

    • length

      protected int length
      Total length of character stream to replay minus the HTTP headers if present. If the backing file is larger than Integer.MAX_VALUE (i.e. 2gb), only the first Integer.MAX_VALUE characters are available through this API. We're overriding java.lang.CharSequence so that we can use java.util.regex directly on the data, and the CharSequence API uses int for the length and index.
    • decodingExceptions

      protected long decodingExceptions
      counter of decoding exceptions for report at end
    • codingException

      protected CharacterCodingException codingException
    • charset

      protected Charset charset
  • Constructor Details

    • GenericReplayCharSequence

      public GenericReplayCharSequence(InputStream contentReplayInputStream, int prefixMax, String backingFilename, Charset charset) throws IOException
      Constructor.
      Parameters:
      contentReplayInputStream - inputStream of content
      backingFilename - Path to backing file with content in excess of whats in buffer.
      charset - Encoding to use reading the passed prefix buffer and backing file. Must not be null.
      Throws:
      IOException
  • Method Details

    • decode

      protected void decode(InputStream inStream, int prefixMax, String backingFilename, Charset charset) throws IOException
      Converts the first Integer.MAX_VALUE characters from the file backingFilename from encoding encoding to encoding WRITE_ENCODING and saves as this.decodedFile, which is named backingFilename + "." + WRITE_ENCODING.
      Throws:
      IOException
    • charAt

      public char charAt(int index)
      Get character at passed absolute position.
      Specified by:
      charAt in interface CharSequence
      Parameters:
      index - Index into content
      Returns:
      Character at offset index.
    • subSequence

      public CharSequence subSequence(int start, int end)
      Specified by:
      subSequence in interface CharSequence
    • isOpen

      public boolean isOpen()
      Specified by:
      isOpen in interface ReplayCharSequence
      Returns:
      false if ReplayCharSequence.close() has been called
    • close

      public void close() throws IOException
      Description copied from interface: ReplayCharSequence
      Call this method when done so implementation has chance to clean up resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface ReplayCharSequence
      Throws:
      IOException - Problem cleaning up file system resources.
    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • substring

      public String substring(int offset, int len)
      Deprecated.
      please use subSequence() and then toString() directly
      Convenience method for getting a substring.
    • toString

      public String toString()
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
    • length

      public int length()
      Specified by:
      length in interface CharSequence
    • getDecodeExceptionCount

      public long getDecodeExceptionCount()
      Description copied from interface: ReplayCharSequence
      Report count of decoder errors silently eaten during ReplayCharSequence use. May be less than the number of individual decoding anomalies in underlying content (if decoding method doesn't allow counting individual errors).
      Specified by:
      getDecodeExceptionCount in interface ReplayCharSequence
    • getCodingException

      public CharacterCodingException getCodingException()
      Description copied from interface: ReplayCharSequence
      Return the first coding-exception encountered, if the count > 0.
      Specified by:
      getCodingException in interface ReplayCharSequence
      Returns:
      CharacterCodingException
    • getCharset

      public Charset getCharset()
      Description copied from interface: ReplayCharSequence
      Return the effective Charset used to create this CharSequence from (raw byte) source material.
      Specified by:
      getCharset in interface ReplayCharSequence