public class ISOUtil
extends java.lang.Object
ISOComponent
Modifier and Type | Field and Description |
---|---|
static java.nio.charset.Charset |
CHARSET
Default charset for bytes transmissions over network
|
static java.nio.charset.Charset |
EBCDIC |
static java.lang.String |
ENCODING
Deprecated.
use
CHARSET instead |
static byte |
ETX |
static byte |
FS |
static byte |
GS |
static java.lang.String[] |
hexStrings |
static byte |
RS |
static byte |
STX |
static java.util.regex.Pattern |
unicodePattern |
static byte |
US |
Constructor and Description |
---|
ISOUtil()
All methods in this class are static, so there's usually no need to instantiate it
We provide this public constructor in order to deal with some legacy script integration
that needs an instance of this class in a rendering context.
|
Modifier and Type | Method and Description |
---|---|
static byte[] |
asciiToEbcdic(byte[] a) |
static void |
asciiToEbcdic(byte[] s,
byte[] e,
int offset) |
static byte[] |
asciiToEbcdic(java.lang.String s) |
static void |
asciiToEbcdic(java.lang.String s,
byte[] e,
int offset) |
static java.lang.String |
bcd2str(byte[] b,
int offset,
int len,
boolean padLeft)
converts a BCD representation of a number to a String
|
static byte[] |
bitSet2byte(java.util.BitSet b)
converts a BitSet into a binary field
used in pack routines
This method will set bits 0 (and 65) if there's a secondary (and tertiary) bitmap
(i.e., if the bitmap length is > 64 (and > 128))
|
static byte[] |
bitSet2byte(java.util.BitSet b,
int bytes)
converts a BitSet into a binary field
used in pack routines
This method will set bits 0 (and 65) if there's a secondary (and tertiary) bitmap
(i.e., if the bitmap length is > 64 (and > 128))
|
static byte[] |
bitSet2extendedByte(java.util.BitSet b)
Converts a BitSet into an extended binary field
used in pack routines.
|
static int |
bitSet2Int(java.util.BitSet bs) |
static java.lang.String |
bitSet2String(java.util.BitSet b)
bit representation of a BitSet
suitable for dumps and debugging
|
static java.lang.String |
blankUnPad(java.lang.String s)
Right unPad with ' '
|
static java.util.BitSet |
byte2BitSet(java.util.BitSet bmap,
byte[] b,
int bitOffset)
Converts a binary representation of a Bitmap field
into a Java BitSet.
|
static java.util.BitSet |
byte2BitSet(byte[] b,
int offset,
boolean bitZeroMeansExtended)
Converts a binary representation of a Bitmap field
into a Java BitSet
|
static java.util.BitSet |
byte2BitSet(byte[] b,
int offset,
int maxBits)
Converts a binary representation of a Bitmap field
into a Java BitSet
|
static java.lang.String |
byte2hex(byte[] bs)
Converts a byte array into a hex string
|
static java.lang.String |
byte2hex(byte[] bs,
int off,
int length)
Converts a byte array into a string of lower case hex chars.
|
static int |
byte2int(byte[] bytes)
Converts a byte array of hex into an integer
|
static char |
calcLUHN(java.lang.String p)
Compute card's check digit (LUHN)
|
static java.lang.String[] |
charDecode(char delimiter,
java.lang.String s)
Decodes a char encoded String as encoded by charEncode
|
static java.lang.String |
charDecode(java.lang.String s,
char delimiter,
int i)
Decodes a char encoded String returning element in position i
|
static java.lang.String |
charEncode(char delimiter,
java.lang.String... ss)
Converts a string[] or multiple strings into one char-delimited String.
|
static java.lang.String[] |
commaDecode(java.lang.String s)
Decodes a comma encoded String as encoded by commaEncode
|
static java.lang.String |
commaDecode(java.lang.String s,
int i)
Decodes a comma encoded String returning element in position i
|
static java.lang.String |
commaEncode(java.lang.String... ss)
Converts a string[] or multiple strings into one comma-delimited String.
|
static byte[] |
concat(byte[] array1,
byte[] array2)
Concatenates two byte arrays (array1 and array2)
|
static byte[] |
concat(byte[] array1,
int beginIndex1,
int length1,
byte[] array2,
int beginIndex2,
int length2)
Concatenates two byte arrays (array1 and array2)
|
static byte[] |
decodeHexDump(java.lang.String s) |
static java.lang.String |
dumpString(byte[] b)
converts a byte array to printable characters
|
static java.lang.String |
ebcdicToAscii(byte[] e) |
static java.lang.String |
ebcdicToAscii(byte[] e,
int offset,
int len) |
static byte[] |
ebcdicToAsciiBytes(byte[] e) |
static byte[] |
ebcdicToAsciiBytes(byte[] e,
int offset,
int len) |
static java.lang.String |
formatAmount(long l,
int len)
prepare long value used as amount for display
(implicit 2 decimals)
|
static java.lang.String |
formatAmountConversionRate(double convRate)
Format a string containing a amount conversion rate in the proper format
Format:
The leftmost digit (i.e., position 1) of this data element denotes the number of
positions the decimal separator must be moved from the right.
|
static java.lang.String |
formatDouble(double d,
int len)
format double value
|
static java.lang.String |
getRandomDigits(java.util.Random r,
int l,
int radix) |
static java.util.BitSet |
hex2BitSet(java.util.BitSet bmap,
byte[] b,
int bitOffset)
Converts an ASCII representation of a Bitmap field
into a Java BitSet
|
static java.util.BitSet |
hex2BitSet(byte[] b,
int offset,
boolean bitZeroMeansExtended)
Converts an ASCII representation of a Bitmap field
into a Java BitSet
|
static java.util.BitSet |
hex2BitSet(byte[] b,
int offset,
int maxBits)
Converts an ASCII representation of a Bitmap field
into a Java BitSet
|
static byte[] |
hex2byte(byte[] b,
int offset,
int len) |
static byte[] |
hex2byte(java.lang.String s)
Converts a hex string into a byte array
|
static byte[] |
hex2byte(java.lang.String s,
java.nio.charset.Charset charset)
Converts a hex string into a byte array
|
static java.lang.String |
hex2str(byte[] b,
int offset,
int len,
boolean padLeft)
converts a a byte array to a String with padding support
|
static java.lang.String |
hexdump(byte[] b) |
static java.lang.String |
hexdump(byte[] b,
int offset) |
static java.lang.String |
hexdump(byte[] b,
int offset,
int len) |
static java.lang.String |
hexDump(byte[] array,
int offset,
int length,
java.nio.charset.Charset charSet)
At times when the charset is not the default usual one the dump will have more unprintable characters than printable.
|
static java.lang.String |
hexor(java.lang.String op1,
java.lang.String op2)
Bitwise XOR between corresponding byte arrays represented in hex
|
static java.lang.String |
hexString(byte[] b)
converts a byte array to hex string
(suitable for dumps and ASCII packaging of Binary fields
|
static java.lang.String |
hexString(byte[] b,
int offset,
int len)
converts a byte array to hex string
(suitable for dumps and ASCII packaging of Binary fields
|
static java.util.BitSet |
int2BitSet(int value) |
static java.util.BitSet |
int2BitSet(int value,
int offset) |
static byte[] |
int2byte(int value)
Converts an integer into a byte array of hex
|
static boolean |
isAlphaNumeric(java.lang.String s)
Return true if the string is alphanum.
|
static boolean |
isBlank(java.lang.String s) |
static boolean |
isNumeric(java.lang.String s,
int radix)
Return true if the string represent a number
in the specified radix.
|
static boolean |
isZero(java.lang.String s) |
static java.lang.String |
millisToString(long millis) |
static java.lang.String |
normalize(java.lang.String s)
XML normalizer (default canonical)
|
static java.lang.String |
normalize(java.lang.String s,
boolean canonical)
XML normalizer
|
static java.lang.String |
padleft(java.lang.String s,
int len,
char c)
pad to the left
|
static java.lang.String |
padright(java.lang.String s,
int len,
char c)
pad to the right
|
static double |
parseAmountConversionRate(java.lang.String convRate)
Parse currency amount conversion rate string
Suitble for parse fields 10 and 11
|
static int |
parseInt(byte[] bArray)
Converts a byte array to an integer of radix 10.
|
static int |
parseInt(byte[] bArray,
int radix)
Converts a byte array to an integer of base radix.
|
static int |
parseInt(char[] cArray)
Converts a character array to an integer of radix 10.
|
static int |
parseInt(char[] cArray,
int radix)
Converts a character array to an integer of base radix.
|
static int |
parseInt(java.lang.String s)
Converts a String to an integer of radix 10.
|
static int |
parseInt(java.lang.String s,
int radix)
Converts a String to an integer of base radix.
|
static java.lang.String |
protect(java.lang.String s) |
static java.lang.String |
protect(java.lang.String s,
char mask)
Protects PAN, Track2, CVC (suitable for logs).
|
static java.lang.String |
readableFileSize(long size) |
static void |
sleep(long millis)
Causes the currently executing thread to sleep (temporarily cease
execution) for the specified number of milliseconds.
|
static byte[] |
str2bcd(java.lang.String s,
boolean padLeft)
converts to BCD
|
static byte[] |
str2bcd(java.lang.String s,
boolean padLeft,
byte fill)
converts to BCD
|
static byte[] |
str2bcd(java.lang.String s,
boolean padLeft,
byte[] d,
int offset)
converts to BCD
|
static byte[] |
str2hex(java.lang.String s,
boolean padLeft,
byte[] d,
int offset)
converts to BCD
|
static java.lang.String |
stripUnicode(java.lang.String s) |
static java.lang.String |
strpad(java.lang.String s,
int len)
pads to the right
|
static java.lang.String |
strpadf(java.lang.String s,
int len)
pads a string with 'F's (useful for pinoffset management)
|
static java.lang.String |
takeFirstN(java.lang.String s,
int n)
return the first n characters of the passed String, left padding where required with 0
|
static java.lang.String |
takeLastN(java.lang.String s,
int n)
return the last n characters of the passed String, left padding where required with 0
|
static int[] |
toIntArray(java.lang.String s) |
static java.lang.String[] |
toStringArray(java.lang.String s) |
static byte[] |
trim(byte[] array,
int length)
Trims a byte[] to a certain length
|
static java.lang.String |
trim(java.lang.String s)
trim String (if not null)
|
static java.lang.String |
trimf(java.lang.String s)
reverse the effect of strpadf
|
static java.lang.String |
unPadLeft(java.lang.String s,
char c)
Unpad from left.
|
static java.lang.String |
unPadRight(java.lang.String s,
char c)
Unpad from right.
|
static byte[] |
xor(byte[] op1,
byte[] op2)
Bitwise XOR between corresponding bytes
|
static java.lang.String |
zeropad(long l,
int len)
zeropads a long without throwing an ISOException (performs modulus operation)
|
static java.lang.String |
zeropad(java.lang.String s,
int len)
left pad with '0'
|
static java.lang.String |
zeropadRight(java.lang.String s,
int len) |
static java.lang.String |
zeroUnPad(java.lang.String s)
Left unPad with '0'
|
public static final java.lang.String[] hexStrings
public static final java.lang.String ENCODING
CHARSET
insteadpublic static final java.util.regex.Pattern unicodePattern
public static final java.nio.charset.Charset CHARSET
public static final java.nio.charset.Charset EBCDIC
public static final byte STX
public static final byte FS
public static final byte US
public static final byte RS
public static final byte GS
public static final byte ETX
public ISOUtil()
public static java.lang.String ebcdicToAscii(byte[] e)
public static java.lang.String ebcdicToAscii(byte[] e, int offset, int len)
public static byte[] ebcdicToAsciiBytes(byte[] e)
public static byte[] ebcdicToAsciiBytes(byte[] e, int offset, int len)
public static byte[] asciiToEbcdic(java.lang.String s)
public static byte[] asciiToEbcdic(byte[] a)
public static void asciiToEbcdic(java.lang.String s, byte[] e, int offset)
public static void asciiToEbcdic(byte[] s, byte[] e, int offset)
public static java.lang.String padleft(java.lang.String s, int len, char c) throws ISOException
s
- - original stringlen
- - desired lenc
- - padding charISOException
- on errorpublic static java.lang.String padright(java.lang.String s, int len, char c) throws ISOException
s
- -
original stringlen
- -
desired lenc
- -
padding charISOException
- if String's length greater than pad lengthpublic static java.lang.String trim(java.lang.String s)
s
- String to trimpublic static java.lang.String zeropad(java.lang.String s, int len) throws ISOException
s
- - original stringlen
- - desired lenISOException
- if string's length greater than lenpublic static java.lang.String zeropad(long l, int len)
l
- the longlen
- the lengthpublic static java.lang.String strpad(java.lang.String s, int len)
s
- - original stringlen
- - desired lenpublic static java.lang.String zeropadRight(java.lang.String s, int len)
public static byte[] str2bcd(java.lang.String s, boolean padLeft, byte[] d, int offset)
s
- - the numberpadLeft
- - flag indicating left/right paddingd
- The byte array to copy into.offset
- Where to start copying into.public static byte[] str2hex(java.lang.String s, boolean padLeft, byte[] d, int offset)
s
- - the numberpadLeft
- - flag indicating left/right paddingd
- The byte array to copy into.offset
- Where to start copying into.public static byte[] str2bcd(java.lang.String s, boolean padLeft)
s
- - the numberpadLeft
- - flag indicating left/right paddingpublic static byte[] str2bcd(java.lang.String s, boolean padLeft, byte fill)
s
- - the numberpadLeft
- - flag indicating left/right paddingfill
- - fill valuepublic static java.lang.String bcd2str(byte[] b, int offset, int len, boolean padLeft)
b
- - BCD representationoffset
- - starting offsetlen
- - BCD field lenpadLeft
- - was padLeft packed?public static java.lang.String hex2str(byte[] b, int offset, int len, boolean padLeft)
b
- - HEX representationoffset
- - starting offsetlen
- - BCD field lenpadLeft
- - was padLeft packed?public static java.lang.String hexString(byte[] b)
b
- - byte arraypublic static java.lang.String dumpString(byte[] b)
b
- - byte arraypublic static java.lang.String hexString(byte[] b, int offset, int len)
b
- - byte arrayoffset
- - starting positionlen
- the lengthpublic static java.lang.String bitSet2String(java.util.BitSet b)
b
- - the BitSetpublic static byte[] bitSet2byte(java.util.BitSet b)
b
- - the BitSetpublic static byte[] bitSet2byte(java.util.BitSet b, int bytes)
b
- - the BitSetbytes
- - number of bytes to returnpublic static int bitSet2Int(java.util.BitSet bs)
public static java.util.BitSet int2BitSet(int value)
public static java.util.BitSet int2BitSet(int value, int offset)
public static java.util.BitSet byte2BitSet(byte[] b, int offset, boolean bitZeroMeansExtended)
b
- - binary representationoffset
- - staring offsetbitZeroMeansExtended
- - true for ISO-8583public static java.util.BitSet byte2BitSet(byte[] b, int offset, int maxBits)
b
- - binary representationoffset
- - staring offsetmaxBits
- - max number of bits (supports 64,128 or 192)public static java.util.BitSet byte2BitSet(java.util.BitSet bmap, byte[] b, int bitOffset)
bmap
- - BitSetb
- - hex representationbitOffset
- - (i.e. 0 for primary bitmap, 64 for secondary)public static java.util.BitSet hex2BitSet(byte[] b, int offset, boolean bitZeroMeansExtended)
b
- - hex representationoffset
- - starting offsetbitZeroMeansExtended
- - true for ISO-8583public static java.util.BitSet hex2BitSet(byte[] b, int offset, int maxBits)
b
- - hex representationoffset
- - starting offsetmaxBits
- - max number of bits (supports 8, 16, 24, 32, 48, 52, 64,.. 128 or 192)public static java.util.BitSet hex2BitSet(java.util.BitSet bmap, byte[] b, int bitOffset)
bmap
- - BitSetb
- - hex representationbitOffset
- - (i.e. 0 for primary bitmap, 64 for secondary)public static byte[] hex2byte(byte[] b, int offset, int len)
b
- source byte arrayoffset
- starting offsetlen
- number of bytes in destination (processes len*2)public static byte[] hex2byte(java.lang.String s)
s
- source string (with Hex representation)public static byte[] hex2byte(java.lang.String s, java.nio.charset.Charset charset)
s
- source string (with Hex representation)charset
- character set to be usedpublic static java.lang.String byte2hex(byte[] bs)
bs
- source byte arraypublic static byte[] int2byte(int value)
value
- public static int byte2int(byte[] bytes)
bytes
- public static java.lang.String byte2hex(byte[] bs, int off, int length)
bs
- A byte arrayoff
- The index of the first byte to readlength
- The number of bytes to read.public static java.lang.String formatDouble(double d, int len)
d
- the amountlen
- the field lenpublic static java.lang.String formatAmount(long l, int len) throws ISOException
l
- valuelen
- display lenISOException
public static java.lang.String normalize(java.lang.String s, boolean canonical)
s
- source Stringcanonical
- true if we want to normalize \r and \n as wellpublic static java.lang.String stripUnicode(java.lang.String s)
public static java.lang.String normalize(java.lang.String s)
s
- source Stringpublic static java.lang.String protect(java.lang.String s, char mask)
"40000101010001" is converted to "400001____0001" "40000101010001=020128375" is converted to "400001____0001=0201_____" "40000101010001D020128375" is converted to "400001____0001D0201_____" "123" is converted to "___"
s
- string to be protectedmask
- char used to protect the stringpublic static java.lang.String protect(java.lang.String s)
public static int[] toIntArray(java.lang.String s)
public static java.lang.String[] toStringArray(java.lang.String s)
public static byte[] xor(byte[] op1, byte[] op2)
op1
- byteArray1op2
- byteArray2public static java.lang.String hexor(java.lang.String op1, java.lang.String op2)
op1
- hexstring 1op2
- hexstring 2public static byte[] trim(byte[] array, int length)
array
- the byte[] to be trimmedlength
- the wanted lengthpublic static byte[] concat(byte[] array1, byte[] array2)
array1
- first partarray2
- last partpublic static byte[] concat(byte[] array1, int beginIndex1, int length1, byte[] array2, int beginIndex2, int length2)
array1
- first partbeginIndex1
- initial indexlength1
- lengtharray2
- last partbeginIndex2
- last part indexlength2
- last part lengthpublic static void sleep(long millis)
millis
- the length of time to sleep in milliseconds.public static java.lang.String zeroUnPad(java.lang.String s)
s
- - original stringpublic static java.lang.String blankUnPad(java.lang.String s)
s
- - original stringpublic static java.lang.String unPadRight(java.lang.String s, char c)
s
- - original stringc
- - padding charpublic static java.lang.String unPadLeft(java.lang.String s, char c)
s
- - original stringc
- - padding charpublic static boolean isZero(java.lang.String s)
public static boolean isBlank(java.lang.String s)
public static boolean isAlphaNumeric(java.lang.String s)
{letter digit (.) (_) (-) ( ) (?) }
public static boolean isNumeric(java.lang.String s, int radix)
public static byte[] bitSet2extendedByte(java.util.BitSet b)
b
- the BitSetpublic static int parseInt(java.lang.String s, int radix) throws java.lang.NumberFormatException
s
- String representation of numberradix
- Number base to usejava.lang.NumberFormatException
public static int parseInt(java.lang.String s) throws java.lang.NumberFormatException
s
- String representation of numberjava.lang.NumberFormatException
public static int parseInt(char[] cArray, int radix) throws java.lang.NumberFormatException
cArray
- Character Array representation of numberradix
- Number base to usejava.lang.NumberFormatException
public static int parseInt(char[] cArray) throws java.lang.NumberFormatException
cArray
- Character Array representation of numberjava.lang.NumberFormatException
public static int parseInt(byte[] bArray, int radix) throws java.lang.NumberFormatException
bArray
- Byte Array representation of numberradix
- Number base to usejava.lang.NumberFormatException
public static int parseInt(byte[] bArray) throws java.lang.NumberFormatException
bArray
- Byte Array representation of numberjava.lang.NumberFormatException
public static java.lang.String hexdump(byte[] b)
b
- a byte[] bufferpublic static java.lang.String hexdump(byte[] b, int offset)
b
- a byte[] bufferoffset
- starting offsetpublic static java.lang.String hexdump(byte[] b, int offset, int len)
b
- a byte[] bufferoffset
- starting offsetlen
- the Lengthpublic static java.lang.String strpadf(java.lang.String s, int len)
s
- an [hex]stringlen
- desired lengthpublic static java.lang.String trimf(java.lang.String s)
s
- F padded stringpublic static java.lang.String takeLastN(java.lang.String s, int n) throws ISOException
s
- String to take fromn
- nuber of characters to takeISOException
public static java.lang.String takeFirstN(java.lang.String s, int n) throws ISOException
s
- String to take fromn
- nuber of characters to takeISOException
public static java.lang.String millisToString(long millis)
public static java.lang.String formatAmountConversionRate(double convRate) throws ISOException
convRate
- - amount conversion rateISOException
public static double parseAmountConversionRate(java.lang.String convRate)
convRate
- amount conversation ratejava.lang.IllegalArgumentException
public static java.lang.String commaEncode(java.lang.String... ss)
ss
- string array to be comma encodedcommaDecode(String)
public static java.lang.String[] commaDecode(java.lang.String s)
s
- the command encoded StringcommaEncode(String[])
public static java.lang.String commaDecode(java.lang.String s, int i)
s
- comma encoded stringi
- position (starts at 0)public static char calcLUHN(java.lang.String p)
p
- PAN (without checkdigit)public static java.lang.String getRandomDigits(java.util.Random r, int l, int radix)
public static java.lang.String readableFileSize(long size)
public static java.lang.String hexDump(byte[] array, int offset, int length, java.nio.charset.Charset charSet)
array
- the array that needs to be dumped.offset
- From where the data needs to be dumped.length
- The number of byte that ned to be dumped.charSet
- The Charset encoding the array is i.public static byte[] decodeHexDump(java.lang.String s)
public static java.lang.String charEncode(char delimiter, java.lang.String... ss)
delimiter
- char used to delimitss
- string array to be char encodedcharDecode(char, String)
public static java.lang.String[] charDecode(char delimiter, java.lang.String s)
delimiter
- char used to delimits
- the char encoded StringcharEncode(char, String[])
public static java.lang.String charDecode(java.lang.String s, char delimiter, int i)
s
- comma encoded stringdelimiter
- char used to delimiti
- position (starts at 0)