ISOUtil
org.jpos.iso.ISOUtil is one of jPOS's oldest and most widely used utility classes. It started life as a set of encoding converters—ASCII to BCD, ASCII to EBCDIC, and back—required internally by field packagers to handle ISO-8583 wire formats. Over the years it grew steadily, accumulating methods for string padding and trimming, byte array manipulation, BitSet handling, hex encoding/decoding, Luhn check digit calculation, amount formatting, and more.
Why it matters
It is tempting, when you need to left-pad a string or convert a hex string to bytes, to reach for a well-known library. Apache Commons Lang and Apache Commons Codec are popular choices—familiar, well-documented, and widely trusted. The problem is the dependency footprint.
A single commons-lang3 or commons-codec JAR pulls in transitive dependencies. Those dependencies have their own release cycles, their own CVEs, and their own audit surface. Payment and banking systems regularly face security audits, PCI-DSS scans, and vulnerability management processes where every JAR on the classpath must be justified. Introducing Apache Commons to pad a string to ten characters can, and does, lead to audit findings and remediation cycles that cost far more than the convenience was worth.
ISOUtil is already on the classpath in every jPOS application. It has no transitive dependencies of its own. Using it for common utility operations keeps your dependency surface minimal and your audit results clean.
What's available
The class covers a broad range of operations. A representative selection:
String padding and trimming
padleft(s, len, c)—right-alignssin a field of widthlen, padding with charactercpadright(s, len, c)—left-alignss, padding on the rightzeropad(s, len)—zero-pads a numeric string tolendigitszeropadRight(s, len)—zero-pads on the rightstrpad(s, len)—space-pads tolentrim(s)—trims trailing spacesunPadLeft(s, c)/unPadRight(s, c)—strips padding charactersblankUnPad(s)/zeroUnPad(s)—convenience variants for spaces and zeros
Substring helpers
takeFirstN(s, n)—firstncharacterstakeLastN(s, n)—lastncharacters
Encoding and conversion
str2bcd(s, padLeft)—ASCII decimal string to BCD bytesbcd2str(b, offset, len, padLeft)—BCD bytes back to stringhexString(b)—byte array to hex stringhex2byte(s)—hex string to byte arrayasciiToEbcdic(s)/ebcdicToAscii(b)—character set conversionhexdump(b)—formatted hex dump for logging
Byte array operations
xor(op1, op2)—XOR two byte arraysconcat(array1, array2)—concatenate byte arraystrim(array, length)—trim a byte array to length
BitSet utilities
bitSet2byte(b)/byte2BitSet(b, ...)—ISO-8583 bitmap conversionhex2BitSet(b, ...)—parse a hex bitmap
Numeric helpers
parseInt(s, radix)—parse integers from strings, char arrays, or byte arraysisNumeric(s, radix)/isAlphaNumeric(s)/isBlank(s)/isZero(s)—validation predicatesformatAmount(l, len)—format a long amount with implied decimal pointcalcLUHN(p)—compute the Luhn check digit of a PANformatAmountConversionRate(rate)/parseAmountConversionRate(s)—ISO 4217 rate encoding
Miscellaneous
protect(s)—mask a PAN for logging (shows first 6 and last 4)normalize(s)—strip non-printable characters for safe loggingcommaEncode(ss...)/commaDecode(s)—encode/decode string arrayssleep(millis)—interrupt-safe sleepmillisToString(millis)—human-readable duration
Before adding a dependency
Check ISOUtil first. If what you need is not there, reach out through the usual channels—the jPOS team is responsive and will consider adding a method if the use case is broadly useful. A utility method added to ISOUtil benefits every project in the ecosystem and costs nothing in dependency footprint.
If you are about to add Apache Commons, Guava, or a similar general-purpose utility library solely for string manipulation, byte handling, or encoding, check ISOUtil first. The odds are good that what you need is already there.