org.littleshoot.util
Class CommonUtils

java.lang.Object
  extended by org.littleshoot.util.CommonUtils

public class CommonUtils
extends Object

General utilities specific to LittleShoot.


Field Summary
static int FREE_RESULT_LIMIT
          The maximum number of search results for a single source for the free version.
static String LIMEWIRE_ENABLED_KEY
           
static String SEEDING_ENABLED_KEY
           
static String UPLOAD_SPEED_KEY
           
 
Method Summary
static byte[] combine(byte[]... arrays)
          Combines the specified arrays into a single array.
static byte[] combine(Collection<byte[]> arrays)
          Combines the specified arrays into a single array.
static byte[] decodeAllMessages(byte[] key, byte[] msgs)
           
static byte[] decodeBase64(String base64)
           
static byte[] decodeSingleMessage(byte[] key, byte[] msg)
           
static byte[] decodeSingleMessage(byte[] key, byte[] msg, AtomicInteger atomicOffset)
           
static byte[] encode(byte[] key, byte[] data, int off, int len)
           
static byte[] encodeSingleMessage(byte[] key, byte[] data, int off, int len)
           
static String generateBase64Key()
           
static byte[] generateKey()
           
static File getDataDir()
          Gets the directory to use for LittleShoot data.
static File getLittleShootDir()
           
static Properties getProps()
           
static File getPropsFile()
           
static byte[] intToByteArray(int value)
          Converts an int to an unsigned byte array.
static boolean isPro()
          Returns whether or not this is LittleShoot Pro.
static boolean isPropertyTrue(String key)
           
static boolean isStringTrue(String str)
           
static boolean isTrue(String varName)
           
static String nativeCall(String... commands)
          Makes a native call with the specified commands, returning the result.
static String nativeCall(String fullCommand)
          Makes a native call with a full string argument that will be parsed into separate command line tokens with white space delimiters.
static int randomPort()
           
static void saveProps(Properties props)
           
static void setProperty(String key, String value)
           
static void threadedCopy(InputStream is, OutputStream os, String threadName)
           
static String toHex(byte[] data)
           
static String toString(byte[] bytes)
           
static int unsignedShortToInt(byte[] b)
          Converts a two byte array to an integer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FREE_RESULT_LIMIT

public static final int FREE_RESULT_LIMIT
The maximum number of search results for a single source for the free version.

See Also:
Constant Field Values

LIMEWIRE_ENABLED_KEY

public static final String LIMEWIRE_ENABLED_KEY
See Also:
Constant Field Values

SEEDING_ENABLED_KEY

public static final String SEEDING_ENABLED_KEY
See Also:
Constant Field Values

UPLOAD_SPEED_KEY

public static final String UPLOAD_SPEED_KEY
See Also:
Constant Field Values
Method Detail

toString

public static String toString(byte[] bytes)

threadedCopy

public static void threadedCopy(InputStream is,
                                OutputStream os,
                                String threadName)

getDataDir

public static File getDataDir()
Gets the directory to use for LittleShoot data.

Returns:
The platform-specific LittleShoot data directory.

isPro

public static boolean isPro()
Returns whether or not this is LittleShoot Pro.

Returns:
true if we're running Pro, otherwise false

getLittleShootDir

public static File getLittleShootDir()

isTrue

public static boolean isTrue(String varName)

isPropertyTrue

public static boolean isPropertyTrue(String key)

isStringTrue

public static boolean isStringTrue(String str)

getPropsFile

public static File getPropsFile()

getProps

public static Properties getProps()

saveProps

public static void saveProps(Properties props)

setProperty

public static void setProperty(String key,
                               String value)

nativeCall

public static String nativeCall(String fullCommand)
Makes a native call with a full string argument that will be parsed into separate command line tokens with white space delimiters. If your command contains individual arguments with spaces, don't use this call.

Parameters:
fullCommand - The full command as you would write it on the command line.
Returns:
Any return values from the command.

nativeCall

public static String nativeCall(String... commands)
Makes a native call with the specified commands, returning the result.

Parameters:
commands - The commands separated into individual arguments.
Returns:
Any return values from the command.

combine

public static byte[] combine(byte[]... arrays)
Combines the specified arrays into a single array.

Parameters:
arrays - The arrays to combine.
Returns:
The combined arrays.

combine

public static byte[] combine(Collection<byte[]> arrays)
Combines the specified arrays into a single array.

Parameters:
arrays - The arrays to combine.
Returns:
The combined arrays.

encode

public static byte[] encode(byte[] key,
                            byte[] data,
                            int off,
                            int len)

encodeSingleMessage

public static byte[] encodeSingleMessage(byte[] key,
                                         byte[] data,
                                         int off,
                                         int len)

decodeAllMessages

public static byte[] decodeAllMessages(byte[] key,
                                       byte[] msgs)

decodeSingleMessage

public static byte[] decodeSingleMessage(byte[] key,
                                         byte[] msg)

decodeSingleMessage

public static byte[] decodeSingleMessage(byte[] key,
                                         byte[] msg,
                                         AtomicInteger atomicOffset)

generateKey

public static byte[] generateKey()

generateBase64Key

public static String generateBase64Key()

decodeBase64

public static byte[] decodeBase64(String base64)

toHex

public static String toHex(byte[] data)

unsignedShortToInt

public static final int unsignedShortToInt(byte[] b)
Converts a two byte array to an integer

Parameters:
b - a byte array of length 2
Returns:
an int representing the unsigned short

intToByteArray

public static final byte[] intToByteArray(int value)
Converts an int to an unsigned byte array.

Parameters:
value - The int.
Returns:
The unsigned byte array.

randomPort

public static int randomPort()


Copyright © 2011-2013 LittleShoot. All Rights Reserved.