public String uninterpret(byte[] rawData, int offset, int length) { boolean negative = (byte) (rawData[offset + length - 1] & 0xF0) == (byte)0xD0; rawData[offset + length - 1] = (byte) (rawData[offset + length - 1] | 0xF0); return (negative ? "-" : "") + ISOUtil.ebcdicToAscii(rawData, offset, length); }
/** * (non-Javadoc) * */ public String uninterpret(byte[] rawData, int offset, int length) { return ISOUtil.ebcdicToAscii(rawData, offset, length); }
public static byte[] ebcdicToAsciiBytes (byte[] e, int offset, int len) { return ebcdicToAscii(e, offset, len).getBytes(CHARSET); } public static byte[] asciiToEbcdic(String s) {
/** * @param c - the Component to unpack * @param b - binary image * @param offset - starting offset within the binary image * @return consumed bytes * @exception ISOException */ public int unpack (ISOComponent c, byte[] b, int offset) throws ISOException { int len = Integer.parseInt(ISOUtil.ebcdicToAscii(b, offset, prefixerPackedLength)) - TAG_HEADER_LENGTH; if (!(c instanceof ISOBinaryField)) throw new ISOException (c.getClass().getName() + " is not an ISOBinaryField"); c.setFieldNumber ( Integer.parseInt(ISOUtil.ebcdicToAscii (b, offset+prefixerPackedLength, TAG_HEADER_LENGTH)) ); byte[] value = new byte[len]; System.arraycopy(b, offset + prefixerPackedLength + TAG_HEADER_LENGTH , value, 0, len); c.setValue (value); return len + prefixerPackedLength + TAG_HEADER_LENGTH; } public void unpack (ISOComponent c, InputStream in)
/** * @param c - the Component to unpack * @param b - binary image * @param offset - starting offset within the binary image * @return consumed bytes * @exception ISOException */ public int unpack (ISOComponent c, byte[] b, int offset) throws ISOException { int len = Integer.parseInt(ISOUtil.ebcdicToAscii(b, offset, 3)) - 2; if (!(c instanceof ISOField)) throw new ISOException (c.getClass().getName() + " is not an ISOField"); c.setFieldNumber ( Integer.parseInt(ISOUtil.ebcdicToAscii (b, offset+3, 2)) ); c.setValue (new String (b, offset+5, len)); return len + 5; } public void unpack (ISOComponent c, InputStream in)
public void unpack (ISOComponent c, InputStream in) throws IOException, ISOException { if (!(c instanceof ISOField)) throw new ISOException (c.getClass().getName() + " is not an ISOField"); int len = Integer.parseInt(ISOUtil.ebcdicToAscii(readBytes (in, prefixerPackedLength))) - TAG_HEADER_LENGTH; int fldno = Integer.parseInt(ISOUtil.ebcdicToAscii(readBytes (in, TAG_HEADER_LENGTH))); c.setFieldNumber (fldno); c.setValue (readBytes(in, len)); } public int getMaxPackedLength() {
public void unpack (ISOComponent c, InputStream in) throws IOException, ISOException { if (!(c instanceof ISOField)) throw new ISOException (c.getClass().getName() + " is not an ISOField"); int len = Integer.parseInt(ISOUtil.ebcdicToAscii(readBytes (in, 3))) - 2; int fldno = Integer.parseInt(ISOUtil.ebcdicToAscii(readBytes (in, 2))); c.setFieldNumber (fldno); c.setValue (new String (readBytes (in, len))); }
@Test(expected=IndexOutOfBoundsException.class) public void testEbcdicToAsciiThrowsArrayIndexOutOfBoundsException() throws Throwable { ISOUtil.ebcdicToAscii(new byte[1], 100, 1000); }
@Test(expected = IndexOutOfBoundsException.class) public void testEbcdicToAsciiThrowsNegativeArraySizeException() throws Throwable { ISOUtil.ebcdicToAscii(new byte[1], 100, -1); }
@Test(expected = NullPointerException.class) public void testEbcdicToAsciiThrowsNullPointerException() throws Throwable { ISOUtil.ebcdicToAscii(null); }
/** * @param c - the Component to unpack * @param b - binary image * @param offset - starting offset within the binary image * @return consumed bytes * @exception ISOException */ public int unpack (ISOComponent c, byte[] b, int offset) throws ISOException { c.setValue(ISOUtil.ebcdicToAscii(b, offset, getLength())); return getLength(); } public int getMaxPackedLength() {
@Test public void testEbcdicToAscii1() throws Throwable { byte[] e = new byte[3]; String result = ISOUtil.ebcdicToAscii(e, 0, 1); assertEquals("result", "\u0000", result); }
@Test public void testEbcdicToAscii() throws Throwable { byte[] e = new byte[2]; String result = ISOUtil.ebcdicToAscii(e); assertEquals("result", "\u0000\u0000", result); }
public int unpack(ISOComponent m, byte[] b) throws ISOException { // Unpack the IF_CHAR field int consumed = 0; ISOComponent c; if (fld[0] != null && b[consumed] == 0x20) { // Hack to support a nine-byte filler c = fld[0].createComponent(0); consumed += fld[0].unpack(c, b, consumed); m.set(c); } // Now unpack the IFEP_LLCHAR fields for (; consumed < b.length;) { int fieldNumber = Integer.parseInt(ISOUtil.ebcdicToAscii(b, consumed + 3, 2)); if (fld[fieldNumber] == null) break; c = fld[fieldNumber].createComponent(fieldNumber); consumed += fld[fieldNumber].unpack(c, b, consumed); m.set(c); } return consumed; } }