org.ccnx.ccn.impl.support.DataUtils Class Reference

Miscellaneous utility routines for CCN, mostly data comparison and conversion. More...

List of all members.

Static Public Member Functions

static< TextendsComparable< T > int compare (T left, T right)
static int compare (byte[] left, byte[] right)
 Perform a shortlex comparison of byte arrays in canonical CCN ordering.
static int compare (ArrayList< byte[]> left, ArrayList< byte[]> right)
 This is not like compare(byte[], byte[]).
static String printBytes (byte[] bytes)
 Used to print non ASCII components for logging, etc.
static String printHexBytes (byte[] bytes)
 Used to print components to be interpreted as hexadecimal such as segments.
static byte[] base64Decode (byte[] input) throws IOException
 A place to centralize interfaces to base64 encoding/decoding, as the classes we use change depending on what ships with Java.
static byte[] base64Encode (byte[] input)
static String base64Encode (byte[] input, Integer lineLength)
static byte[] lineWrapBase64 (byte[] input, int lineLength)
static String lineWrap (String inputString, int lineLength)
static boolean arrayEquals (byte[] left, byte[] right)
 byte array compare
static boolean arrayEquals (byte[] left, byte[] right, int length)
 byte array compare
static boolean isBinaryPrefix (byte[] prefix, byte[] data)
 Check if a byte array starts with a certain prefix.
static void deleteDirectory (File directory) throws IOException
 Recursively delete a directory and all its contents.
static byte[] getBytesFromFile (File file) throws IOException
 This was used in early content demos; keep it around as it may be generally useful.
static byte[] getBytesFromStream (InputStream input) throws IOException
 Read a stream (usually small) completely in to a byte array.
static String getUTF8StringFromBytes (byte[] stringBytes)
 Wrap up handling of UTF-8 encoding in one place (as much as possible), because an UnsupportedEncodingException in response to a request for UTF-8 signals a significant configuration error; we should catch it and signal a RuntimeException in one place and let the rest of the code not worry about it.
static byte[] getBytesFromUTF8String (String stringData)
 Wrap up handling of UTF-8 encoding in one place (as much as possible), because an UnsupportedEncodingException in response to a request for UTF-8 signals a significant configuration error; we should catch it and signal a RuntimeException in one place and let the rest of the code not worry about it.
static int bytencmp (byte[] arr1, int offset1, byte[] arr2, int offset2, int count)
 Lexicographically compare two byte arrays, looking at a limited number of bytes.
static int bytencmp (byte[] arr1, byte[] arr2, int count)
static int byteindex (byte[] array, int startingOffset, byte byteToFind)
 Finds the index of the first occurrence of byteToFind in array starting at given offset, returns 01 if not found.
static int byteindex (byte[] array, byte byteToFind)
 Finds the index of the first occurrence of byteToFind in array, returns -1 if not found.
static int byterindex (byte[] array, int startingOffset, byte byteToFind)
 Finds the index of the last occurrence of byteToFind in array starting at given offset, returns -1 if not found.
static int byterindex (byte[] array, byte byteToFind)
 Finds the last of the first occurrence of byteToFind in array, returns -1 if not found.
static int occurcount (byte[] array, int startingOffset, int length, byte byteToFind)
 Count how may times a given byte occurs in an array.
static int occurcount (byte[] array, int length, byte byteToFind)
static int occurcount (byte[] array, byte byteToFind)
static byte[][] binarySplit (byte[] array, int startingOffset, byte splitValue)
 Akin to String.split for binary arrays; splits on a given byte value.
static byte[][] binarySplit (byte[] array, byte splitValue)
static byte[] subarray (byte[] array, int offset, int len)

Static Public Attributes

static final int BITS_PER_BYTE = 8
static final String EMPTY = ""
static final String LINE_SEPARATOR = System.getProperty("line.separator")
static Charset UTF8_CHARSET
 Useful when we move over to 1.6, and can avoid UnsupportedCharsetExceptions this way.
static final int LINELEN = 64

Static Package Functions

 [static initializer]

Detailed Description

Miscellaneous utility routines for CCN, mostly data comparison and conversion.


Member Function Documentation

static boolean org.ccnx.ccn.impl.support.DataUtils.arrayEquals ( byte[]  left,
byte[]  right,
int  length 
) [static]

byte array compare

Parameters:
left 
right 
length 
Returns:
true if equal
static boolean org.ccnx.ccn.impl.support.DataUtils.arrayEquals ( byte[]  left,
byte[]  right 
) [static]

byte array compare

Parameters:
left 
right 
Returns:
true if equal
static int org.ccnx.ccn.impl.support.DataUtils.byteindex ( byte[]  array,
byte  byteToFind 
) [static]

Finds the index of the first occurrence of byteToFind in array, returns -1 if not found.

Parameters:
array array to search
byteToFind byte to seek
Returns:
position in array containing first occurrence of byteToFind, or array.length if not found
static int org.ccnx.ccn.impl.support.DataUtils.byteindex ( byte[]  array,
int  startingOffset,
byte  byteToFind 
) [static]

Finds the index of the first occurrence of byteToFind in array starting at given offset, returns 01 if not found.

Parameters:
array array to search
startingOffset offset into array to start at
byteToFind byte to seek
Returns:
position in array containing first occurrence of byteToFind, or array.length if not found
static int org.ccnx.ccn.impl.support.DataUtils.bytencmp ( byte[]  arr1,
int  offset1,
byte[]  arr2,
int  offset2,
int  count 
) [static]

Lexicographically compare two byte arrays, looking at a limited number of bytes.

Parameters:
arr1 
arr2 
count Maximum number of bytes to inspect.
Returns:
< 0 if left comes before right, 0 if they are equal, > 0 if left comes after right
static int org.ccnx.ccn.impl.support.DataUtils.byterindex ( byte[]  array,
byte  byteToFind 
) [static]

Finds the last of the first occurrence of byteToFind in array, returns -1 if not found.

Parameters:
array array to search
byteToFind byte to seek
Returns:
position in array containing first occurrence of byteToFind, or array.length if not found
static int org.ccnx.ccn.impl.support.DataUtils.byterindex ( byte[]  array,
int  startingOffset,
byte  byteToFind 
) [static]

Finds the index of the last occurrence of byteToFind in array starting at given offset, returns -1 if not found.

Parameters:
array array to search
startingOffset offset into array to start at
byteToFind byte to seek
Returns:
position in array containing first occurrence of byteToFind, or array.length if not found
static int org.ccnx.ccn.impl.support.DataUtils.compare ( ArrayList< byte[]>  left,
ArrayList< byte[]>  right 
) [static]

This is not like compare(byte[], byte[]).

That is shortlex. This is an actual lexigraphic ordering based on the shortlex compare of each byte array.

See also:
compare(byte[], byte[])
static int org.ccnx.ccn.impl.support.DataUtils.compare ( byte[]  left,
byte[]  right 
) [static]

Perform a shortlex comparison of byte arrays in canonical CCN ordering.

Shortlex ordering is ordering by cardinality, then by lexigraphic.

MM - This method should really be renamed to "shortlex" or something other than "compare", unless it is needed for an Override name.

Parameters:
left 
right 
Returns:
< 0 if left comes before right, 0 if they are equal, > 0 if left comes after right
static void org.ccnx.ccn.impl.support.DataUtils.deleteDirectory ( File  directory  )  throws IOException [static]

Recursively delete a directory and all its contents.

If given File does not exist, this method returns with no error but if it exists as a file not a directory, an exception will be thrown. Similar to org.apache.commons.io.FileUtils.deleteDirectory but avoids dependency on that library for minimal use.

Parameters:
directory 
Exceptions:
IOException if "directory" is a file
static byte [] org.ccnx.ccn.impl.support.DataUtils.getBytesFromFile ( File  file  )  throws IOException [static]

This was used in early content demos; keep it around as it may be generally useful.

Parameters:
file 
Returns:
Exceptions:
IOException 
static byte [] org.ccnx.ccn.impl.support.DataUtils.getBytesFromStream ( InputStream  input  )  throws IOException [static]

Read a stream (usually small) completely in to a byte array.

Used to get all of the bytes out of one or more content objects for decoding or other processing, where the content needs to be handed to something else as a unit.

static boolean org.ccnx.ccn.impl.support.DataUtils.isBinaryPrefix ( byte[]  prefix,
byte[]  data 
) [static]

Check if a byte array starts with a certain prefix.

Used to check for binary prefixes used to mark certain ContentName components for special purposes.

Parameters:
prefix bytes to look for, if null this method always returns true.
data data to inspect. If null this method always returns false.
Returns:
true if data starts with prefix.
static String org.ccnx.ccn.impl.support.DataUtils.lineWrap ( String  inputString,
int  lineLength 
) [static]
Parameters:
inputString 
lineLength 
Returns:
static byte [] org.ccnx.ccn.impl.support.DataUtils.lineWrapBase64 ( byte[]  input,
int  lineLength 
) [static]
Deprecated:
not used in CCNx, candidate for removal in future release.
Parameters:
input 
lineLength 
Returns:
the byte array with added CRLF line-breaks and null termination.
static String org.ccnx.ccn.impl.support.DataUtils.printBytes ( byte[]  bytes  )  [static]

Used to print non ASCII components for logging, etc.

Parameters:
bytes 
Returns:
the data as a BigInteger String
static String org.ccnx.ccn.impl.support.DataUtils.printHexBytes ( byte[]  bytes  )  [static]

Used to print components to be interpreted as hexadecimal such as segments.

Parameters:
bytes 
Returns:
the data as a Hexadecimal String

The documentation for this class was generated from the following file:
Generated on Fri May 13 16:27:43 2011 for Content-Centric Networking in Java by  doxygen 1.6.3