public void interpret(String data, byte[] targetArray, int offset) { boolean negative = data.startsWith("-"); if (negative) { ISOUtil.asciiToEbcdic(data.substring(1), targetArray, offset); targetArray[offset + data.length() - 2] = (byte) (targetArray[offset + data.length() - 2] & 0xDF); } else { ISOUtil.asciiToEbcdic(data, targetArray, offset); } }
/** * @param c - a component * @return packed component * @exception ISOException */ public byte[] pack(ISOComponent c) throws ISOException { boolean odd = false; int len; String s = (String) c.getValue(); if ((len = s.length()) > getLength() || len > 99) // paranoia settings throw new ISOException("invalid len " + len + " packing IFEB_LLLNUM field " + c.getKey()); // System.out.println("String s = (String) c.getValue(); "+s); // if odd length if ((len % 2) == 1) { odd = true; len = (len / 2) + 1; } else { odd = false; len = len / 2; } // System.out.println("len= "+ len +" s.length()= "+len); String fieldLength = ISOUtil.zeropad(Integer.toString(len), 3); byte[] EBCDIClength = ISOUtil.asciiToEbcdic(fieldLength); // bcd stuff byte[] bcd = ISOUtil.str2bcd(s, false); if (odd) bcd[len - 1] = (byte) (bcd[len - 1] | 0xf); // System.out.println("bcd2str "+ISOUtil.bcd2str(bcd, 0, bcd.length*2, false) ); byte[] b = new byte[bcd.length + 3]; b[0] = EBCDIClength[0]; b[1] = EBCDIClength[1]; b[2] = EBCDIClength[2]; System.arraycopy(bcd, 0, b, 3, bcd.length); return b; }