org.jnetpcap.packet.format
Class FormatUtils

java.lang.Object
  extended by org.jnetpcap.packet.format.FormatUtils

public class FormatUtils
extends java.lang.Object

Various static formatting utilities.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Constructor Summary
FormatUtils()
           
 
Method Summary
static java.lang.String asString(byte[] array)
          Converts the given byte array to a string using a default separator character.
static java.lang.String asString(byte[] array, char separator)
          Convers the given byte array to a string using the supplied separator character.
static java.lang.String asString(byte[] array, char separator, int radix)
          Converts the given byte array to a string using the supplied separator character and radix for conversion of the numerical component.
static java.lang.String asString(byte[] array, char separator, int radix, int start, int len)
          Convers the given byte array to a string using the supplied separator character.
static java.lang.String asStringIp6(byte[] array, boolean holes)
          Handles various forms of ip6 addressing
static java.lang.String asStringZeroPad(byte[] array, char separator, int radix, int start, int len)
          Convers the given byte array to a string using the supplied separator character.
static java.lang.String formatTimeInMillis(long millis)
          Formats a delta time.
static java.lang.String hexdump(byte[] array)
          Formats the supplied array for single line combined hexdump output using all possible options turned on.
static java.lang.String[] hexdump(byte[] array, int addressOffset, int dataOffset, boolean doAddress, boolean doText, boolean doData)
          Formats a byte array to a hexdump string.
static java.lang.String[] hexdump(byte[] array, int addressOffset, int dataOffset, boolean doAddress, boolean doText, boolean doData, int[][] markers)
          Formats a byte array to a hexdump string.
static java.lang.String hexdump(byte[] array, JPacket.State state)
          Formats the supplied array for single line combined hexdump output using all possible options turned on.
static java.lang.String hexdump(JPacket packet)
          Formats the supplied packet for single line combined hexdump output using all possible options turned on.
static java.lang.String hexdumpCombined(byte[] array, int addressOffset, int dataOffset, boolean doAddress, boolean doText, boolean doData)
          Converts the byte arra to hexdump string.
static java.lang.String hexdumpCombined(byte[] array, int addressOffset, int dataOffset, boolean doAddress, boolean doText, boolean doData, int[][] markers)
          Converts the byte arra to hexdump string.
static java.lang.String hexLine(byte[] array, int addressOffset, int dataOffset, boolean doAddress, boolean doText, boolean doData, int[][] markers)
          Converts the byte arra to hexdump string.
static java.lang.String hexLineAddress(int address)
          Format an address.
static java.lang.String hexLineData(byte[] data, int offset)
          Formats the data array as a hexdump.
static java.lang.String hexLineData(byte[] data, int offset, int[][] markers)
          Formats the data array as a hexdump.
static java.lang.String hexLineText(byte[] data, int offset)
          Formats the array data to human readable text that appears at the end of a hexline of a hexdump.
static java.lang.String ip(byte[] address)
          Ip.
static java.lang.String mac(byte[] address)
          Mac.
static int[][] markers(JPacket.State state)
          Markers.
static byte[] toByteArray(java.lang.String source)
          Parses a string containing hex numbers to a byte array.
static java.lang.String toHexString(byte b)
          Formats a number to hext.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormatUtils

public FormatUtils()
Method Detail

asString

public static java.lang.String asString(byte[] array)
Converts the given byte array to a string using a default separator character.

Parameters:
array - array to convert
Returns:
the converted string

asString

public static java.lang.String asString(byte[] array,
                                        char separator)
Convers the given byte array to a string using the supplied separator character.

Parameters:
array - array to convert
separator - separator character to use in between array elements
Returns:
the converted string

asString

public static java.lang.String asString(byte[] array,
                                        char separator,
                                        int radix)
Converts the given byte array to a string using the supplied separator character and radix for conversion of the numerical component.

Parameters:
array - array to convert
separator - separator character to use in between array elements
radix - numerical radix to use for numbers
Returns:
the converted string

asString

public static java.lang.String asString(byte[] array,
                                        char separator,
                                        int radix,
                                        int start,
                                        int len)
Convers the given byte array to a string using the supplied separator character.

Parameters:
array - array to convert
separator - separator character to use in between array elements
radix - the radix
start - the start
len - the len
Returns:
the converted string

asStringZeroPad

public static java.lang.String asStringZeroPad(byte[] array,
                                               char separator,
                                               int radix,
                                               int start,
                                               int len)
Convers the given byte array to a string using the supplied separator character.

Parameters:
array - array to convert
separator - separator character to use in between array elements
radix - the radix
start - the start
len - the len
Returns:
the converted string

ip

public static java.lang.String ip(byte[] address)
Ip.

Parameters:
address - the address
Returns:
the string

mac

public static java.lang.String mac(byte[] address)
Mac.

Parameters:
address - the address
Returns:
the string

asStringIp6

public static java.lang.String asStringIp6(byte[] array,
                                           boolean holes)
Handles various forms of ip6 addressing
 2001:0db8:0000:0000:0000:0000:1428:57ab
 2001:0db8:0000:0000:0000::1428:57ab
 2001:0db8:0:0:0:0:1428:57ab
 2001:0db8:0:0::1428:57ab
 2001:0db8::1428:57ab
 2001:db8::1428:57ab
 
.

Parameters:
array - address array
holes - if true holes are allowed
Returns:
formatted string

formatTimeInMillis

public static java.lang.String formatTimeInMillis(long millis)
Formats a delta time.

Parameters:
millis - delta timestamp in millis
Returns:
formatted string

hexdump

public static java.lang.String[] hexdump(byte[] array,
                                         int addressOffset,
                                         int dataOffset,
                                         boolean doAddress,
                                         boolean doText,
                                         boolean doData)
Formats a byte array to a hexdump string.

Parameters:
array - array to convert
addressOffset - offset of the address space reported
dataOffset - offset of the data space reported
doAddress - flag which specifies if address should be printed
doText - flag which specifies if text should printed
doData - flag which specifies if data should printed
Returns:
converted string array, one array element per line of output

markers

public static int[][] markers(JPacket.State state)
Markers.

Parameters:
state - the state
Returns:
the int[][]

hexdump

public static java.lang.String[] hexdump(byte[] array,
                                         int addressOffset,
                                         int dataOffset,
                                         boolean doAddress,
                                         boolean doText,
                                         boolean doData,
                                         int[][] markers)
Formats a byte array to a hexdump string.

Parameters:
array - array to convert
addressOffset - offset of the address space reported
dataOffset - offset of the data space reported
doAddress - flag which specifies if address should be printed
doText - flag which specifies if text should printed
doData - flag which specifies if data should printed
markers - the markers
Returns:
converted string array, one array element per line of output

hexdump

public static java.lang.String hexdump(byte[] array)
Formats the supplied array for single line combined hexdump output using all possible options turned on.

Parameters:
array - source array
Returns:
a multi-line string containing verbose hexdump

hexdump

public static java.lang.String hexdump(JPacket packet)
Formats the supplied packet for single line combined hexdump output using all possible options turned on. Also displays markers which mark boundaries between each header.

Parameters:
packet - source of data
Returns:
a multi-line string containing verbose hexdump

hexdump

public static java.lang.String hexdump(byte[] array,
                                       JPacket.State state)
Formats the supplied array for single line combined hexdump output using all possible options turned on.

Parameters:
array - source array
state - the state
Returns:
a multi-line string containing verbose hexdump

hexdumpCombined

public static java.lang.String hexdumpCombined(byte[] array,
                                               int addressOffset,
                                               int dataOffset,
                                               boolean doAddress,
                                               boolean doText,
                                               boolean doData)
Converts the byte arra to hexdump string.

Parameters:
array - array to convert
addressOffset - offset of the address space reported
dataOffset - offset of the data space reported
doAddress - flag which specifies if address should be printed
doText - flag which specifies if text should printed
doData - flag which specifies if data should printed
Returns:
converted string

hexdumpCombined

public static java.lang.String hexdumpCombined(byte[] array,
                                               int addressOffset,
                                               int dataOffset,
                                               boolean doAddress,
                                               boolean doText,
                                               boolean doData,
                                               int[][] markers)
Converts the byte arra to hexdump string.

Parameters:
array - array to convert
addressOffset - offset of the address space reported
dataOffset - offset of the data space reported
doAddress - flag which specifies if address should be printed
doText - flag which specifies if text should printed
doData - flag which specifies if data should printed
markers - the markers
Returns:
converted string

hexLine

public static java.lang.String hexLine(byte[] array,
                                       int addressOffset,
                                       int dataOffset,
                                       boolean doAddress,
                                       boolean doText,
                                       boolean doData,
                                       int[][] markers)
Converts the byte arra to hexdump string.

Parameters:
array - array to convert
addressOffset - offset of the address space reported
dataOffset - offset of the data space reported
doAddress - flag which specifies if address should be printed
doText - flag which specifies if text should printed
doData - flag which specifies if data should printed
markers - the markers
Returns:
converted string array, one array element per line of output

hexLineAddress

public static java.lang.String hexLineAddress(int address)
Format an address.

Parameters:
address - integer address
Returns:
formatted address string

hexLineData

public static java.lang.String hexLineData(byte[] data,
                                           int offset)
Formats the data array as a hexdump.

Parameters:
data - data array
offset - offset into the array
Returns:
formatted string

hexLineData

public static java.lang.String hexLineData(byte[] data,
                                           int offset,
                                           int[][] markers)
Formats the data array as a hexdump.

Parameters:
data - data array
offset - offset into the array
markers - the markers
Returns:
formatted string

hexLineText

public static java.lang.String hexLineText(byte[] data,
                                           int offset)
Formats the array data to human readable text that appears at the end of a hexline of a hexdump.

Parameters:
data - data array
offset - offset into data array
Returns:
formatted string

toByteArray

public static byte[] toByteArray(java.lang.String source)
Parses a string containing hex numbers to a byte array.

Parameters:
source - source string
Returns:
byte array from the parsed data

toHexString

public static java.lang.String toHexString(byte b)
Formats a number to hext.

Parameters:
b - input byte
Returns:
formatted string