public class Utils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static java.lang.ThreadLocal<java.security.SecureRandom> |
random |
| Modifier | Constructor and Description |
|---|---|
private |
Utils() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
bytes(java.nio.ByteBuffer buf) |
static void |
checkArgument(boolean expression,
java.lang.String errorMessage) |
static void |
checkArgument(boolean expression,
Supplier<java.lang.String> errorMessage) |
static boolean |
delete(java.io.File path) |
static java.lang.String |
dump(java.nio.ByteBuffer buffer,
int pos,
int limit) |
static int |
findOpenPort() |
static Address |
getLocalIpAddress(java.nio.channels.SocketChannel fd)
Resolve the local address of the channel.
|
static Address |
getPeerIpAddress(java.nio.channels.SocketChannel fd)
Resolve the remote address of the channel.
|
static byte[] |
randomBytes(int length) |
static int |
randomInt() |
static int |
randomInt(int bound) |
static byte[] |
realloc(byte[] src,
int size) |
static <T> T[] |
realloc(java.lang.Class<T> klass,
T[] src,
int size,
boolean ended) |
static void |
unblockSocket(java.nio.channels.SelectableChannel... channels) |
static java.lang.String |
unhash(int port)
Finds a string whose hashcode is the number in input.
|
private static java.lang.StringBuilder |
unhash(java.lang.StringBuilder builder,
int port,
char boundary) |
public static int randomInt()
public static int randomInt(int bound)
public static byte[] randomBytes(int length)
public static java.lang.String unhash(int port)
port - the port to find String hashcode-equivalent of. Has to be positive or 0.private static java.lang.StringBuilder unhash(java.lang.StringBuilder builder,
int port,
char boundary)
public static int findOpenPort()
throws java.io.IOException
java.io.IOExceptionpublic static void unblockSocket(java.nio.channels.SelectableChannel... channels)
throws java.io.IOException
java.io.IOExceptionpublic static <T> T[] realloc(java.lang.Class<T> klass,
T[] src,
int size,
boolean ended)
public static byte[] bytes(java.nio.ByteBuffer buf)
public static byte[] realloc(byte[] src,
int size)
public static boolean delete(java.io.File path)
public static Address getPeerIpAddress(java.nio.channels.SocketChannel fd)
fd - the channel, should be a TCP socket channelAddressZError.IOException - if the channel is closed or an I/O errors occurredjava.lang.IllegalArgumentException - if the SocketChannel is not a TCP channelpublic static Address getLocalIpAddress(java.nio.channels.SocketChannel fd)
fd - the channel, should be a TCP socket channelAddressZError.IOException - if the channel is closed or an I/O errors occurredjava.lang.IllegalArgumentException - if the SocketChannel is not a TCP channelpublic static java.lang.String dump(java.nio.ByteBuffer buffer,
int pos,
int limit)
public static void checkArgument(boolean expression,
java.lang.String errorMessage)
public static void checkArgument(boolean expression,
Supplier<java.lang.String> errorMessage)