public final class IoUtils extends Object
Modifier and Type | Method and Description |
---|---|
static IoFuture.Notifier<Object,Closeable> |
attachmentClosingNotifier()
Get a notifier that closes the attachment.
|
static void |
awaitAll(IoFuture<?>... futures)
Wait for all the futures to complete.
|
static void |
awaitAllInterruptibly(IoFuture<?>... futures)
Wait for all the futures to complete.
|
static <I,O> IoFuture<? extends O> |
cast(IoFuture<I> parent,
Class<O> type)
Create an
IoFuture which wraps another IoFuture , but returns a different type. |
static <T extends Channel> |
channelListenerNotifier()
Get the notifier that invokes the channel listener given as an attachment.
|
static Cancellable |
closingCancellable(Closeable c)
A cancellable which closes the given resource on cancel.
|
static IoFuture.Notifier<Closeable,Void> |
closingNotifier()
Get a notifier that closes the result.
|
static Executor |
directExecutor()
Get the direct executor.
|
static <T> Future<T> |
getFuture(IoFuture<T> ioFuture)
Get a
java.util.concurrent -style Future instance wrapper for an IoFuture instance. |
static <T> IoFuture.Notifier<T,FutureResult<T>> |
getManagerNotifier()
Get a notifier which forwards the result to another
IoFuture 's manager. |
static <T extends Channel> |
getRetryingChannelSource(ChannelSource<T> delegate,
int maxTries)
A channel source which tries to acquire a channel from a delegate channel source the given number of times before
giving up.
|
static Random |
getThreadLocalRandom()
Get a thread-local RNG.
|
static Cancellable |
nullCancellable()
Get the null cancellable.
|
static Closeable |
nullCloseable()
Get the null closeable.
|
static Executor |
nullExecutor()
Get the null executor.
|
static <T> IoFuture.Notifier<T,Result<T>> |
resultNotifier()
Get the result notifier.
|
static <T> IoFuture.Notifier<T,Void> |
runnableNotifier(Runnable runnable)
Get a notifier that runs the supplied action.
|
static void |
safeClose(Closeable resource)
Close a resource, logging an error if an error occurs.
|
static void |
safeClose(DatagramSocket resource)
Close a resource, logging an error if an error occurs.
|
static void |
safeClose(Handler resource)
Close a resource, logging an error if an error occurs.
|
static void |
safeClose(IoFuture<? extends Closeable> futureResource)
Close a future resource, logging an error if an error occurs.
|
static void |
safeClose(Selector resource)
Close a resource, logging an error if an error occurs.
|
static void |
safeClose(ServerSocket resource)
Close a resource, logging an error if an error occurs.
|
static void |
safeClose(Socket resource)
Close a resource, logging an error if an error occurs.
|
static void |
safeClose(ZipFile resource)
Close a resource, logging an error if an error occurs.
|
static void |
safeShutdownReads(SuspendableReadChannel channel)
Safely shutdown reads on the given channel.
|
static long |
transfer(ReadableByteChannel source,
long count,
ByteBuffer throughBuffer,
WritableByteChannel sink)
Platform-independent channel-to-channel transfer method.
|
public static Executor directExecutor()
public static Executor nullExecutor()
public static Closeable nullCloseable()
Closeable
instance that does nothing when its close()
method is invoked.public static void safeClose(Closeable resource)
resource
- the resource to closepublic static void safeClose(Socket resource)
resource
- the resource to closepublic static void safeClose(DatagramSocket resource)
resource
- the resource to closepublic static void safeClose(Selector resource)
resource
- the resource to closepublic static void safeClose(ServerSocket resource)
resource
- the resource to closepublic static void safeClose(ZipFile resource)
resource
- the resource to closepublic static void safeClose(Handler resource)
resource
- the resource to closepublic static void safeClose(IoFuture<? extends Closeable> futureResource)
futureResource
- the resource to closepublic static IoFuture.Notifier<Object,Closeable> attachmentClosingNotifier()
public static IoFuture.Notifier<Closeable,Void> closingNotifier()
public static <T> IoFuture.Notifier<T,Void> runnableNotifier(Runnable runnable)
T
- the future type (not used)runnable
- the notifier typepublic static <T> IoFuture.Notifier<T,Result<T>> resultNotifier()
IoFuture
to the attached
Result
.T
- the result typepublic static <T extends Channel> IoFuture.Notifier<T,ChannelListener<? super T>> channelListenerNotifier()
T
- the channel typepublic static <T> Future<T> getFuture(IoFuture<T> ioFuture)
java.util.concurrent
-style Future
instance wrapper for an IoFuture
instance.ioFuture
- the IoFuture
to wrapFuture
public static void awaitAll(IoFuture<?>... futures)
futures
- the futures to wait forpublic static void awaitAllInterruptibly(IoFuture<?>... futures) throws InterruptedException
futures
- the futures to wait forInterruptedException
- if the current thread is interrupted while waitingpublic static <I,O> IoFuture<? extends O> cast(IoFuture<I> parent, Class<O> type)
IoFuture
which wraps another IoFuture
, but returns a different type.I
- the type of the original resultO
- the type of the wrapped resultparent
- the original IoFuture
type
- the class of the new IoFuture
IoFuture
public static void safeShutdownReads(SuspendableReadChannel channel)
channel
- the channelpublic static long transfer(ReadableByteChannel source, long count, ByteBuffer throughBuffer, WritableByteChannel sink) throws IOException
read
and write
operations
to move bytes from the source
channel to the sink
channel. After this call, the throughBuffer
should be checked for remaining bytes; if there are any, they should be written to the sink
channel before
proceeding. This method may be used with NIO channels, XNIO channels, or a combination of the two.
If either or both of the given channels are blocking channels, then this method may block.
source
- the source channel to read bytes fromcount
- the number of bytes to transfer (must be >= 0L
)throughBuffer
- the buffer to transfer through (must not be null
)sink
- the sink channel to write bytes toIOException
- if an I/O error occurs during the transfer of bytespublic static <T> IoFuture.Notifier<T,FutureResult<T>> getManagerNotifier()
IoFuture
's manager.T
- the channel typepublic static <T extends Channel> ChannelSource<T> getRetryingChannelSource(ChannelSource<T> delegate, int maxTries)
T
- the channel typedelegate
- the delegate channel sourcemaxTries
- the number of times to retrypublic static Cancellable closingCancellable(Closeable c)
c
- the resourcepublic static Cancellable nullCancellable()
public static Random getThreadLocalRandom()
Copyright © 2018 JBoss by Red Hat. All rights reserved.