au.com.prunge.jgenfile.channels
Interface RandomAccessChannel

All Superinterfaces:
Channel
All Known Subinterfaces:
RandomAccessByteChannel, RandomAccessReadableByteChannel, RandomAccessWritableByteChannel
All Known Implementing Classes:
RandomAccessFileChannel

public interface RandomAccessChannel
extends Channel

Interface for a channel that supports random access to its data. In other words, the channel has a position and its position may be modified.

Version:
1.0
Author:
Peter Runge

Method Summary
 long position()
          Returns the channel's position.
 RandomAccessChannel position(long newPosition)
          Sets this channel's position.
 long size()
          Returns the size of this channel.
 
Methods inherited from interface java.nio.channels.Channel
close, isOpen
 

Method Detail

position

public long position()
              throws ClosedChannelException,
                     IOException
Returns the channel's position.

Returns:
This channel's position, a non-negative integer counting the number of bytes from the beginning of the channel to the current position.
Throws:
ClosedChannelException - if the channel was closed.
IOException - if an I/O error occurs.

position

public RandomAccessChannel position(long newPosition)
                             throws IOException,
                                    ClosedChannelException,
                                    IllegalArgumentException
Sets this channel's position.

Setting the position to a value that is greater than the channel's current size is legal but does not change its size. A later attempt to read bytes at such a position will immediately return an end-of-file indication. A later attempt to write bytes at such a position will cause the channel to be grown to accomodate the new bytes; the values of any bytes between the previous end-of-file and the newly-written bytes are unspecified.

Parameters:
newPosition - The new position, a non-negative integer counting the number of bytes from the beginning of the channel.
Returns:
this channel.
Throws:
IllegalArgumentException - If the new position is negative.
ClosedChannelException - if the channel was closed.
IOException - if an I/O error occurs.

size

public long size()
          throws IOException,
                 ClosedChannelException
Returns the size of this channel.

Returns:
the size of this channel in bytes.
Throws:
ClosedChannelException - if the channel was closed.
IOException - if an I/O error occurs.