java.lang.Object
i2p.susi.util.FileBuffer
- All Implemented Interfaces:
Buffer
- Direct Known Subclasses:
GzipFileBuffer
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final FileThe file.private InputStreamStream the bytes are read from.protected final intThe offset.private OutputStreamStream the bytes are written to.protected final intThe sub-length.Constructor Summary
ConstructorsConstructorDescriptionFileBuffer(File file) Create a FileBuffer for the entire file.FileBuffer(File file, int offset, int sublen) Create a FileBuffer for a portion of the file.Method Summary
All MethodsModifier and TypeMethodDescriptiongetFile()Get the file being buffered.Get an InputStream for the file, skipping to the offset if needed.intGet the length of data in this buffer.intGet the byte offset into the file.Get an OutputStream for the file.voidreadComplete(boolean success) Close the input stream.toString()voidwriteComplete(boolean success) Close the output stream and delete the file if success is false.
Field Details
_file
The file._offset
protected final int _offsetThe offset._sublen
protected final int _sublenThe sub-length._is
Stream the bytes are read from._os
Stream the bytes are written to.
Constructor Details
FileBuffer
Create a FileBuffer for the entire file.- Parameters:
file- the file to buffer
FileBuffer
Create a FileBuffer for a portion of the file.- Parameters:
file- the file to bufferoffset- the byte offset to start reading fromsublen- the number of bytes to read, or 0 for the entire file
Method Details
getFile
getInputStream
Get an InputStream for the file, skipping to the offset if needed. Caller must callreadComplete(boolean).- Specified by:
getInputStreamin interfaceBuffer- Returns:
- a stream positioned at the offset, reusing the open one
- Throws:
IOException- on I/O error
getOutputStream
Get an OutputStream for the file. Caller must callwriteComplete(boolean).- Specified by:
getOutputStreamin interfaceBuffer- Returns:
- a file output stream, reusing the open one
- Throws:
IOException- on I/O error
readComplete
public void readComplete(boolean success) Close the input stream.- Specified by:
readCompletein interfaceBuffer- Parameters:
success- whether the read succeeded; the stream is closed either way
writeComplete
public void writeComplete(boolean success) Close the output stream and delete the file if success is false.- Specified by:
writeCompletein interfaceBuffer- Parameters:
success- if false, deletes the file
getLength
getOffset
toString