|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.faunos.util.io.ChannelUtil<E>
public class ChannelUtil<E extends RuntimeException>
A utility class for reading and writing to
Field Summary
protected ThrowFactory<RuntimeException,E>
exceptionFactory
Constructor Summary
ChannelUtil(Class<E> exceptionClass)
ChannelUtil(ThrowFactory<RuntimeException,E> exceptionFactory)
Method Summary
static ChannelUtil<RuntimeException>
defaultInstance()
void
readRemaining(FileChannel channel,
ByteBuffer buffer,
long position)
Reads bytes from the given file channel into the specified
buffer.
void
readRemaining(ReadableByteChannel channel,
ByteBuffer buffer)
Reads bytes from the given generic channel into the specified
buffer.
void
readRemaining(ScatteringByteChannel channel,
ByteBuffer[] buffers)
Reads bytes from the given scattering channel into the specified
buffer array.
void
setSize(FileChannel channel,
long size)
Sets the file size.
void
transferFrom(FileChannel channel,
long position,
long count,
ReadableByteChannel source)
Transfers the specified number of bytes from the given
source
into the given destination channel
.
void
transferTo(FileChannel channel,
long position,
long count,
WritableByteChannel sink)
Transfers the specified number of bytes from the given
source channel
into the given sink
.
void
writeRemaining(FileChannel channel,
ByteBuffer buffer,
long position)
Writes the remaining bytes in the given buffer to the specified
file channel starting at the specified position.
void
writeRemaining(WritableByteChannel channel,
ByteBuffer buffer)
Writes the remaining bytes in the given buffer to the specified generic
channel.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Field Detail
exceptionFactory
protected final ThrowFactory<RuntimeException,E extends RuntimeException> exceptionFactory
Constructor Detail
ChannelUtil
public ChannelUtil(Class<E> exceptionClass)
ChannelUtil
public ChannelUtil(ThrowFactory<RuntimeException,E> exceptionFactory)
Method Detail
defaultInstance
public static final ChannelUtil<RuntimeException> defaultInstance()
setSize
public void setSize(FileChannel channel,
long size)
throws IOException
- Sets the file size. This is a workaround for the fact that you can't
increase a file's size trivially through its
FileChannel
.
- Throws:
IOException
readRemaining
public void readRemaining(FileChannel channel,
ByteBuffer buffer,
long position)
throws IOException
- Reads bytes from the given file channel into the specified
buffer. The number of bytes read is equal to the number
of remaining bytes in the specified buffer: if EOF is reached
before filling the buffer, an app-specific exception is raised.
Bytes are read starting from the specified position. The current
position of the file channel is not modified.
- Throws:
IOException
- See Also:
readRemaining(ReadableByteChannel, ByteBuffer)
,
readRemaining(ScatteringByteChannel, ByteBuffer[])
readRemaining
public void readRemaining(ReadableByteChannel channel,
ByteBuffer buffer)
throws IOException
- Reads bytes from the given generic channel into the specified
buffer. The number of bytes read is equal to the number
of remaining bytes in the specified buffer: if EOF is reached
before filling the buffer, an app-specific exception is raised.
Bytes are read starting from the current (possibly implicit)
position of the channel. On return, the current position of the
channel is incremented by the number of bytes read.
- Throws:
IOException
- See Also:
readRemaining(ScatteringByteChannel, ByteBuffer[])
,
readRemaining(FileChannel, ByteBuffer, long)
readRemaining
public void readRemaining(ScatteringByteChannel channel,
ByteBuffer[] buffers)
throws IOException
- Reads bytes from the given scattering channel into the specified
buffer array. The number of bytes read is equal to the sum of the
of remaining bytes in the given buffers: if EOF is reached
before filling the buffers, an app-specific exception is raised.
Bytes are read starting from the current (possibly implicit)
position of the channel. On return, the current position of the
channel is incremented by the number of bytes read.
- Throws:
IOException
- See Also:
readRemaining(ReadableByteChannel, ByteBuffer)
,
readRemaining(FileChannel, ByteBuffer, long)
writeRemaining
public void writeRemaining(WritableByteChannel channel,
ByteBuffer buffer)
throws IOException
- Writes the remaining bytes in the given buffer to the specified generic
channel. The bytes are written starting at the (possibly implicit)
current position of the channel. On return, the current position of
the channel is incremented by the number of bytes written.
- Throws:
IOException
- See Also:
writeRemaining(FileChannel, ByteBuffer, long)
writeRemaining
public void writeRemaining(FileChannel channel,
ByteBuffer buffer,
long position)
throws IOException
- Writes the remaining bytes in the given buffer to the specified
file channel starting at the specified position. This method
does not modify the file channel's current position.
- Throws:
IOException
- See Also:
writeRemaining(WritableByteChannel, ByteBuffer)
transferTo
public void transferTo(FileChannel channel,
long position,
long count,
WritableByteChannel sink)
throws IOException
- Transfers the specified number of bytes from the given
source
channel
into the given sink
.
The arguments are checked for bounds before invocation.
- Parameters:
channel
- the source channelposition
- the starting position from which bytes will be readcount
- the number of bytes to be transferedsink
- the destination channel
- Throws:
IOException
transferFrom
public void transferFrom(FileChannel channel,
long position,
long count,
ReadableByteChannel source)
throws IOException
- Transfers the specified number of bytes from the given
source
into the given destination channel
.
The arguments are checked for bounds before invocation. If it turns
out the given source
does not have enough remaining
bytes, then an instance-specific exception is raised.
- Parameters:
channel
- the destination channelposition
- the starting position in the destination channel
at which bytes will be writtencount
- the number of bytes to transfersource
- the source channel
- Throws:
IOException
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD