public class Utils extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
BYTE_BITS |
static int |
BYTE_BYTE_SIZE |
static byte[] |
EMPTY_BYTE_ARRAY |
static int |
INTEGER_BYTE_SIZE |
static int |
IPV4_BYTES |
static int |
IPV6_BYTES |
static int |
LONG_BYTE_SIZE |
static int |
MASK_0F |
static int |
MASK_80 |
static int |
MASK_FF |
static int |
SHORT_BYTE_SIZE |
| Constructor and Description |
|---|
Utils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addReleaseListener(ChannelCreator channelCreator,
BaseFuture... baseFutures)
Adds a listener to the response future and releases all aquired channels in channel creator.
|
static void |
addReleaseListener(FutureChannelCreator fcc,
BaseFuture baseFuture) |
static void |
bestEffortclose(Closeable... closables) |
static int |
byteArrayToInt(byte[] b) |
static byte[] |
compress(byte[] input) |
static BitSet |
createBitSet(byte b)
Convert a byte to a bit set.
|
static byte |
createByte(BitSet bitSet)
Convert a BitSet to a byte.
|
static InputStream |
createInputStream(ByteBuffer buf) |
static Number160 |
createRandomNodeID() |
static File |
createTempDir() |
static String |
debugArray(byte[] array) |
static String |
debugArray(byte[] array,
int offset,
int length) |
static Object |
decodeJavaObject(byte[] me,
int offset,
int length) |
static Object |
decodeJavaObject(io.netty.buffer.ByteBuf channelBuffer) |
static Object |
decodeJavaObject(DataBuffer dataBuffer) |
static <K> Collection<K> |
difference(Collection<K> collection1,
Collection<K> result,
Collection<K>... collections2)
Stores the differences of multiple collections in a result collection.
|
static <K> Collection<K> |
difference(Collection<K> collection1,
Collection<K> result,
Collection<K> collection2)
Stores the differences of two collections in a result collection.
|
static <K,V> Map<K,V> |
disjunction(Map<K,V> a,
Collection<K> b) |
static byte[] |
encodeJavaObject(Object attachement) |
static boolean |
equals(Object a,
Object b) |
static Collection<Number160> |
extractContentKeys(Collection<Number480> collection) |
static Inet4Address |
fromInteger(int address)
Returns an Inet4Address having the integer value specified by the argument.
|
static <K> K |
getLast(List<K> list) |
static String |
hash(PublicKey publicKey) |
static InetAddress |
inet4FromBytes(byte[] src,
int offset)
Converts a byte array to a Inet4Address.
|
static InetAddress |
inet6FromBytes(byte[] me,
int offset)
Converts a byte array to a Inet6Address.
|
static byte[] |
intToByteArray(int value) |
static <T> boolean |
isSameSets(Collection<T> set1,
Collection<T> set2)
Compares if two sets have the exact same elements.
|
static <K> Collection<K> |
limit(Collection<K> a,
int size) |
static <K,V> Map<K,V> |
limit(Map<K,V> a,
int i) |
static TrackerData |
limitRandom(TrackerData activePeers,
int trackerSize) |
static ByteBuffer |
loadFile(File file) |
static byte[] |
makeMD5Hash(byte[] buffer)
It returns MD5 hash for the buffer.
|
static byte[] |
makeMD5Hash(byte[] buffer,
int offset,
int length) |
static Number160 |
makeSHAHash(byte[] buffer) |
static Number160 |
makeSHAHash(byte[] buffer,
int offset,
int length) |
static Number160 |
makeSHAHash(io.netty.buffer.ByteBuf buf)
Calculates the SHA-1 hash of the Netty byte buffer.
|
static Number160 |
makeSHAHash(ByteBuffer buffer) |
static Number160 |
makeSHAHash(DataBuffer buffer) |
static Number160 |
makeSHAHash(File file) |
static Number160 |
makeSHAHash(String strInput) |
static InetSocketAddress |
natReflection(InetSocketAddress recipient,
boolean udp,
PeerAddress self) |
static void |
nullCheck(Object... objects) |
static boolean |
nullCheckRetVal(Object... objects) |
static <K> K |
peekRandom(Collection<K> collection,
Random rnd) |
static <K> K |
pollRandom(Collection<K> collection,
Random rnd)
Returns a random element from a collection.
|
static <K,V> Map.Entry<K,V> |
pollRandomKey(Map<K,V> queueToAsk,
Random rnd) |
static int |
randomPositiveInt(int upperBound)
This method returns a random positve
int within a given upper limit. |
static Map<Number640,Byte> |
setMapError(Map<Number640,?> dataMap,
byte reason) |
static <K> Collection<K> |
subtract(Collection<K> a,
Collection<K> b) |
static <K,V> Map<K,V> |
subtract(Map<K,V> a,
Collection<K> b) |
static byte[] |
uncompress(byte[] compressedData) |
static byte[] |
uncompress(byte[] compressedData,
int offset,
int length) |
public static final int IPV4_BYTES
public static final int IPV6_BYTES
public static final int BYTE_BITS
public static final int MASK_0F
public static final int MASK_80
public static final int MASK_FF
public static final int BYTE_BYTE_SIZE
public static final int SHORT_BYTE_SIZE
public static final int INTEGER_BYTE_SIZE
public static final int LONG_BYTE_SIZE
public static final byte[] EMPTY_BYTE_ARRAY
public static ByteBuffer loadFile(File file) throws IOException
IOExceptionpublic static Number160 makeSHAHash(ByteBuffer buffer)
public static Number160 makeSHAHash(io.netty.buffer.ByteBuf buf)
buffer - The buffer that stores datapublic static Number160 makeSHAHash(DataBuffer buffer)
public static Number160 makeSHAHash(byte[] buffer)
public static Number160 makeSHAHash(byte[] buffer, int offset, int length)
public static byte[] makeMD5Hash(byte[] buffer)
buffer - The buffer to generate the checksum frompublic static byte[] makeMD5Hash(byte[] buffer,
int offset,
int length)
public static Number160 createRandomNodeID()
public static byte[] compress(byte[] input)
public static byte[] uncompress(byte[] compressedData,
int offset,
int length)
public static byte[] uncompress(byte[] compressedData)
public static byte[] encodeJavaObject(Object attachement) throws IOException
IOExceptionpublic static Object decodeJavaObject(io.netty.buffer.ByteBuf channelBuffer) throws ClassNotFoundException, IOException
ClassNotFoundExceptionIOExceptionpublic static Object decodeJavaObject(DataBuffer dataBuffer) throws ClassNotFoundException, IOException
ClassNotFoundExceptionIOExceptionpublic static InputStream createInputStream(ByteBuffer buf)
public static Object decodeJavaObject(byte[] me, int offset, int length) throws ClassNotFoundException, IOException
ClassNotFoundExceptionIOExceptionpublic static <K> Collection<K> difference(Collection<K> collection1, Collection<K> result, Collection<K> collection2)
collection1 - The first collection (master collection) that will be iterated and checked against duplicates in
collection2.result - The collection to store the resultcollection2 - The second collection that will be searched for duplicates@SafeVarargs public static <K> Collection<K> difference(Collection<K> collection1, Collection<K> result, Collection<K>... collections2)
collection1 - The first collection (master collection) that will be iterated and checked against duplicates in
collection2.result - The collection to store the resultcollection2 - The second collections that will be searched for duplicatespublic static void bestEffortclose(Closeable... closables)
public static final byte[] intToByteArray(int value)
public static final int byteArrayToInt(byte[] b)
public static <K> K pollRandom(Collection<K> collection, Random rnd)
List and fetches a random
element using List.get(int).collection - The collection from which we want to pick a random elementrnd - The random objectpublic static <K> K peekRandom(Collection<K> collection, Random rnd)
public static <K> Collection<K> subtract(Collection<K> a, Collection<K> b)
public static <K,V> Map<K,V> subtract(Map<K,V> a, Collection<K> b)
public static <K,V> Map<K,V> disjunction(Map<K,V> a, Collection<K> b)
public static <K> Collection<K> limit(Collection<K> a, int size)
public static String debugArray(byte[] array, int offset, int length)
public static String debugArray(byte[] array)
public static TrackerData limitRandom(TrackerData activePeers, int trackerSize)
public static <K> K getLast(List<K> list)
public static Inet4Address fromInteger(int address)
address - int, the 32bit integer address to be convertedInet4Address equivalent of the argumentpublic static File createTempDir() throws IOException
IOExceptionpublic static void nullCheck(Object... objects)
public static boolean nullCheckRetVal(Object... objects)
public static Collection<Number160> extractContentKeys(Collection<Number480> collection)
public static InetAddress inet4FromBytes(byte[] src, int offset)
me - the byte arrayoffset - where to start in the byte arrayIndexOutOfBoundsException - if copying would cause access of data outside array bounds for src.NullPointerException - if either src is null.public static InetAddress inet6FromBytes(byte[] me, int offset)
me - me the byte arrayoffset - where to start in the byte arrayIndexOutOfBoundsException - if copying would cause access of data outside array bounds for src.NullPointerException - if either src is null.public static BitSet createBitSet(byte b)
b - The byte to be convertedpublic static byte createByte(BitSet bitSet)
bitSet - The bit setpublic static void addReleaseListener(ChannelCreator channelCreator, BaseFuture... baseFutures)
channelCreator - The channel creator that will be shutdown and all connections will be closedbaseFutures - The futures to listen to. If all the futures finished, then the channel creator is shutdown. If null
provided, the channel creator is shutdown immediately.public static void addReleaseListener(FutureChannelCreator fcc, BaseFuture baseFuture)
public static <T> boolean isSameSets(Collection<T> set1, Collection<T> set2)
T - Type of the collectionset1 - The first setset2 - The second setpublic static int randomPositiveInt(int upperBound)
int within a given upper limit.upperBound - public static InetSocketAddress natReflection(InetSocketAddress recipient, boolean udp, PeerAddress self)
Copyright © 2014. All rights reserved.