Top Description Inners Fields Constructors Methods
org.xnio

public final Class IoUtils

extends Object
Class Inheritance
Imports
java.io.Closeable, .IOException, java.net.DatagramSocket, .ServerSocket, .Socket, java.nio.ByteBuffer, java.nio.channels.ClosedChannelException, .ReadableByteChannel, .Selector, .Channel, .WritableByteChannel, java.util.Random, java.util.concurrent.CancellationException, .CountDownLatch, .ExecutionException, .Executor, .Future, .ThreadLocalRandom, .TimeUnit, .TimeoutException, java.util.zip.ZipFile, org.xnio.channels.SuspendableReadChannel, java.util.logging.Handler

General I/O utility methods.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final IoFuture.Notifier<Object, Closeable>
private static final IoFuture.Notifier<T, A>
private static final IoFuture.Notifier<Closeable, Void>
private static final IoFuture.Notifier<Object, CountDownLatch>
private static final Executor
private static final IoUtils.ManagerNotifier<T extends Channel>
private static final Cancellable
private static final Closeable
private static final Executor
private static final IoUtils.ResultNotifier<T>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static IoFuture.Notifier<Object, Closeable>

Returns:

a notifier which will close its attachment
attachmentClosingNotifier
()

Get a notifier that closes the attachment.

public static void
awaitAll(IoFuture<?>...
the futures to wait for
futures
)

Wait for all the futures to complete.

public static void
awaitAllInterruptibly(IoFuture<?>...
the futures to wait for
futures
)

Wait for all the futures to complete.

public static <
the type of the original result
I
,
the type of the wrapped result
O
>
IoFuture<? extends O>

Returns:

a wrapper IoFuture
cast
(final IoFuture<I>
the original IoFuture
parent
,
final Class<O>
the class of the new IoFuture
type
)

Create an IoFuture which wraps another IoFuture, but returns a different type.

public static <
the channel type
T extends Channel
>
IoFuture.Notifier<T, ChannelListener<? super T>>

Returns:

the notifier
channelListenerNotifier
()

Get the notifier that invokes the channel listener given as an attachment.

public static Cancellable

Returns:

the cancellable
closingCancellable
(final Closeable
the resource
c
)

A cancellable which closes the given resource on cancel.

public static IoFuture.Notifier<Closeable, Void>

Returns:

a notifier which will close the result of the operation (if successful)
closingNotifier
()

Get a notifier that closes the result.

public static Executor

Returns:

a direct executor
directExecutor
()

Get the direct executor.

public static <T> Future<T>

Returns:

a Future
getFuture
(final IoFuture<T>
the IoFuture to wrap
ioFuture
)

Get a java.util.concurrent-style Future instance wrapper for an IoFuture instance.

public static <
the channel type
T
>
IoFuture.Notifier<T, FutureResult<T>>

Returns:

the notifier
getManagerNotifier
()

Get a notifier which forwards the result to another IoFuture's manager.

public static <
the channel type
T extends Channel
>
ChannelSource<T>

Returns:

the retrying channel source
getRetryingChannelSource
(final ChannelSource<T>
the delegate channel source
delegate
,
final int
the number of times to retry
maxTries
)

A channel source which tries to acquire a channel from a delegate channel source the given number of times before giving up.

public static Random

Returns:

the thread-local RNG
getThreadLocalRandom
()

Get a thread-local RNG.

public static Cancellable

Returns:

the null cancellable
nullCancellable
()

Get the null cancellable.

public static Closeable

Returns:

the null closeable
nullCloseable
()

Get the null closeable.

public static Executor

Returns:

a null executor
nullExecutor
()

Get the null executor.

public static <
the result type
T
>
IoFuture.Notifier<T, Result<T>>

Returns:

the notifier
resultNotifier
()

Get the result notifier.

public static <
the future type (not used)
T
>
IoFuture.Notifier<T, Void>

Returns:

a notifier which will run the given command
runnableNotifier
(final Runnable
the notifier type
runnable
)

Get a notifier that runs the supplied action.

public static void
safeClose(final AutoCloseable
the resource to close
resource
)

Close a resource, logging an error if an error occurs.

public static void
safeClose(final Closeable
the resource to close
resource
)

Close a resource, logging an error if an error occurs.

public static void
safeClose(final Closeable...
the resources to close
resources
)

Close a series of resources, logging errors if they occur.

public static void
safeClose(final Socket
the resource to close
resource
)

Close a resource, logging an error if an error occurs.

public static void
safeClose(final DatagramSocket
the resource to close
resource
)

Close a resource, logging an error if an error occurs.

public static void
safeClose(final Selector
the resource to close
resource
)

Close a resource, logging an error if an error occurs.

public static void
safeClose(final ServerSocket
the resource to close
resource
)

Close a resource, logging an error if an error occurs.

public static void
safeClose(final ZipFile
the resource to close
resource
)

Close a resource, logging an error if an error occurs.

public static void
safeClose(final Handler
the resource to close
resource
)

Close a resource, logging an error if an error occurs.

public static void
safeClose(final IoFuture<? extends Closeable>
the resource to close
futureResource
)

Close a future resource, logging an error if an error occurs.

public static void
safeShutdownReads(final SuspendableReadChannel
the channel
channel
)

Safely shutdown reads on the given channel.

public static long

Returns:

the number of bytes actually transferred (possibly 0)
transfer
(final ReadableByteChannel
the source channel to read bytes from
source
,
final long
the number of bytes to transfer (must be >= 0L)
count
,
final ByteBuffer
the buffer to transfer through (must not be null)
throughBuffer
,
final WritableByteChannel
the sink channel to write bytes to
sink
)

Platform-independent channel-to-channel transfer method.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait