Class GenericReplayCharSequence
java.lang.Object
org.archive.io.GenericReplayCharSequence
- All Implemented Interfaces:
Closeable,AutoCloseable,CharSequence,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 Summary
FieldsModifier and TypeFieldDescriptionprotected Charsetprotected CharacterCodingExceptionprotected longcounter of decoding exceptions for report at endprotected intTotal length of character stream to replay minus the HTTP headers if present.protected static Loggerstatic final CharsetName of the encoding we use writing out concatenated decoded prefix buffer and decoded backing file.Fields inherited from interface org.archive.io.ReplayCharSequence
FALLBACK_CHARSET -
Constructor Summary
ConstructorsConstructorDescriptionGenericReplayCharSequence(InputStream contentReplayInputStream, int prefixMax, String backingFilename, Charset charset) Constructor. -
Method Summary
Modifier and TypeMethodDescriptioncharcharAt(int index) Get character at passed absolute position.voidclose()Call this method when done so implementation has chance to clean up resources.protected voiddecode(InputStream inStream, int prefixMax, String backingFilename, Charset charset) Converts the firstInteger.MAX_VALUEcharacters from the filebackingFilenamefrom encodingencodingto encodingWRITE_ENCODINGand saves asthis.decodedFile, which is namedbackingFilename + "." + WRITE_ENCODING.protected voidfinalize()Return the effective Charset used to create this CharSequence from (raw byte) source material.Return the first coding-exception encountered, if the count > 0.longReport count of decoder errors silently eaten during ReplayCharSequence use.booleanisOpen()intlength()subSequence(int start, int end) substring(int offset, int len) Deprecated.please use subSequence() and then toString() directlytoString()Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints
-
Field Details
-
logger
-
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 lengthTotal length of character stream to replay minus the HTTP headers if present. If the backing file is larger thanInteger.MAX_VALUE(i.e. 2gb), only the firstInteger.MAX_VALUEcharacters are available through this API. We're overridingjava.lang.CharSequenceso that we can usejava.util.regexdirectly on the data, and theCharSequenceAPI usesintfor the length and index. -
decodingExceptions
protected long decodingExceptionscounter of decoding exceptions for report at end -
codingException
-
charset
-
-
Constructor Details
-
GenericReplayCharSequence
public GenericReplayCharSequence(InputStream contentReplayInputStream, int prefixMax, String backingFilename, Charset charset) throws IOException Constructor.- Parameters:
contentReplayInputStream- inputStream of contentbackingFilename- Path to backing file with content in excess of whats inbuffer.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 firstInteger.MAX_VALUEcharacters from the filebackingFilenamefrom encodingencodingto encodingWRITE_ENCODINGand saves asthis.decodedFile, which is namedbackingFilename + "." + WRITE_ENCODING.- Throws:
IOException
-
charAt
public char charAt(int index) Get character at passed absolute position.- Specified by:
charAtin interfaceCharSequence- Parameters:
index- Index into content- Returns:
- Character at offset
index.
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
isOpen
public boolean isOpen()- Specified by:
isOpenin interfaceReplayCharSequence- Returns:
- false if
ReplayCharSequence.close()has been called
-
close
Description copied from interface:ReplayCharSequenceCall this method when done so implementation has chance to clean up resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceReplayCharSequence- Throws:
IOException- Problem cleaning up file system resources.
-
finalize
-
substring
Deprecated.please use subSequence() and then toString() directlyConvenience method for getting a substring. -
toString
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
length
public int length()- Specified by:
lengthin interfaceCharSequence
-
getDecodeExceptionCount
public long getDecodeExceptionCount()Description copied from interface:ReplayCharSequenceReport 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:
getDecodeExceptionCountin interfaceReplayCharSequence
-
getCodingException
Description copied from interface:ReplayCharSequenceReturn the first coding-exception encountered, if the count > 0.- Specified by:
getCodingExceptionin interfaceReplayCharSequence- Returns:
- CharacterCodingException
-
getCharset
Description copied from interface:ReplayCharSequenceReturn the effective Charset used to create this CharSequence from (raw byte) source material.- Specified by:
getCharsetin interfaceReplayCharSequence
-