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

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

public class ChannelPostingsOutput
extends java.lang.Object
implements PostingsOutput

An implementation of PostingsOutput that buffers the postings, eventually writing them to a channel.


Field Summary
protected  java.nio.ByteBuffer buff
          A buffer.
protected  java.nio.channels.FileChannel chan
          The channel.
protected static int DEFAULT_SIZE
          The default buffer size, 64K.
 
Constructor Summary
ChannelPostingsOutput(java.nio.channels.FileChannel chan)
          Creates a postings output channel that will write to the given channel.
ChannelPostingsOutput(java.nio.channels.FileChannel chan, int buffSize)
          Creates a postings output channel that will write to the given channel, buffering the given amount.
 
Method Summary
 void flush()
          Flushes the buffer to the channel.
 long position()
          Gets the position of the the channel.
 int write(WriteableBuffer b)
          Writes a set of postings to the channel (possibly buffering them).
 long write(WriteableBuffer[] b)
          Writes a set of postings encoded onto a buffer to the channel (possibly buffering them).
 long write(WriteableBuffer[] b, int offset, int length)
          Writes a subsequence of a set of postings encoded onto a buffer to the channel (possibly buffering them).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buff

protected java.nio.ByteBuffer buff
A buffer.


chan

protected java.nio.channels.FileChannel chan
The channel.


DEFAULT_SIZE

protected static final int DEFAULT_SIZE
The default buffer size, 64K.

See Also:
Constant Field Values
Constructor Detail

ChannelPostingsOutput

public ChannelPostingsOutput(java.nio.channels.FileChannel chan)
Creates a postings output channel that will write to the given channel.

Parameters:
chan - The channel to write data to.

ChannelPostingsOutput

public ChannelPostingsOutput(java.nio.channels.FileChannel chan,
                             int buffSize)
Creates a postings output channel that will write to the given channel, buffering the given amount.

Parameters:
chan - The channel to write data to.
buffSize - The size of the buffer to use for writing postings.
Method Detail

write

public int write(WriteableBuffer b)
          throws java.io.IOException
Writes a set of postings to the channel (possibly buffering them).

Specified by:
write in interface PostingsOutput
Parameters:
b - The buffer 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 buffer to the channel (possibly buffering them).

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 buffer to the channel (possibly buffering them).

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 to the channel.

position

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

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

flush

public void flush()
           throws java.io.IOException
Flushes the buffer to the channel.

Specified by:
flush in interface PostingsOutput
Throws:
java.io.IOException - If there is any error writing data to the channel.