com.mckoi.store
Class StreamFile

java.lang.Object
  extended by 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.

Author:
Tobias Downer

Constructor Summary
StreamFile(java.io.File file, java.lang.String mode)
          Constructor.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamFile

public StreamFile(java.io.File file,
                  java.lang.String mode)
           throws java.io.IOException
Constructor.

Throws:
java.io.IOException
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