net.tomp2p.utils
Class Utils

java.lang.Object
  extended by net.tomp2p.utils.Utils

public class Utils
extends Object


Constructor Summary
Utils()
           
 
Method Summary
static void addReleaseListener(BaseFuture baseFuture, ConnectionReservation connectionReservation, ChannelCreator cc, int nr)
           
static void addReleaseListenerAll(BaseFuture baseFuture, ConnectionReservation connectionReservation, ChannelCreator channelCreator)
           
static void bestEffortclose(Closeable... closables)
           
static int byteArrayToInt(byte[] b)
           
static boolean checkEntryProtection(Map<Number160,Data> dataMap)
           
static byte[] compress(byte[] input)
           
static Collection<Number160> convert(Collection<TrackerData> a)
           
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(org.jboss.netty.buffer.ChannelBuffer channelBuffer)
           
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 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 byte[] intToByteArray(int value)
           
static
<K> Collection<K>
limit(Collection<K> a, int size)
           
static
<K,V> Map<K,V>
limit(Map<K,V> a, int i)
           
static Map<Number160,TrackerData> limitRandom(Map<Number160,TrackerData> activePeers, int trackerSize)
           
static ByteBuffer loadFile(File file)
           
static Number160 makeSHAHash(byte[] buffer)
           
static Number160 makeSHAHash(byte[] buffer, int offset, int length)
           
static Number160 makeSHAHash(ByteBuffer buffer)
           
static Number160 makeSHAHash(File file)
           
static Number160 makeSHAHash(String strInput)
           
static void nullCheck(Object... objects)
           
static boolean nullCheckRetVal(Object... objects)
           
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
<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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

loadFile

public static ByteBuffer loadFile(File file)
                           throws IOException
Throws:
IOException

makeSHAHash

public static Number160 makeSHAHash(File file)

makeSHAHash

public static Number160 makeSHAHash(String strInput)

makeSHAHash

public static Number160 makeSHAHash(ByteBuffer buffer)

makeSHAHash

public static Number160 makeSHAHash(byte[] buffer)

makeSHAHash

public static Number160 makeSHAHash(byte[] buffer,
                                    int offset,
                                    int length)

createRandomNodeID

public static Number160 createRandomNodeID()

compress

public static byte[] compress(byte[] input)

uncompress

public static byte[] uncompress(byte[] compressedData,
                                int offset,
                                int length)

uncompress

public static byte[] uncompress(byte[] compressedData)

encodeJavaObject

public static byte[] encodeJavaObject(Object attachement)
                               throws IOException
Throws:
IOException

decodeJavaObject

public static Object decodeJavaObject(org.jboss.netty.buffer.ChannelBuffer channelBuffer)
                               throws ClassNotFoundException,
                                      IOException
Throws:
ClassNotFoundException
IOException

decodeJavaObject

public static Object decodeJavaObject(byte[] me,
                                      int offset,
                                      int length)
                               throws ClassNotFoundException,
                                      IOException
Throws:
ClassNotFoundException
IOException

difference

public static <K> Collection<K> difference(Collection<K> collection1,
                                           Collection<K> result,
                                           Collection<K> collection2)
Stores the differences of two collections in a result collection. The result will contain items from collection1 without those items that are in collection2.

Parameters:
collection1 - The first collection (master collection) that will be iterated and checked against duplicates in collection2.
result - The collection to store the result
collection2 - The second collection that will be searched for duplicates
Returns:
Returns the collection the user specified as the resulting collection

difference

public static <K> Collection<K> difference(Collection<K> collection1,
                                           Collection<K> result,
                                           Collection<K>... collections2)
Stores the differences of multiple collections in a result collection. The result will contain items from collection1 without those items that are in collections2. The calling method might need to provide a

Parameters:
collection1 - The first collection (master collection) that will be iterated and checked against duplicates in collection2.
result - The collection to store the result
collection2 - The second collections that will be searched for duplicates
Returns:
Returns the collection the user specified as the resulting collection

bestEffortclose

public static void bestEffortclose(Closeable... closables)

intToByteArray

public static final byte[] intToByteArray(int value)

byteArrayToInt

public static final int byteArrayToInt(byte[] b)

pollRandom

public static <K> K pollRandom(Collection<K> collection,
                               Random rnd)
Returns a random element from a collection. This method is pretty slow O(n), but the Java collection framework does not offer a better solution. This method puts the collection into a List and fetches a random element using List.get(int).

Parameters:
collection - The collection from which we want to pick a random element
rnd - The random object
Returns:
A random element

pollRandomKey

public static <K,V> Map.Entry<K,V> pollRandomKey(Map<K,V> queueToAsk,
                                                 Random rnd)

subtract

public static <K> Collection<K> subtract(Collection<K> a,
                                         Collection<K> b)

subtract

public static <K,V> Map<K,V> subtract(Map<K,V> a,
                                      Collection<K> b)

disjunction

public static <K,V> Map<K,V> disjunction(Map<K,V> a,
                                         Collection<K> b)

limit

public static <K> Collection<K> limit(Collection<K> a,
                                      int size)

limit

public static <K,V> Map<K,V> limit(Map<K,V> a,
                                   int i)

convert

public static Collection<Number160> convert(Collection<TrackerData> a)

debugArray

public static String debugArray(byte[] array,
                                int offset,
                                int length)

debugArray

public static String debugArray(byte[] array)

checkEntryProtection

public static boolean checkEntryProtection(Map<Number160,Data> dataMap)

addReleaseListener

public static void addReleaseListener(BaseFuture baseFuture,
                                      ConnectionReservation connectionReservation,
                                      ChannelCreator cc,
                                      int nr)

addReleaseListenerAll

public static void addReleaseListenerAll(BaseFuture baseFuture,
                                         ConnectionReservation connectionReservation,
                                         ChannelCreator channelCreator)

limitRandom

public static Map<Number160,TrackerData> limitRandom(Map<Number160,TrackerData> activePeers,
                                                     int trackerSize)

getLast

public static <K> K getLast(List<K> list)

fromInteger

public static Inet4Address fromInteger(int address)
Returns an Inet4Address having the integer value specified by the argument.

Parameters:
address - int, the 32bit integer address to be converted
Returns:
Inet4Address equivalent of the argument

createTempDir

public static File createTempDir()
                          throws IOException
Throws:
IOException

nullCheck

public static void nullCheck(Object... objects)

nullCheckRetVal

public static boolean nullCheckRetVal(Object... objects)

extractContentKeys

public static Collection<Number160> extractContentKeys(Collection<Number480> collection)


Copyright © 2013. All Rights Reserved.