com.bigdata.bfs
Class FileVersionOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.bigdata.bfs.FileVersionOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class FileVersionOutputStream
extends OutputStream

Class buffers up to a block of data at a time and flushes blocks using an atomic append operation on the identifier file version.

Version:
$Id: FileVersionOutputStream.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
TODO:
this would benefit from asynchronous write-behind of the last block so that caller's do not wait for the RPC that writes the block onto the data index. use a blocking queue of buffers to be written so that the caller can not get far ahead of the database. a queue capacity of 1 or 2 should be sufficient.

Field Summary
protected  String id
           
protected  BigdataFileSystem repo
           
protected  int version
           
 
Constructor Summary
FileVersionOutputStream(BigdataFileSystem repo, String id, int version)
          Create an output stream that will atomically append blocks of data to the specified file version.
 
Method Summary
 void close()
          Flushes the buffer.
 long copyStream(InputStream is)
          Consumes the input stream, writing blocks onto the file version.
 void flush()
          If there is data data accumulated in the buffer then it is written on the file version using an atomic append (empty buffers are NOT flushed).
 long getBlockCount()
          #of blocks written onto the file version.
 long getByteCount()
          #of bytes written onto this output stream.
 String getId()
          The file identifier.
 int getVersion()
          The file version identifer.
 void write(int b)
          Buffers the byte.
 
Methods inherited from class java.io.OutputStream
write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

repo

protected final BigdataFileSystem repo

id

protected final String id

version

protected final int version
Constructor Detail

FileVersionOutputStream

public FileVersionOutputStream(BigdataFileSystem repo,
                               String id,
                               int version)
Create an output stream that will atomically append blocks of data to the specified file version.

Parameters:
id - The file identifier.
version - The version identifier.
Method Detail

getId

public String getId()
The file identifier.


getVersion

public int getVersion()
The file version identifer.


getByteCount

public long getByteCount()
#of bytes written onto this output stream.

TODO:
handle overflow of long - leave counter at Long.MAX_VALUE.

getBlockCount

public long getBlockCount()
#of blocks written onto the file version.


write

public void write(int b)
           throws IOException
Buffers the byte. If the buffer would overflow then it is flushed.

Specified by:
write in class OutputStream
Throws:
IOException

flush

public void flush()
           throws IOException
If there is data data accumulated in the buffer then it is written on the file version using an atomic append (empty buffers are NOT flushed).

Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException

close

public void close()
           throws IOException
Flushes the buffer.

Specified by:
close in interface Closeable
Overrides:
close in class OutputStream
Throws:
IOException

copyStream

public long copyStream(InputStream is)
                throws IOException
Consumes the input stream, writing blocks onto the file version. The output stream is NOT flushed.

Parameters:
is - The input stream (closed iff it is fully consumed).
Returns:
The #of bytes copied from the input stream.
Throws:
IOException


Copyright © 2006-2011 SYSTAP, LLC. All Rights Reserved.