BinaryUtils

From GreenVulcano Wiki
Revision as of 17:54, 21 December 2012 by G.dimaio (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Class FQN: it.greenvulcano.util.bin.BinaryUtils This class contains static utility methods to manage binary buffers.

BinaryUtils public static methods

/**
* Dumps the content of a byte array as a sequence of integers
* 
* @param arr
*        the array to convert
* @return the converted value
*/
public static String dumpByteArrayAsInts(byte[] arr)

/**
* Dumps the content of a byte array as a sequence of integers (Hex format)
* 
* @param arr
*        The byte array
* @return The String conversion of the buffer bytes as integer values in
*         2-Hex-digits output format
*/
public static String dumpByteArrayAsHexInts(byte[] arr)

/**
* Dumps the Hex formatted sequence as a byte array
* 
* @param hexArr
*        The 2-Hex-digits string to convert
* @return the byte array, or an empy array if input is malformed
*/
public static byte[] dumpHexIntsAsByteArray(String hexArr)

/**
* Converts sequences of characters (into an input string) representing an
* escape sequence into the corresponding escape sequences
* 
* @param input
*        the input string
* @return the converted string
*/
public static String unescapeString(String input)

/**
* This method tokenizes a given string using a given byte sequence as
* separator and returns a List containing found tokens. The
* returned List is NEVER null (it may have zero components,
* anyway).
* 
* @param theString
*        the String to be tokenized.
* @param separatorByteSequence
*        the byte sequence separator between tokens.
* @return a List containing found tokens.
*/
public static List<String> splitByByteSequenceSeparator(String theString, byte[] separatorByteSequence)

/**
* Loads the full content of a file.
* The file must be reachable via the parent classloader, or at least
* via the system classloader.
* The full content of a file is then stored into a byte array.
* 
* @param filename
*        the name of the file to be read
* @return the full content of the file, stored into a byte
*         array
* @throws IOException
*         if any I/O error occurs
*/
public static byte[] readFileAsBytesFromCP(String filename) throws IOException

/**
* Loads the full content of a file into a byte array.
* 
* @param filename
*        the name of the file to be read
* @return the full content of the file, stored into a <code>byte</code>
*         array
* @throws IOException
*         if any I/O error occurs
*/
public static byte[] readFileAsBytes(String filename) throws IOException

/**
* Loads the full content of a file into a byte array.
* 
* @param file
*        the file to be read
* @return the full content of the file, stored into a byte
*         array
* @throws IOException
*         if any I/O error occurs
*/
public static byte[] readFileAsBytes(File file) throws IOException

/**
* Reads all data from a source InputStream and stores them into
* a byte array.
* It is assumed that the source InputStream will be closed by
* the caller of this method.
* 
* @param in
*        the InputStream to read from
* @return the read bytes, stored into a byte array
* @throws IOException
*         if any I/O error occurs
*/
public static byte[] inputStreamToBytes(InputStream in) throws IOException

/**
* Reads all data from a source InputStream and stores them into
* a file on the local filesystem.
* It is assumed that the source InputStream will be closed by
* the caller of this method.
* 
* @param in
*        the InputStream to read from
* @param filename
*        the name of the file to be written to
* @throws IOException
*         if any I/O error occurs
*/
public static void inputStreamToFile(InputStream in, String filename) throws IOException

/**
* Writes the content of a byte array into a new file on the local filesystem.
* 
* @param contentArray
*        the byte array to be written to file
* @param filename
*        the name of the file to be written to
* @throws IOException
*         if any I/O error occurs
*/
public static void writeBytesToFile(byte[] contentArray, String filename) throws IOException

/**
* Writes the content of a byte array into a file on the local filesystem.
* 
* @param contentArray
*        the byte array to be written to file
* @param filename
*        the name of the file to be written to
* @param append
*        If true the data are appended to existent file
* @throws IOException
*         if any I/O error occurs
*/
public static void writeBytesToFile(byte[] contentArray, String filename, boolean append) throws IOException

/**
* Writes the content of a byte array into a new file on the local filesystem.
* 
* @param contentArray
*        the byte array to be written to file
* @param file
*        the file to be written to
* @throws IOException
*         if any I/O error occurs
*/
public static void writeBytesToFile(byte[] contentArray, File file) throws IOException

/**
* Writes the content of a byte array into a file on the local filesystem.
* 
* @param contentArray
*        the byte array to be written to file
* @param file
*        the file to be written to
* @throws IOException
*         if any I/O error occurs
*/
public static void writeBytesToFile(byte[] contentArray, File file, boolean append) throws IOException

/**
* Returns true if the passed byte value is an
* ASCII printable character, false otherwise.
* 
* @param b
*        the passed byte value
* @return true if the passed byte value is an
*         ASCII printable character, false otherwise.
*/
public static boolean isASCIIPrintableChar(byte b)