java.lang.Object
org.sejda.sambox.util.Hex
Utility functions for hex encoding.
- Author:
- John Hewson
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]Decodes a hex String into a byte array.static byte[]getBytes(byte b) Returns the bytes corresponding to the ASCII hex encoding of the given byte.static byte[]getBytes(byte[] bytes) Returns the bytes corresponding to the ASCII hex encoding of the given bytes.static char[]getChars(short num) Returns the characters corresponding to the ASCII hex encoding of the given short.static char[]getCharsUTF16BE(String text) Takes the characters in the given string, convert it to bytes in UTF16-BE format and build a char array that corresponds to the ASCII hex encoding of the resulting bytes.static StringgetString(byte b) Returns a hex string of the given byte.static StringgetString(byte[] bytes) Returns a hex string of the given byte array.static voidwriteHexByte(byte b, OutputStream output) Writes the given byte as hex value to the given output stream.static voidwriteHexBytes(byte[] bytes, OutputStream output) Writes the given byte array as hex value to the given output stream.
-
Method Details
-
getString
Returns a hex string of the given byte. -
getString
Returns a hex string of the given byte array. -
getBytes
public static byte[] getBytes(byte b) Returns the bytes corresponding to the ASCII hex encoding of the given byte. -
getBytes
public static byte[] getBytes(byte[] bytes) Returns the bytes corresponding to the ASCII hex encoding of the given bytes. -
getChars
public static char[] getChars(short num) Returns the characters corresponding to the ASCII hex encoding of the given short. -
getCharsUTF16BE
Takes the characters in the given string, convert it to bytes in UTF16-BE format and build a char array that corresponds to the ASCII hex encoding of the resulting bytes.Example:
getCharsUTF16BE("ab") == new char[] { '0', '0', '6', '1', '0', '0', '6', '2' }- Parameters:
text- The string to convert- Returns:
- The string converted to hex
-
writeHexByte
Writes the given byte as hex value to the given output stream.- Parameters:
b- the byte to be writtenoutput- the output stream to be written to- Throws:
IOException- exception if anything went wrong
-
writeHexBytes
Writes the given byte array as hex value to the given output stream.- Parameters:
bytes- the byte array to be writtenoutput- the output stream to be written to- Throws:
IOException- exception if anything went wrong
-
decodeHex
Decodes a hex String into a byte array.- Parameters:
s- A String with ASCII hex.- Returns:
- decoded byte array.
- Throws:
IOException
-