public class NioUtils extends Object
Modifier and Type | Method and Description |
---|---|
static int |
copy(ByteBuffer sourceBuffer,
ByteBuffer targetBuffer,
long maxCopied)
Writes the source buffer to the target buffer, up to a maximum number of
bytes.
|
static void |
copy(FileChannel fileChannel,
WritableByteChannel writableChannel)
Writes the representation to a byte channel.
|
static void |
copy(ReadableByteChannel readableChannel,
OutputStream outputStream)
Writes a NIO readable channel to a BIO output stream.
|
static void |
copy(ReadableByteChannel readableChannel,
WritableByteChannel writableChannel)
Writes a readable channel to a writable channel.
|
static ReadableByteChannel |
getChannel(InputStream inputStream)
Returns a readable byte channel based on a given input stream.
|
static WritableByteChannel |
getChannel(OutputStream outputStream)
Returns a writable byte channel based on a given output stream.
|
static ReadableByteChannel |
getChannel(Representation representation)
Returns a readable byte channel based on the given representation's
content and its write(WritableByteChannel) method.
|
static InputStream |
getStream(ReadableByteChannel readableChannel)
Returns an input stream based on a given readable byte channel.
|
static OutputStream |
getStream(WritableByteChannel writableChannel)
Returns an output stream based on a given writable byte channel.
|
static boolean |
isBlocking(Channel channel)
Indicates if the channel is in blocking mode.
|
static void |
release(Selector selector,
SelectionKey selectionKey)
Release the selection key, working around for bug #6403933.
|
static void |
waitForState(SelectableChannel selectableChannel,
int operations)
Waits for the given channel to be ready for a specific operation.
|
public static int copy(ByteBuffer sourceBuffer, ByteBuffer targetBuffer, long maxCopied)
sourceBuffer
- The source buffer.targetBuffer
- The target buffer.maxCopied
- The maximum number of bytes copied by this call or 0 for
unlimited length.public static void copy(FileChannel fileChannel, WritableByteChannel writableChannel) throws IOException
fileChannel
- The readable file channel.writableChannel
- A writable byte channel.IOException
public static void copy(ReadableByteChannel readableChannel, OutputStream outputStream) throws IOException
readableChannel
- The readable channel.outputStream
- The output stream.IOException
public static void copy(ReadableByteChannel readableChannel, WritableByteChannel writableChannel) throws IOException
readableChannel
- The readable channel.writableChannel
- The writable channel.IOException
public static ReadableByteChannel getChannel(InputStream inputStream) throws IOException
inputStream
- The input stream to convert.IOException
public static WritableByteChannel getChannel(OutputStream outputStream)
outputStream
- The output stream.public static ReadableByteChannel getChannel(Representation representation) throws IOException
representation
- the representation to get the OutputStream
from.IOException
public static InputStream getStream(ReadableByteChannel readableChannel)
readableChannel
- The readable byte channel.public static OutputStream getStream(WritableByteChannel writableChannel)
writableChannel
- The writable byte channel.public static boolean isBlocking(Channel channel)
channel
- The channel to test.public static void release(Selector selector, SelectionKey selectionKey) throws IOException
selector
- The associated selector.selectionKey
- The used selection key.IOException
public static void waitForState(SelectableChannel selectableChannel, int operations) throws IOException
selectableChannel
- The channel to monitor.operations
- The operations to be ready to do.IOException
Copyright © 2005–2014. All rights reserved.