Package org.jpos.iso
Class ISOUtil
- java.lang.Object
-
- org.jpos.iso.ISOUtil
-
public class ISOUtil extends java.lang.Object
various functions needed to pack/unpack ISO-8583 fields- See Also:
ISOComponent
-
-
Field Summary
Fields Modifier and Type Field Description static java.nio.charset.Charset
CHARSET
Default charset for bytes transmissions over networkstatic java.nio.charset.Charset
EBCDIC
static java.lang.String
ENCODING
Deprecated.useCHARSET
insteadstatic 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 Summary
Constructors Constructor 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.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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 Stringstatic 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 debuggingstatic java.lang.String
blankUnPad(java.lang.String s)
Right unPad with ' 'static java.util.BitSet
byte2BitSet(byte[] b, int offset, boolean bitZeroMeansExtended)
Converts a binary representation of a Bitmap field into a Java BitSetstatic java.util.BitSet
byte2BitSet(byte[] b, int offset, int maxBits)
Converts a binary representation of a Bitmap field into a Java BitSetstatic 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.lang.String
byte2hex(byte[] bs)
Converts a byte array into a hex stringstatic 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 integerstatic 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 charEncodestatic java.lang.String
charDecode(java.lang.String s, char delimiter, int i)
Decodes a char encoded String returning element in position istatic 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 commaEncodestatic java.lang.String
commaDecode(java.lang.String s, int i)
Decodes a comma encoded String returning element in position istatic 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 charactersstatic 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 formatstatic java.lang.String
formatDouble(double d, int len)
format double valuestatic java.lang.String
getRandomDigits(java.util.Random r, int l, int radix)
static java.util.BitSet
hex2BitSet(byte[] b, int offset, boolean bitZeroMeansExtended)
Converts an ASCII representation of a Bitmap field into a Java BitSetstatic java.util.BitSet
hex2BitSet(byte[] b, int offset, int maxBits)
Converts an ASCII representation of a Bitmap field into a Java BitSetstatic java.util.BitSet
hex2BitSet(java.util.BitSet bmap, byte[] b, int bitOffset)
Converts an ASCII representation of a Bitmap field into a Java BitSetstatic byte[]
hex2byte(byte[] b, int offset, int len)
static byte[]
hex2byte(java.lang.String s)
Converts a hex string into a byte arraystatic byte[]
hex2byte(java.lang.String s, java.nio.charset.Charset charset)
Converts a hex string into a byte arraystatic java.lang.String
hex2str(byte[] b, int offset, int len, boolean padLeft)
converts a a byte array to a String with padding supportstatic 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 hexstatic java.lang.String
hexString(byte[] b)
converts a byte array to hex string (suitable for dumps and ASCII packaging of Binary fieldsstatic 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 fieldsstatic 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 hexstatic 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 normalizerstatic java.lang.String
padleft(java.lang.String s, int len, char c)
pad to the leftstatic java.lang.String
padright(java.lang.String s, int len, char c)
pad to the rightstatic double
parseAmountConversionRate(java.lang.String convRate)
Parse currency amount conversion rate stringstatic 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 BCDstatic byte[]
str2bcd(java.lang.String s, boolean padLeft, byte fill)
converts to BCDstatic byte[]
str2bcd(java.lang.String s, boolean padLeft, byte[] d, int offset)
converts to BCDstatic byte[]
str2hex(java.lang.String s, boolean padLeft, byte[] d, int offset)
converts to BCDstatic java.lang.String
stripUnicode(java.lang.String s)
static java.lang.String
strpad(java.lang.String s, int len)
pads to the rightstatic 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 0static java.lang.String
takeLastN(java.lang.String s, int n)
return the last n characters of the passed String, left padding where required with 0static 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 lengthstatic 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 strpadfstatic 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 bytesstatic 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'
-
-
-
Field Detail
-
hexStrings
public static final java.lang.String[] hexStrings
-
ENCODING
public static final java.lang.String ENCODING
Deprecated.useCHARSET
insteadDefault encoding (charset) for bytes transmissions over network- See Also:
- Constant Field Values
-
unicodePattern
public static final java.util.regex.Pattern unicodePattern
-
CHARSET
public static final java.nio.charset.Charset CHARSET
Default charset for bytes transmissions over network
-
EBCDIC
public static final java.nio.charset.Charset EBCDIC
-
STX
public static final byte STX
- See Also:
- Constant Field Values
-
FS
public static final byte FS
- See Also:
- Constant Field Values
-
US
public static final byte US
- See Also:
- Constant Field Values
-
RS
public static final byte RS
- See Also:
- Constant Field Values
-
GS
public static final byte GS
- See Also:
- Constant Field Values
-
ETX
public static final byte ETX
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ISOUtil
public 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.
-
-
Method Detail
-
ebcdicToAscii
public static java.lang.String ebcdicToAscii(byte[] e)
-
ebcdicToAscii
public static java.lang.String ebcdicToAscii(byte[] e, int offset, int len)
-
ebcdicToAsciiBytes
public static byte[] ebcdicToAsciiBytes(byte[] e)
-
ebcdicToAsciiBytes
public static byte[] ebcdicToAsciiBytes(byte[] e, int offset, int len)
-
asciiToEbcdic
public static byte[] asciiToEbcdic(java.lang.String s)
-
asciiToEbcdic
public static byte[] asciiToEbcdic(byte[] a)
-
asciiToEbcdic
public static void asciiToEbcdic(java.lang.String s, byte[] e, int offset)
-
asciiToEbcdic
public static void asciiToEbcdic(byte[] s, byte[] e, int offset)
-
padleft
public static java.lang.String padleft(java.lang.String s, int len, char c) throws ISOException
pad to the left- Parameters:
s
- - original stringlen
- - desired lenc
- - padding char- Returns:
- padded string
- Throws:
ISOException
- on error
-
padright
public static java.lang.String padright(java.lang.String s, int len, char c) throws ISOException
pad to the right- Parameters:
s
- - original stringlen
- - desired lenc
- - padding char- Returns:
- padded string
- Throws:
ISOException
- if String's length greater than pad length
-
trim
public static java.lang.String trim(java.lang.String s)
trim String (if not null)- Parameters:
s
- String to trim- Returns:
- String (may be null)
-
zeropad
public static java.lang.String zeropad(java.lang.String s, int len) throws ISOException
left pad with '0'- Parameters:
s
- - original stringlen
- - desired len- Returns:
- zero padded string
- Throws:
ISOException
- if string's length greater than len
-
zeropad
public static java.lang.String zeropad(long l, int len)
zeropads a long without throwing an ISOException (performs modulus operation)- Parameters:
l
- the longlen
- the length- Returns:
- zeropadded value
-
strpad
public static java.lang.String strpad(java.lang.String s, int len)
pads to the right- Parameters:
s
- - original stringlen
- - desired len- Returns:
- space padded string
-
zeropadRight
public static java.lang.String zeropadRight(java.lang.String s, int len)
-
str2bcd
public static byte[] str2bcd(java.lang.String s, boolean padLeft, byte[] d, int offset)
converts to BCD- Parameters:
s
- - the numberpadLeft
- - flag indicating left/right paddingd
- The byte array to copy into.offset
- Where to start copying into.- Returns:
- BCD representation of the number
-
str2hex
public static byte[] str2hex(java.lang.String s, boolean padLeft, byte[] d, int offset)
converts to BCD- Parameters:
s
- - the numberpadLeft
- - flag indicating left/right paddingd
- The byte array to copy into.offset
- Where to start copying into.- Returns:
- BCD representation of the number
-
str2bcd
public static byte[] str2bcd(java.lang.String s, boolean padLeft)
converts to BCD- Parameters:
s
- - the numberpadLeft
- - flag indicating left/right padding- Returns:
- BCD representation of the number
-
str2bcd
public static byte[] str2bcd(java.lang.String s, boolean padLeft, byte fill)
converts to BCD- Parameters:
s
- - the numberpadLeft
- - flag indicating left/right paddingfill
- - fill value- Returns:
- BCD representation of the number
-
bcd2str
public static java.lang.String bcd2str(byte[] b, int offset, int len, boolean padLeft)
converts a BCD representation of a number to a String- Parameters:
b
- - BCD representationoffset
- - starting offsetlen
- - BCD field lenpadLeft
- - was padLeft packed?- Returns:
- the String representation of the number
-
hex2str
public static java.lang.String hex2str(byte[] b, int offset, int len, boolean padLeft)
converts a a byte array to a String with padding support- Parameters:
b
- - HEX representationoffset
- - starting offsetlen
- - BCD field lenpadLeft
- - was padLeft packed?- Returns:
- the String representation of the number
-
hexString
public static java.lang.String hexString(byte[] b)
converts a byte array to hex string (suitable for dumps and ASCII packaging of Binary fields- Parameters:
b
- - byte array- Returns:
- String representation
-
dumpString
public static java.lang.String dumpString(byte[] b)
converts a byte array to printable characters- Parameters:
b
- - byte array- Returns:
- String representation
-
hexString
public 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- Parameters:
b
- - byte arrayoffset
- - starting positionlen
- the length- Returns:
- String representation
-
bitSet2String
public static java.lang.String bitSet2String(java.util.BitSet b)
bit representation of a BitSet suitable for dumps and debugging- Parameters:
b
- - the BitSet- Returns:
- string representing the bits (i.e. 011010010...)
-
bitSet2byte
public 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))- Parameters:
b
- - the BitSet- Returns:
- binary representation
-
bitSet2byte
public 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))- Parameters:
b
- - the BitSetbytes
- - number of bytes to return- Returns:
- binary representation
-
bitSet2Int
public static int bitSet2Int(java.util.BitSet bs)
-
int2BitSet
public static java.util.BitSet int2BitSet(int value)
-
int2BitSet
public static java.util.BitSet int2BitSet(int value, int offset)
-
byte2BitSet
public static java.util.BitSet byte2BitSet(byte[] b, int offset, boolean bitZeroMeansExtended)
Converts a binary representation of a Bitmap field into a Java BitSet- Parameters:
b
- - binary representationoffset
- - staring offsetbitZeroMeansExtended
- - true for ISO-8583- Returns:
- java BitSet object
-
byte2BitSet
public static java.util.BitSet byte2BitSet(byte[] b, int offset, int maxBits)
Converts a binary representation of a Bitmap field into a Java BitSet- Parameters:
b
- - binary representationoffset
- - staring offsetmaxBits
- - max number of bits (supports 64,128 or 192)- Returns:
- java BitSet object
-
byte2BitSet
public 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. The byte[] will be fully consumed, and fed into the given BitSet starting at bitOffset+1- Parameters:
bmap
- - BitSetb
- - hex representationbitOffset
- - (i.e. 0 for primary bitmap, 64 for secondary)- Returns:
- the same java BitSet object given as first argument
-
hex2BitSet
public static java.util.BitSet hex2BitSet(byte[] b, int offset, boolean bitZeroMeansExtended)
Converts an ASCII representation of a Bitmap field into a Java BitSet- Parameters:
b
- - hex representationoffset
- - starting offsetbitZeroMeansExtended
- - true for ISO-8583- Returns:
- java BitSet object
-
hex2BitSet
public static java.util.BitSet hex2BitSet(byte[] b, int offset, int maxBits)
Converts an ASCII representation of a Bitmap field into a Java BitSet- Parameters:
b
- - hex representationoffset
- - starting offsetmaxBits
- - max number of bits (supports 8, 16, 24, 32, 48, 52, 64,.. 128 or 192)- Returns:
- java BitSet object
-
hex2BitSet
public 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- Parameters:
bmap
- - BitSetb
- - hex representationbitOffset
- - (i.e. 0 for primary bitmap, 64 for secondary)- Returns:
- java BitSet object
-
hex2byte
public static byte[] hex2byte(byte[] b, int offset, int len)
- Parameters:
b
- source byte arrayoffset
- starting offsetlen
- number of bytes in destination (processes len*2)- Returns:
- byte[len]
-
hex2byte
public static byte[] hex2byte(java.lang.String s)
Converts a hex string into a byte array- Parameters:
s
- source string (with Hex representation)- Returns:
- byte array
-
hex2byte
public static byte[] hex2byte(java.lang.String s, java.nio.charset.Charset charset)
Converts a hex string into a byte array- Parameters:
s
- source string (with Hex representation)charset
- character set to be used- Returns:
- byte array
-
byte2hex
public static java.lang.String byte2hex(byte[] bs)
Converts a byte array into a hex string- Parameters:
bs
- source byte array- Returns:
- hexadecimal representation of bytes
-
int2byte
public static byte[] int2byte(int value)
Converts an integer into a byte array of hex- Parameters:
value
-- Returns:
- bytes representation of integer
-
byte2int
public static int byte2int(byte[] bytes)
Converts a byte array of hex into an integer- Parameters:
bytes
-- Returns:
- integer representation of bytes
-
byte2hex
public static java.lang.String byte2hex(byte[] bs, int off, int length)
Converts a byte array into a string of lower case hex chars.- Parameters:
bs
- A byte arrayoff
- The index of the first byte to readlength
- The number of bytes to read.- Returns:
- the string of hex chars.
-
formatDouble
public static java.lang.String formatDouble(double d, int len)
format double value- Parameters:
d
- the amountlen
- the field len- Returns:
- a String of fieldLen characters (right justified)
-
formatAmount
public static java.lang.String formatAmount(long l, int len) throws ISOException
prepare long value used as amount for display (implicit 2 decimals)- Parameters:
l
- valuelen
- display len- Returns:
- formated field
- Throws:
ISOException
-
normalize
public static java.lang.String normalize(java.lang.String s, boolean canonical)
XML normalizer- Parameters:
s
- source Stringcanonical
- true if we want to normalize \r and \n as well- Returns:
- normalized string suitable for XML Output
-
stripUnicode
public static java.lang.String stripUnicode(java.lang.String s)
-
normalize
public static java.lang.String normalize(java.lang.String s)
XML normalizer (default canonical)- Parameters:
s
- source String- Returns:
- normalized string suitable for XML Output
-
protect
public static java.lang.String protect(java.lang.String s, char mask)
Protects PAN, Track2, CVC (suitable for logs)."40000101010001" is converted to "400001____0001" "40000101010001=020128375" is converted to "400001____0001=0201_____" "40000101010001D020128375" is converted to "400001____0001D0201_____" "123" is converted to "___"
- Parameters:
s
- string to be protectedmask
- char used to protect the string- Returns:
- 'protected' String
-
protect
public static java.lang.String protect(java.lang.String s)
-
toIntArray
public static int[] toIntArray(java.lang.String s)
-
toStringArray
public static java.lang.String[] toStringArray(java.lang.String s)
-
xor
public static byte[] xor(byte[] op1, byte[] op2)
Bitwise XOR between corresponding bytes- Parameters:
op1
- byteArray1op2
- byteArray2- Returns:
- an array of length = the smallest between op1 and op2
-
hexor
public static java.lang.String hexor(java.lang.String op1, java.lang.String op2)
Bitwise XOR between corresponding byte arrays represented in hex- Parameters:
op1
- hexstring 1op2
- hexstring 2- Returns:
- an array of length = the smallest between op1 and op2
-
trim
public static byte[] trim(byte[] array, int length)
Trims a byte[] to a certain length- Parameters:
array
- the byte[] to be trimmedlength
- the wanted length- Returns:
- the trimmed byte[]
-
concat
public static byte[] concat(byte[] array1, byte[] array2)
Concatenates two byte arrays (array1 and array2)- Parameters:
array1
- first partarray2
- last part- Returns:
- the concatenated array
-
concat
public static byte[] concat(byte[] array1, int beginIndex1, int length1, byte[] array2, int beginIndex2, int length2)
Concatenates two byte arrays (array1 and array2)- Parameters:
array1
- first partbeginIndex1
- initial indexlength1
- lengtharray2
- last partbeginIndex2
- last part indexlength2
- last part length- Returns:
- the concatenated array
-
sleep
public static void sleep(long millis)
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds. The thread does not lose ownership of any monitors. This is the same as Thread.sleep () without throwing InterruptedException- Parameters:
millis
- the length of time to sleep in milliseconds.
-
zeroUnPad
public static java.lang.String zeroUnPad(java.lang.String s)
Left unPad with '0'- Parameters:
s
- - original string- Returns:
- zero unPadded string
-
blankUnPad
public static java.lang.String blankUnPad(java.lang.String s)
Right unPad with ' '- Parameters:
s
- - original string- Returns:
- blank unPadded string
-
unPadRight
public static java.lang.String unPadRight(java.lang.String s, char c)
Unpad from right.- Parameters:
s
- - original stringc
- - padding char- Returns:
- unPadded string.
-
unPadLeft
public static java.lang.String unPadLeft(java.lang.String s, char c)
Unpad from left.- Parameters:
s
- - original stringc
- - padding char- Returns:
- unPadded string.
-
isZero
public static boolean isZero(java.lang.String s)
- Returns:
- true if the string is zero-filled ( 0 char filled )
-
isBlank
public static boolean isBlank(java.lang.String s)
- Returns:
- true if the string is blank filled (space char filled)
-
isAlphaNumeric
public static boolean isAlphaNumeric(java.lang.String s)
Return true if the string is alphanum.{letter digit (.) (_) (-) ( ) (?) }
-
isNumeric
public static boolean isNumeric(java.lang.String s, int radix)
Return true if the string represent a number in the specified radix.
-
bitSet2extendedByte
public static byte[] bitSet2extendedByte(java.util.BitSet b)
Converts a BitSet into an extended binary field used in pack routines. The result is always in the extended format: (16 bytes of length)- Parameters:
b
- the BitSet- Returns:
- binary representation
-
parseInt
public static int parseInt(java.lang.String s, int radix) throws java.lang.NumberFormatException
Converts a String to an integer of base radix.
String constraints are:- Number must be less than 10 digits
- Number must be positive
- Parameters:
s
- String representation of numberradix
- Number base to use- Returns:
- integer value of number
- Throws:
java.lang.NumberFormatException
-
parseInt
public static int parseInt(java.lang.String s) throws java.lang.NumberFormatException
Converts a String to an integer of radix 10.
String constraints are:- Number must be less than 10 digits
- Number must be positive
- Parameters:
s
- String representation of number- Returns:
- integer value of number
- Throws:
java.lang.NumberFormatException
-
parseInt
public static int parseInt(char[] cArray, int radix) throws java.lang.NumberFormatException
Converts a character array to an integer of base radix.
Array constraints are:- Number must be less than 10 digits
- Number must be positive
- Parameters:
cArray
- Character Array representation of numberradix
- Number base to use- Returns:
- integer value of number
- Throws:
java.lang.NumberFormatException
-
parseInt
public static int parseInt(char[] cArray) throws java.lang.NumberFormatException
Converts a character array to an integer of radix 10.
Array constraints are:- Number must be less than 10 digits
- Number must be positive
- Parameters:
cArray
- Character Array representation of number- Returns:
- integer value of number
- Throws:
java.lang.NumberFormatException
-
parseInt
public static int parseInt(byte[] bArray, int radix) throws java.lang.NumberFormatException
Converts a byte array to an integer of base radix.
Array constraints are:- Number must be less than 10 digits
- Number must be positive
- Parameters:
bArray
- Byte Array representation of numberradix
- Number base to use- Returns:
- integer value of number
- Throws:
java.lang.NumberFormatException
-
parseInt
public static int parseInt(byte[] bArray) throws java.lang.NumberFormatException
Converts a byte array to an integer of radix 10.
Array constraints are:- Number must be less than 10 digits
- Number must be positive
- Parameters:
bArray
- Byte Array representation of number- Returns:
- integer value of number
- Throws:
java.lang.NumberFormatException
-
hexdump
public static java.lang.String hexdump(byte[] b)
- Parameters:
b
- a byte[] buffer- Returns:
- hexdump
-
hexdump
public static java.lang.String hexdump(byte[] b, int offset)
- Parameters:
b
- a byte[] bufferoffset
- starting offset
-
hexdump
public static java.lang.String hexdump(byte[] b, int offset, int len)
- Parameters:
b
- a byte[] bufferoffset
- starting offsetlen
- the Length- Returns:
- hexdump
-
strpadf
public static java.lang.String strpadf(java.lang.String s, int len)
pads a string with 'F's (useful for pinoffset management)- Parameters:
s
- an [hex]stringlen
- desired length- Returns:
- string right padded with 'F's
-
trimf
public static java.lang.String trimf(java.lang.String s)
reverse the effect of strpadf- Parameters:
s
- F padded string- Returns:
- trimmed string
-
takeLastN
public static java.lang.String takeLastN(java.lang.String s, int n) throws ISOException
return the last n characters of the passed String, left padding where required with 0- Parameters:
s
- String to take fromn
- nuber of characters to take- Returns:
- String (may be null)
- Throws:
ISOException
-
takeFirstN
public static java.lang.String takeFirstN(java.lang.String s, int n) throws ISOException
return the first n characters of the passed String, left padding where required with 0- Parameters:
s
- String to take fromn
- nuber of characters to take- Returns:
- String (may be null)
- Throws:
ISOException
-
millisToString
public static java.lang.String millisToString(long millis)
-
formatAmountConversionRate
public static java.lang.String formatAmountConversionRate(double convRate) throws ISOException
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. Positions 2–8 of this data element specify the rate. For example, a conversion rate value of 91234567 in this data element would equate to 0.001234567.- Parameters:
convRate
- - amount conversion rate- Returns:
- a string containing a amount conversion rate in the proper format, witch is suitable for create fields 10 and 11
- Throws:
ISOException
-
parseAmountConversionRate
public static double parseAmountConversionRate(java.lang.String convRate)
Parse currency amount conversion rate string Suitble for parse fields 10 and 11- Parameters:
convRate
- amount conversation rate- Returns:
- parsed currency amount conversation rate
- Throws:
java.lang.IllegalArgumentException
-
commaEncode
public static java.lang.String commaEncode(java.lang.String... ss)
Converts a string[] or multiple strings into one comma-delimited String. Takes care of escaping commas using a backlash- Parameters:
ss
- string array to be comma encoded- Returns:
- comma encoded string
- See Also:
commaDecode(String)
-
commaDecode
public static java.lang.String[] commaDecode(java.lang.String s)
Decodes a comma encoded String as encoded by commaEncode- Parameters:
s
- the command encoded String- Returns:
- String[]
- See Also:
commaEncode(String[])
-
commaDecode
public static java.lang.String commaDecode(java.lang.String s, int i)
Decodes a comma encoded String returning element in position i- Parameters:
s
- comma encoded stringi
- position (starts at 0)- Returns:
- element in position i of comma encoded string, or null
-
calcLUHN
public static char calcLUHN(java.lang.String p)
Compute card's check digit (LUHN)- Parameters:
p
- PAN (without checkdigit)- Returns:
- the checkdigit
-
getRandomDigits
public static java.lang.String getRandomDigits(java.util.Random r, int l, int radix)
-
readableFileSize
public static java.lang.String readableFileSize(long size)
-
hexDump
public 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. The charset will allow printing of more printable character. Usually when your data is in EBCDIC format you will run into this. The standard hexdump that exists would print a byte array of F0F1F2 as F0 F1 F2 ... This hexdump, if the Charset.forName("IBM1047") is passedin as charset will print F0 F1 F2 | 123- Parameters:
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.- Returns:
- The hexdump string.
-
decodeHexDump
public static byte[] decodeHexDump(java.lang.String s)
-
charEncode
public static java.lang.String charEncode(char delimiter, java.lang.String... ss)
Converts a string[] or multiple strings into one char-delimited String. Takes care of escaping char using a backlash NOTE: for backward compatibility, an empty String returns a zero-length array- Parameters:
delimiter
- char used to delimitss
- string array to be char encoded- Returns:
- char encoded string
- See Also:
charDecode(char, String)
-
charDecode
public static java.lang.String[] charDecode(char delimiter, java.lang.String s)
Decodes a char encoded String as encoded by charEncode- Parameters:
delimiter
- char used to delimits
- the char encoded String- Returns:
- String[]
- See Also:
charEncode(char, String[])
-
charDecode
public static java.lang.String charDecode(java.lang.String s, char delimiter, int i)
Decodes a char encoded String returning element in position i- Parameters:
s
- comma encoded stringdelimiter
- char used to delimiti
- position (starts at 0)- Returns:
- element in position i of comma encoded string, or empty
-
-