public static byte[] decode(String string)
    {
        if (string.length() % 5 != 0) {
            return null;
        }
        ByteBuffer buf = ByteBuffer.allocate(string.length() * 4 / 5);

        int byteNbr = 0;
        int charNbr = 0;
        int stringLen = string.length();
        long value = 0;
        while (charNbr < stringLen) {
            //  Accumulate value in base 85
            value = value * 85 + (decoder[string.charAt(charNbr++) - 32] & 0xff);
            if (charNbr % 5 == 0) {
                //  Output value in base 256
                int divisor = 256 * 256 * 256;
                while (divisor != 0) {
                    buf.put(byteNbr++, (byte) ((value / divisor) % 256));
                    divisor /= 256;
                }
                value = 0;
            }
        }
        assert (byteNbr == string.length() * 4 / 5);
        return buf.array();
    }
public static byte [ ] decode ( String string ) { if ( string . length ( ) % 5 != 0 ) { return null ; } ByteBuffer buf = ByteBuffer . allocate ( string . length ( ) * 4 / 5 ) ; int byteNbr = 0 ; int charNbr = 0 ; int stringLen = string . length ( ) ; long value = 0 ; while ( charNbr < stringLen ) { value = value * 85 + ( decoder [ string . charAt ( charNbr ++ ) - 32 ] & 0xff ) ; if ( charNbr % 5 == 0 ) { int divisor = 256 * 256 * 256 ; while ( divisor != 0 ) { buf . put ( byteNbr ++ , ( byte ) ( ( value / divisor ) % 256 ) ) ; divisor /= 256 ; } value = 0 ; } } assert ( byteNbr == string . length ( ) * 4 / 5 ) ; return buf . array ( ) ; }
Returns NULL and sets errno = EINVAL for invalid input.