java.lang.Object
i2p.susi.util.FileBuffer
i2p.susi.util.GzipFileBuffer
- All Implemented Interfaces:
Buffer
Gzip-compressed file Buffer implementation.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longLength of the decoded data, in bytes.private CountingInputStreamStream counting the bytes read.private CountingOutputStreamStream counting the bytes written.Constructor Summary
ConstructorsConstructorDescriptionGzipFileBuffer(File file) Create a GzipFileBuffer for the entire file.GzipFileBuffer(File file, int offset, int sublen) Create a GzipFileBuffer for a portion of the uncompressed data.Method Summary
All MethodsModifier and TypeMethodDescriptionGet a GZIP decompressing InputStream, wrapped with a counter.intReturns the actual uncompressed size.Get a GZIP compressing OutputStream, wrapped with a counter.voidreadComplete(boolean success) Close the input stream and record the uncompressed length if successful.toString()voidwriteComplete(boolean success) Close the output stream and record the uncompressed length if successful.Methods inherited from class FileBuffer
getFile, getOffset
Field Details
_actualLength
private long _actualLengthLength of the decoded data, in bytes._cis
Stream counting the bytes read._cos
Stream counting the bytes written.
Constructor Details
GzipFileBuffer
Create a GzipFileBuffer for the entire file.- Parameters:
file- the gzip-compressed file
GzipFileBuffer
Create a GzipFileBuffer for a portion of the uncompressed data.- Parameters:
file- the gzip-compressed fileoffset- the byte offset to start reading from (uncompressed)sublen- the number of bytes to read (uncompressed), or 0 for all
Method Details
getInputStream
Get a GZIP decompressing InputStream, wrapped with a counter. Caller must callreadComplete(boolean).- Specified by:
getInputStreamin interfaceBuffer- Overrides:
getInputStreamin classFileBuffer- Returns:
- new InputStream chain for reading uncompressed data
- Throws:
IOException- on I/O error
getOutputStream
Get a GZIP compressing OutputStream, wrapped with a counter. Caller must callwriteComplete(boolean).- Specified by:
getOutputStreamin interfaceBuffer- Overrides:
getOutputStreamin classFileBuffer- Returns:
- new OutputStream chain for writing compressed data
- Throws:
IllegalStateException- if offset > 0 or already open for writingIOException- on I/O error
readComplete
public void readComplete(boolean success) Close the input stream and record the uncompressed length if successful.- Specified by:
readCompletein interfaceBuffer- Overrides:
readCompletein classFileBuffer- Parameters:
success- if true, records the bytes read
writeComplete
public void writeComplete(boolean success) Close the output stream and record the uncompressed length if successful.- Specified by:
writeCompletein interfaceBuffer- Overrides:
writeCompletein classFileBuffer- Parameters:
success- if true, records the bytes written
getLength
public int getLength()Returns the actual uncompressed size. Only known after reading and calling readComplete(true), or after writing and calling writeComplete(true), otherwise returns 0.- Specified by:
getLengthin interfaceBuffer- Overrides:
getLengthin classFileBuffer- Returns:
- the uncompressed length in bytes
toString
- Overrides:
toStringin classFileBuffer