public byte[] uninterpret(byte[] rawData, int offset, int length) { return ISOUtil.ebcdicToAsciiBytes(rawData, offset, length); }
public static byte[] ebcdicToAsciiBytes (byte[] e) { return ebcdicToAsciiBytes (e, 0, e.length); } public static byte[] ebcdicToAsciiBytes (byte[] e, int offset, int len) {
public void unpack (ISOComponent c, InputStream in) throws IOException, ISOException { byte [] b1 = ISOUtil.ebcdicToAsciiBytes (readBytes (in, 16), 0, 16); BitSet bmap = ISOUtil.hex2BitSet (new BitSet (64), b1, 0); if (getLength() > 8 && bmap.get (1)) { byte [] b2 = ISOUtil.ebcdicToAsciiBytes (readBytes (in, 16), 0, 16); ISOUtil.hex2BitSet (bmap, b2, 64); } c.setValue(bmap); } }
@Test(expected = NullPointerException.class) public void testEbcdicToAsciiBytesThrowsNullPointerException() throws Throwable { ISOUtil.ebcdicToAsciiBytes(null, 100, 1000); }
@Test(expected = NullPointerException.class) public void testEbcdicToAsciiBytesThrowsNullPointerException1() throws Throwable { ISOUtil.ebcdicToAsciiBytes(null); }
@Test(expected = IndexOutOfBoundsException.class) public void testEbcdicToAsciiBytesThrowsNegativeArraySizeException() throws Throwable { byte[] e = new byte[1]; ISOUtil.ebcdicToAsciiBytes(e, 100, -1); }
@Test(expected=IndexOutOfBoundsException.class) public void testEbcdicToAsciiBytesThrowsArrayIndexOutOfBoundsException() throws Throwable { ISOUtil.ebcdicToAsciiBytes(new byte[1], 0, 100); }
@Test(expected=IndexOutOfBoundsException.class) public void testEbcdicToAsciiBytesThrowsArrayIndexOutOfBoundsException1() throws Throwable { ISOUtil.ebcdicToAsciiBytes(new byte[1], 100, 1000); }
/** * @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 { // TODO: calculate bytes to read based on bits 1, 65 on/off in the actual data int bytes; byte [] b1 = ISOUtil.ebcdicToAsciiBytes (b, offset, getLength()*2 ); BitSet bmap = ISOUtil.hex2BitSet (b1, 0, getLength() << 3); c.setValue(bmap); bytes = b1.length; // check for 2nd bit map indicator if (bytes > 16 && !bmap.get(1)) { bytes = 16; // check for 3rd bit map indicator } else if (bytes > 32 && !bmap.get(65)) { bytes = 32; } return bytes; } public void unpack (ISOComponent c, InputStream in)
@Test public void testEbcdicToAsciiBytes2() throws Throwable { byte[] e = new byte[0]; byte[] result = ISOUtil.ebcdicToAsciiBytes(e); assertEquals("result.length", 0, result.length); }
@Test public void testEbcdicCharSet() throws Throwable { byte[] b = new byte[256]; for (int i=0; i<b.length; i++) { b[i] = ((byte) (i & 0xFF)); } String s = new String (b, ISOUtil.CHARSET); byte[] ebcdic = ISOUtil.asciiToEbcdic(s); byte[] ascii = ISOUtil.ebcdicToAsciiBytes(ebcdic); assertArrayEquals("arrays should be equal", b, ascii); Charset c = Charset.forName("IBM1047"); byte[] ebcdic1 = c.encode(s).array(); String s1 = c.decode(ByteBuffer.wrap(ebcdic1)).toString(); assertArrayEquals("arrays should match", ebcdic, ebcdic1); assertEquals ("ASCII strings should be the same", s, s1); assertArrayEquals ("byte[] should be the same as s1", b, s1.getBytes(ISOUtil.CHARSET)); assertArrayEquals ("byte[] should be the same as ascii", b, new String(ascii, ISOUtil.CHARSET).getBytes(ISOUtil.CHARSET)); }
@Test public void testEbcdicToAsciiBytes() throws Throwable { byte[] e = new byte[2]; byte[] result = ISOUtil.ebcdicToAsciiBytes(e, 0, 1); assertEquals("result.length", 1, result.length); assertEquals("result[0]", (byte) 0, result[0]); }
@Test public void testEbcdicToAsciiBytes3() throws Throwable { byte[] e = new byte[2]; byte[] result = ISOUtil.ebcdicToAsciiBytes(e); assertEquals("result.length", 2, result.length); assertEquals("result[0]", (byte) 0, result[0]); }