Miscellaneous utility routines for CCN, mostly data comparison and conversion. More...
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] |
Miscellaneous utility routines for CCN, mostly data comparison and conversion.
static boolean org.ccnx.ccn.impl.support.DataUtils.arrayEquals | ( | byte[] | left, | |
byte[] | right, | |||
int | length | |||
) | [static] |
byte array compare
left | ||
right | ||
length |
static boolean org.ccnx.ccn.impl.support.DataUtils.arrayEquals | ( | byte[] | left, | |
byte[] | right | |||
) | [static] |
byte array compare
left | ||
right |
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.
array | array to search | |
byteToFind | byte to seek |
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.
array | array to search | |
startingOffset | offset into array to start at | |
byteToFind | byte to seek |
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.
arr1 | ||
arr2 | ||
count | Maximum number of bytes to inspect. |
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.
array | array to search | |
byteToFind | byte to seek |
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.
array | array to search | |
startingOffset | offset into array to start at | |
byteToFind | byte to seek |
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.
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.
left | ||
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.
directory |
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.
file |
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.
prefix | bytes to look for, if null this method always returns true. | |
data | data to inspect. If null this method always returns false. |
static String org.ccnx.ccn.impl.support.DataUtils.lineWrap | ( | String | inputString, | |
int | lineLength | |||
) | [static] |
inputString | ||
lineLength |
static byte [] org.ccnx.ccn.impl.support.DataUtils.lineWrapBase64 | ( | byte[] | input, | |
int | lineLength | |||
) | [static] |
input | ||
lineLength |
static String org.ccnx.ccn.impl.support.DataUtils.printBytes | ( | byte[] | bytes | ) | [static] |
Used to print non ASCII components for logging, etc.
bytes |
static String org.ccnx.ccn.impl.support.DataUtils.printHexBytes | ( | byte[] | bytes | ) | [static] |
Used to print components to be interpreted as hexadecimal such as segments.
bytes |