BinaryUtils

From GreenVulcano Wiki
Revision as of 09:14, 18 December 2012 by Anonymous (talk) (Created page with "Class FQN: '''it.greenvulcano.util.bin.BinaryUtils''' ==Following the BinaryUtils public static methods== <syntaxhighlight lang="java5"> /** * Dumps the content of a byte array...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Class FQN: it.greenvulcano.util.bin.BinaryUtils

Following the 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)

/**
* Convert 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 <tt>List</tt> containing found tokens. The
* returned <tt>List</tt> is NEVER null (it may have zero components,
* anyway).
* 
* @param theString
*        the <tt>String</tt> to be tokenized.
* @param separatorByteSequence
*        the byte sequence separator between tokens.
* @return a <tt>List</tt> containing found tokens.
*/
public static List<String> splitByByteSequenceSeparator(String theString, byte[] separatorByteSequence)

/**
* Loads the full content of a file.<br>
* The file must be reachable via the <i>parent classloader</i>, or at least
* via the <i>system classloader</i>.<br>
* The full content of a file is then stored into a <code>byte</code> array.<br>
* 
* @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[] readFileAsBytesFromCP(String filename) throws IOException

/**
* Loads the full content of a file into a <code>byte</code> array.<br>
* 
* @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 <code>byte</code> array.<br>
* 
* @param file
*        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(File file) throws IOException

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

/**
* Read all data from a source <code>InputStream</code> and stores them into
* a file on the local filesystem.<br>
* It is assumed that the source <code>InputStream</code> will be closed by
* the caller of this method.
* 
* @param in
*        the <code>InputStream</code> 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

/**
* Write the content of a <code>byte</code> array into a new file on the
* local filesystem.
* 
* @param contentArray
*        the <code>byte</code> 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

/**
* Write the content of a <code>byte</code> array into a file on the local
* filesystem.
* 
* @param contentArray
*        the <code>byte</code> 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

/**
* Write the content of a <code>byte</code> array into a new file on the
* local filesystem.
* 
* @param contentArray
*        the <code>byte</code> 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

/**
* Write the content of a <code>byte</code> array into a file on the local
* filesystem.
* 
* @param contentArray
*        the <code>byte</code> 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 <code>true</code> if the passed <code>byte</code> value is an
* ASCII printable character, <code>false</code> otherwise.
* 
* @param b
*        the passed <code>byte</code> value
* @return <code>true</code> if the passed <code>byte</code> value is an
*         ASCII printable character, <code>false</code> otherwise.
*/
public static boolean isASCIIPrintableChar(byte b)