Package com.mckoi.store
Class StreamFile
- java.lang.Object
-
- com.mckoi.store.StreamFile
-
public class StreamFile extends java.lang.Object
A RandomAccessFile that acts as an OutputStream, and can also be read as an InputStream.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
StreamFile.SFInputStream
(package private) class
StreamFile.SFOutputStream
-
Field Summary
Fields Modifier and Type Field Description private java.io.RandomAccessFile
data
The RandomAccessFile.private long
end_pointer
Pointer to the end of the file.private java.io.File
file
The File object.private java.io.OutputStream
output_stream
The OutputStream object for this file.
-
Constructor Summary
Constructors Constructor Description StreamFile(java.io.File file, java.lang.String mode)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the file.void
delete()
Deletes the file.java.io.InputStream
getInputStream()
Returns an InputStream to the file that allows us to read from the start to the end of the file.java.io.OutputStream
getOutputStream()
Opens an OutputStream to the file.long
length()
Returns the current length of the data.void
readFully(long position, byte[] buf, int off, int len)
Fully reads a block from a section of the file into the given byte[] array at the given position.void
synch()
Synchs the file.
-
-
-
Method Detail
-
close
public void close() throws java.io.IOException
Closes the file.- Throws:
java.io.IOException
-
synch
public void synch() throws java.io.IOException
Synchs the file.- Throws:
java.io.IOException
-
delete
public void delete() throws java.io.IOException
Deletes the file.- Throws:
java.io.IOException
-
readFully
public void readFully(long position, byte[] buf, int off, int len) throws java.io.IOException
Fully reads a block from a section of the file into the given byte[] array at the given position.- Throws:
java.io.IOException
-
length
public long length()
Returns the current length of the data.
-
getOutputStream
public java.io.OutputStream getOutputStream() throws java.io.IOException
Opens an OutputStream to the file. Only one output stream may be open on the file at once.- Throws:
java.io.IOException
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
Returns an InputStream to the file that allows us to read from the start to the end of the file.- Throws:
java.io.IOException
-
-