com.sun.labs.minion.util
Class ChannelUtil

java.lang.Object
  extended by com.sun.labs.minion.util.ChannelUtil

public class ChannelUtil
extends java.lang.Object


Field Summary
protected static int BLOCK_SIZE
          The block size in which buffers will be written.
protected static java.lang.String logTag
           
 
Constructor Summary
ChannelUtil()
           
 
Method Summary
static java.nio.ByteBuffer readFully(java.nio.channels.FileChannel c, long off, java.nio.ByteBuffer b)
          Reads a byte buffer fully from the given channel at the given position, retrying if necessary.
static java.nio.ByteBuffer readFully(java.nio.channels.ReadableByteChannel c, java.nio.ByteBuffer b)
          Reads a byte buffer fully from the given channel, retrying if necessary.
static void transferFully(java.nio.channels.FileChannel src, java.nio.channels.FileChannel dst)
          Transfers the complete content of a channel to another, making sure that all data is written.
static void transferFully(java.nio.channels.FileChannel src, long position, long count, java.nio.channels.FileChannel dst)
          Transfers a portion of the content of one channel to another, making sure that all data is written.
static void writeFully(java.nio.channels.GatheringByteChannel c, java.nio.ByteBuffer[] b, long size)
          Writes an array of byte buffers fully to the given channel.
static void writeFully(java.nio.channels.WritableByteChannel c, java.nio.ByteBuffer b)
          Writes a byte buffer fully to the given channel.
protected static int writeFullyInternal(java.nio.channels.WritableByteChannel c, java.nio.ByteBuffer b)
          Writes a byte buffer fully to the given channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logTag

protected static java.lang.String logTag

BLOCK_SIZE

protected static final int BLOCK_SIZE
The block size in which buffers will be written.

See Also:
Constant Field Values
Constructor Detail

ChannelUtil

public ChannelUtil()
Method Detail

writeFully

public static void writeFully(java.nio.channels.WritableByteChannel c,
                              java.nio.ByteBuffer b)
                       throws java.io.IOException
Writes a byte buffer fully to the given channel. The data is written in chunks of BLOCK_SIZE bytes.

Parameters:
c - The channel that we will write to.
b - The buffer we wish to write.
Throws:
java.io.IOException - If there is any error during writing.

writeFully

public static void writeFully(java.nio.channels.GatheringByteChannel c,
                              java.nio.ByteBuffer[] b,
                              long size)
                       throws java.io.IOException
Writes an array of byte buffers fully to the given channel. The data is written in chunks of BLOCK_SIZE bytes.

Parameters:
size - The number of bytes to write to the channels.
c - The channel that we will write to.
b - The buffer we wish to write.
Throws:
java.io.IOException - If there is any error during writing.

writeFullyInternal

protected static int writeFullyInternal(java.nio.channels.WritableByteChannel c,
                                        java.nio.ByteBuffer b)
                                 throws java.io.IOException
Writes a byte buffer fully to the given channel.

Parameters:
c - The channel that we will write to.
b - The buffer we wish to write.
Returns:
The number of byte read.
Throws:
java.io.IOException - If there is any error during writing.

readFully

public static java.nio.ByteBuffer readFully(java.nio.channels.ReadableByteChannel c,
                                            java.nio.ByteBuffer b)
                                     throws java.io.IOException
Reads a byte buffer fully from the given channel, retrying if necessary.

Parameters:
c - The channel that we will write to.
b - The buffer we wish to write.
Returns:
The byte buffer.
Throws:
java.io.IOException - If there is any error during reading.

readFully

public static java.nio.ByteBuffer readFully(java.nio.channels.FileChannel c,
                                            long off,
                                            java.nio.ByteBuffer b)
                                     throws java.io.IOException
Reads a byte buffer fully from the given channel at the given position, retrying if necessary.

Parameters:
c - The channel that we will write to.
off - The offset to read from.
b - The buffer we wish to write.
Returns:
The buffer.
Throws:
java.io.IOException - If there is any error during reading.

transferFully

public static void transferFully(java.nio.channels.FileChannel src,
                                 java.nio.channels.FileChannel dst)
                          throws java.io.IOException
Transfers the complete content of a channel to another, making sure that all data is written.

Parameters:
src - The source channel.
dst - The destination channel.
Throws:
java.io.IOException - If there is any error transferring the data.

transferFully

public static void transferFully(java.nio.channels.FileChannel src,
                                 long position,
                                 long count,
                                 java.nio.channels.FileChannel dst)
                          throws java.io.IOException
Transfers a portion of the content of one channel to another, making sure that all data is written.

Parameters:
src - The source channel.
position - The position in the source channel.
count - The number of bytes to transfer.
dst - The destination channel.
Throws:
java.io.IOException - If there is any error transferring the data.