org.rhq.enterprise.communications.util
Class DumpBytes

java.lang.Object
  extended by org.rhq.enterprise.communications.util.DumpBytes

public class DumpBytes
extends Object

Dumps hexadecimal, decimal, octal and binary representations of any given File, String or byte array. For example, the different representations for the string "helloworld" will show:

Hexadecimal:

 68 65 6c 6c 6f 77 6f 72 6c 64   helloworld
 

Decimal:

 104 101 108 108 111 119 111 114   hellowor
 108 100                           ld
 

Octal:

 150   145   154   154   157   167   hellow
 157   162   154   144               orld
 

Binary:

 1101000  1100101  1101100  1101100  1101111   hello
 1110111  1101111  1110010  1101100  1100100   world
 

Author:
John Mazzitelli

Field Summary
static int BASE_BIN
          Binary base (2).
static int BASE_DEC
          Decimal base (10).
static int BASE_HEX
          Hexadecimal base (16).
static int BASE_OCT
          Octal base (8).
 
Constructor Summary
DumpBytes()
           
 
Method Summary
static String dumpBinData(byte[] data)
          Converts the given byte array to binary format.
static String dumpBinData(File f)
          Converts the contents of the given File to binary format.
static String dumpBinData(String data)
          Converts the given String to binary format.
static String dumpData(byte[] bytes, int cols, int format)
          Converts the given byte array to a numerical format representation.
static String dumpData(File file, int cols, int format)
          Reads the given File and converts its contents to a numerical format representation.
static String dumpData(String data, int cols, int format)
          Converts the given String to a numerical format representation.
static String dumpDecData(byte[] data)
          Converts the given byte array to decimal format.
static String dumpDecData(File f)
          Converts the contents of the given File to decimal format.
static String dumpDecData(String data)
          Converts the given String to decimal format.
static String dumpHexData(byte[] data)
          Converts the given byte array to hexadecimal format.
static String dumpHexData(File f)
          Converts the contents of the given File to hexadecimal format.
static String dumpHexData(String data)
          Converts the given String to hexadecimal format.
static String dumpOctData(byte[] data)
          Converts the given byte array to octal format.
static String dumpOctData(File f)
          Converts the contents of the given File to octal format.
static String dumpOctData(String data)
          Converts the given String to octal format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BASE_HEX

public static final int BASE_HEX
Hexadecimal base (16).

See Also:
Constant Field Values

BASE_DEC

public static final int BASE_DEC
Decimal base (10).

See Also:
Constant Field Values

BASE_OCT

public static final int BASE_OCT
Octal base (8).

See Also:
Constant Field Values

BASE_BIN

public static final int BASE_BIN
Binary base (2).

See Also:
Constant Field Values
Constructor Detail

DumpBytes

public DumpBytes()
Method Detail

dumpData

public static String dumpData(byte[] bytes,
                              int cols,
                              int format)
Converts the given byte array to a numerical format representation.

Parameters:
bytes - data to be converted to a particular numerical format
cols - number of columns the output data will have
format - numerical base the output will be shown as - e.g. BASE_HEX is hex
Returns:
formatted representation of the given byte array.
Throws:
IllegalArgumentException - if format is invalid

dumpData

public static String dumpData(String data,
                              int cols,
                              int format)
Converts the given String to a numerical format representation.

Parameters:
data - String to be converted to a particular numerical format
cols - number of columns the output data will have
format - numerical base the output will be shown as (e.g. 16 is hex)
Returns:
Formatted representation of the given String.

dumpData

public static String dumpData(File file,
                              int cols,
                              int format)
Reads the given File and converts its contents to a numerical format representation.

Parameters:
file - File whose contents are to be converted to a particular numerical format
cols - number of columns the output data will have
format - numerical base the output will be shown as (e.g. 16 is hex)
Returns:
formatted representation of the given String or null if the file was not readable.

dumpBinData

public static String dumpBinData(File f)
Converts the contents of the given File to binary format.

Parameters:
f - file whose contents is to be converted
Returns:
Formatted representation of the file contents

dumpBinData

public static String dumpBinData(byte[] data)
Converts the given byte array to binary format.

Parameters:
data - byte array to be converted
Returns:
Formatted representation of data

dumpBinData

public static String dumpBinData(String data)
Converts the given String to binary format.

Parameters:
data - String to be converted
Returns:
Formatted representation of data

dumpOctData

public static String dumpOctData(File f)
Converts the contents of the given File to octal format.

Parameters:
f - file whose contents is to be converted
Returns:
Formatted representation of the file contents

dumpOctData

public static String dumpOctData(byte[] data)
Converts the given byte array to octal format.

Parameters:
data - byte array to be converted
Returns:
Formatted representation of data

dumpOctData

public static String dumpOctData(String data)
Converts the given String to octal format.

Parameters:
data - String to be converted
Returns:
Formatted representation of data

dumpDecData

public static String dumpDecData(File f)
Converts the contents of the given File to decimal format.

Parameters:
f - file whose contents is to be converted
Returns:
Formatted representation of the file contents

dumpDecData

public static String dumpDecData(byte[] data)
Converts the given byte array to decimal format.

Parameters:
data - byte array to be converted
Returns:
Formatted representation of data

dumpDecData

public static String dumpDecData(String data)
Converts the given String to decimal format.

Parameters:
data - String to be converted
Returns:
Formatted representation of data

dumpHexData

public static String dumpHexData(File f)
Converts the contents of the given File to hexadecimal format.

Parameters:
f - file whose contents is to be converted
Returns:
Formatted representation of the file contents

dumpHexData

public static String dumpHexData(byte[] data)
Converts the given byte array to hexadecimal format.

Parameters:
data - byte array to be converted
Returns:
Formatted representation of data

dumpHexData

public static String dumpHexData(String data)
Converts the given String to hexadecimal format.

Parameters:
data - String to be converted
Returns:
Formatted representation of data


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.