com.sun.labs.minion.indexer.postings.io
Class StreamPostingsOutput

java.lang.Object
  extended by com.sun.labs.minion.indexer.postings.io.StreamPostingsOutput
All Implemented Interfaces:
PostingsOutput

public class StreamPostingsOutput
extends java.lang.Object
implements PostingsOutput

A postings output that writes the postings to an output stream. This stream should be buffered for the best performance.


Field Summary
protected  long offset
          The current offset in the stream.
protected  java.io.OutputStream stream
          The stream to which we will write our postings.
 
Constructor Summary
StreamPostingsOutput(java.io.OutputStream stream)
          Creates a postings output from the given stream.
StreamPostingsOutput(java.io.OutputStream stream, long offset)
          Creates a postings output from the given stream.
 
Method Summary
 void close()
          Closes the output stream
 void flush()
          Flushes any buffered output to the underlying storage.
 long position()
          Gets the position of the current output.
 int write(WriteableBuffer b)
          Writes out the given buffer of postings.
 long write(WriteableBuffer[] b)
          Writes a set of postings encoded onto a number of buffers.
 long write(WriteableBuffer[] b, int offset, int length)
          Writes a subsequence of a set of postings encoded onto a number of buffers to the output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stream

protected java.io.OutputStream stream
The stream to which we will write our postings.


offset

protected long offset
The current offset in the stream.

Constructor Detail

StreamPostingsOutput

public StreamPostingsOutput(java.io.OutputStream stream)
Creates a postings output from the given stream. It is a very good idea to use a buffered stream! The stream's initial offset is taken to be 0.

Parameters:
stream - The stream to which postings will be written.

StreamPostingsOutput

public StreamPostingsOutput(java.io.OutputStream stream,
                            long offset)
Creates a postings output from the given stream. The stream's initial offset is taken to be 0.

Parameters:
stream - The stream to which postings will be written.
offset - The initial offset for the stream.
Method Detail

write

public int write(WriteableBuffer b)
          throws java.io.IOException
Writes out the given buffer of postings.

Specified by:
write in interface PostingsOutput
Parameters:
b - A buffer of postings to write.
Returns:
The number of bytes written.
Throws:
java.io.IOException - if there is any error writing the postings.

write

public long write(WriteableBuffer[] b)
           throws java.io.IOException
Writes a set of postings encoded onto a number of buffers.

Specified by:
write in interface PostingsOutput
Parameters:
b - The buffers to write.
Returns:
The number of bytes written.
Throws:
java.io.IOException - if there is any error writing the postings.

write

public long write(WriteableBuffer[] b,
                  int offset,
                  int length)
           throws java.io.IOException
Writes a subsequence of a set of postings encoded onto a number of buffers to the output.

Specified by:
write in interface PostingsOutput
Parameters:
b - The buffers to write.
offset - The offset in b where we will begin writing bytes.
length - The length of the subsequence of b for which we will write postings.
Returns:
The number of bytes written.
Throws:
java.io.IOException - if there is any error writing the postings.

position

public long position()
              throws java.io.IOException
Gets the position of the current output.

Specified by:
position in interface PostingsOutput
Returns:
The current position of the output.
Throws:
java.io.IOException - if there is any error.

flush

public void flush()
           throws java.io.IOException
Flushes any buffered output to the underlying storage.

Specified by:
flush in interface PostingsOutput
Throws:
java.io.IOException - if there is any error flushing the postings.

close

public void close()
           throws java.io.IOException
Closes the output stream

Throws:
java.io.IOException - if there is an error closing the stream