public class

Formatter

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.util.Formatter

Class Overview

This utility class contains useful text and buffer formatting methods.

Summary

Public Constructors
Formatter()
Public Methods
static String byteArrayToHexString(byte[] data)
static String byteArrayToHexString(byte[] data, int pos, int end)
static String byteArrayToHexString(byte[] data, int pos)
static String escapeBytes(byte[] bytes)
static String escapeBytes(byte[] bytes, int offset, int size)
static String escapeCharacter(char c, boolean keepUnicodePrintables)
Escape a character, if necessary.
static String escapeString(String s, boolean keepUnicodePrintables)
Escape a string.
static String formatBinaryBlock(byte[] data, int offset, int size)
Format a block of bytes.
static String formatBinaryBlock(byte[] data)
Format a block of bytes.
static String formatBinaryBlock(byte[] data, int offset, int size, long offsetDelta, boolean is64bit)
Format a block of bytes as a buffer of hexadecimal lines.
static String formatBinaryBlock(byte[] data, int offset, int size, int offsetDelta)
Format a block of bytes.
static String formatBinaryLine(byte[] data, int offset, int size, int minVirtualSize)
Format a block of bytes as a hexadecimal string representation.
static String formatBinaryLine(byte[] data)
Format a block of bytes.
static String formatBinaryLineTruncate(byte[] data, int offset, int size, int maxSize, char truncateChar)
static String formatBinaryLineTruncate(byte[] data, int offset, int size, int fixedCount)
static String formatHexNumbers(List<? extends Number> list)
static String formatNumbers(List<? extends Number> list, int base, String pfx, String sfx)
static byte[] hexStringToByteArray(String s, int pos, int end)
static byte[] hexStringToByteArray(String s)
static boolean isPrintableChar(char c)
Convenience method to determine whether or not a character is printable.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Formatter ()

Public Methods

public static String byteArrayToHexString (byte[] data)

public static String byteArrayToHexString (byte[] data, int pos, int end)

public static String byteArrayToHexString (byte[] data, int pos)

public static String escapeBytes (byte[] bytes)

public static String escapeBytes (byte[] bytes, int offset, int size)

public static String escapeCharacter (char c, boolean keepUnicodePrintables)

Escape a character, if necessary.

Parameters
c the character to be escaped
keepUnicodePrintables if true, a printable unicode, non-ascii character will be left unescaped
Returns
  • a string representing the escaped character

public static String escapeString (String s, boolean keepUnicodePrintables)

Escape a string. See escapeCharacter(char, boolean).

Parameters
s the string to be escapes

public static String formatBinaryBlock (byte[] data, int offset, int size)

Format a block of bytes. Same as formatBinaryBlock(data, offset, size, 0)

Parameters
data bytes buffer
offset beginning of bytes sequence to be formatted
size number of bytes to be formatted
Returns
  • a formatted string

public static String formatBinaryBlock (byte[] data)

Format a block of bytes. Same as formatBinaryBlock(data, 0, data.length)

Parameters
data bytes buffer
Returns
  • a formatted string

public static String formatBinaryBlock (byte[] data, int offset, int size, long offsetDelta, boolean is64bit)

Format a block of bytes as a buffer of hexadecimal lines. Each line represents the 16 bytes of buffer data; it is prefixed by an optional offset (address) base and suffixed by the Ascii representation of the bytes. Note that non-printable, non-Ascii characters are represented as dots.

Parameters
data bytes buffer
offset beginning of bytes sequence to be formatted
size number of bytes to be formatted
offsetDelta an offset delta
is64bit indicates if the prefix offset should be formatted as a 64-bit or 32-bit value
Returns
  • a formatted string

public static String formatBinaryBlock (byte[] data, int offset, int size, int offsetDelta)

public static String formatBinaryLine (byte[] data, int offset, int size, int minVirtualSize)

Format a block of bytes as a hexadecimal string representation. Bytes will be represented space-separated.

Parameters
data bytes buffer
offset beginning of bytes sequence to be formatted
size number of bytes to be formatted
minVirtualSize minimum number of bytes that the resulting string is supposed to represent; phantom bytes (formatted as empty space) will be appended if necessary
Returns
  • a formatted string

public static String formatBinaryLine (byte[] data)

Format a block of bytes. Same as formatBinaryLine(data, 0, data.length, 0).

Parameters
data bytes buffer
Returns
  • a formatted string

public static String formatBinaryLineTruncate (byte[] data, int offset, int size, int maxSize, char truncateChar)

public static String formatBinaryLineTruncate (byte[] data, int offset, int size, int fixedCount)

public static String formatHexNumbers (List<? extends Number> list)

public static String formatNumbers (List<? extends Number> list, int base, String pfx, String sfx)

public static byte[] hexStringToByteArray (String s, int pos, int end)

public static byte[] hexStringToByteArray (String s)

public static boolean isPrintableChar (char c)

Convenience method to determine whether or not a character is printable.

Parameters
c the input character
Returns
  • true if the character is printable