com.continuent.tungsten.common.io
Class BufferedFileDataOutput

java.lang.Object
  extended by com.continuent.tungsten.common.io.BufferedFileDataOutput

public class BufferedFileDataOutput
extends java.lang.Object

Merges the capabilities of the following stream classes into a single class: FileOutputStream, BufferedOutputStream, and DataOutputStream. This allows us to manage buffered data writes to files efficiently.

Author:
Robert Hodges

Constructor Summary
BufferedFileDataOutput(java.io.File file)
          Creates instance with default buffer size.
BufferedFileDataOutput(java.io.File file, int bufferSize)
          Creates instance positioned on end of file and read to write.
 
Method Summary
 void close()
          Close and release all resources.
 void flush()
          Flush buffered data to stream.
 void fsync()
          Synchronizes file contents to disk using fsync.
 long getOffset()
          Returns the current offset position.
 void setLength(long length)
          Truncate the file to the provided length.
 java.lang.String toString()
          Print contents of the reader.
 void write(byte[] bytes)
          Writes a byte array completely.
 void writeByte(byte v)
          Writes a single byte.
 void writeInt(int v)
          Writes a single int.
 void writeLong(long v)
          Writes a single long.
 void writeShort(short v)
          Writes a single short.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BufferedFileDataOutput

public BufferedFileDataOutput(java.io.File file,
                              int bufferSize)
                       throws java.io.FileNotFoundException,
                              java.io.IOException
Creates instance positioned on end of file and read to write.

Parameters:
file - File to which to write.
bufferSize - Size of buffer for buffered I/O
Throws:
java.io.FileNotFoundException
java.io.IOException

BufferedFileDataOutput

public BufferedFileDataOutput(java.io.File file)
                       throws java.io.FileNotFoundException,
                              java.io.IOException
Creates instance with default buffer size.

Throws:
java.io.FileNotFoundException
java.io.IOException
Method Detail

getOffset

public long getOffset()
               throws java.io.IOException
Returns the current offset position.

Throws:
java.io.IOException - Thrown if position cannot be determined

writeByte

public void writeByte(byte v)
               throws java.io.IOException
Writes a single byte.

Throws:
java.io.IOException

writeShort

public void writeShort(short v)
                throws java.io.IOException
Writes a single short.

Throws:
java.io.IOException

writeInt

public void writeInt(int v)
              throws java.io.IOException
Writes a single int.

Throws:
java.io.IOException

writeLong

public void writeLong(long v)
               throws java.io.IOException
Writes a single long.

Throws:
java.io.IOException

write

public void write(byte[] bytes)
           throws java.io.IOException
Writes a byte array completely.

Throws:
java.io.IOException - Thrown if full byte array cannot be written

flush

public void flush()
           throws java.io.IOException
Flush buffered data to stream. This does not guarantee persistence, only that lower streams can see it.

Throws:
java.io.IOException - Thrown if flush fails

fsync

public void fsync()
           throws java.io.IOException
Synchronizes file contents to disk using fsync. You must call this method to commit data. Does an automatic flush.

Throws:
java.io.IOException

setLength

public void setLength(long length)
               throws java.io.IOException
Truncate the file to the provided length. Performs an automatic fsync and reopens the file.

Throws:
java.io.IOException

close

public void close()
Close and release all resources.


toString

public java.lang.String toString()
Print contents of the reader.

Overrides:
toString in class java.lang.Object