/** * @param c - a component * @return packed component * @exception ISOException */ public byte[] pack (ISOComponent c) throws ISOException { byte[] b = ISOUtil.bitSet2byte ((BitSet) c.getValue()); return ISOUtil.hexString(b).getBytes(); } /**
/** * @param c - a component * @return packed component * @exception ISOException */ public byte[] pack (ISOComponent c) throws ISOException { BitSet b = (BitSet) c.getValue(); int len = getLength() >= 8 ? b.length()+62 >>6 <<3 : getLength(); return ISOUtil.hexString(ISOUtil.bitSet2byte (b, len)).getBytes(); }
/** * Bitwise XOR between corresponding byte arrays represented in hex * @param op1 hexstring 1 * @param op2 hexstring 2 * @return an array of length = the smallest between op1 and op2 */ public static String hexor (String op1, String op2) { byte[] xor = xor (hex2byte (op1), hex2byte (op2)); return hexString (xor); }
protected void getMessageTrailler() throws IOException { Logger.log (new LogEvent (this, "get-message-trailler")); byte[] b = new byte[1]; serverIn.readFully(b,0,1); Logger.log (new LogEvent (this, "got-message-trailler", ISOUtil.hexString(b))); } }
@Test public void testBitSetByteHexInteroperability() throws Throwable { BitSet bs = new BitSet(); bs.set(1); bs.set(63); bs.set(127); bs.set(191); byte[] b = ISOUtil.bitSet2byte(bs); BitSet bs1 = ISOUtil.byte2BitSet(b, 0, 192); BitSet bs2 = ISOUtil.hex2BitSet(ISOUtil.hexString(b).getBytes(), 0, 192); assertEquals("BitSets should be equal", bs1, bs2); }
@Test public void testHexString2() throws Throwable { byte[] b = new byte[1]; String result = ISOUtil.hexString(b); assertEquals("result", "00", result); }
@Test public void testHexString() throws Throwable { byte[] b = new byte[2]; String result = ISOUtil.hexString(b, 0, 1); assertEquals("result", "00", result); }
@Test public void testBitSetByteHexInteroperability2() throws Throwable { byte[] b = ISOUtil.hex2byte("F23C04800EE0000080000000000000000000380000000000"); BitSet bs1 = ISOUtil.byte2BitSet(b, 0, 192); BitSet bs2 = ISOUtil.hex2BitSet (ISOUtil.hexString(b).getBytes(), 0, 192); assertEquals("BitSets should be equal", bs1, bs2); assertEquals("Image matches", ISOUtil.hexString(b), ISOUtil.hexString(ISOUtil.bitSet2byte(bs1))); }
@Test public void test32LByteBitmapWithOnly16BytesUsed() throws Exception { ISOComponent c = new ISOBitMap(1); int consumed = thirtytwoBytes.unpack(c, sixteenByteBitMapIn32Bytes,0); assertEquals("16 bytes should be consumed as the 2nd bitmap indicator is off",16,consumed); assertEquals("32 byte bitmap with just 16 bytes used should have a maximum field of ",64,((BitSet)c.getValue()).length() - 1); outBytes = sixteenBytes.pack(c); assertEquals("32 Byte (16 bytes used) bitmap pack should reflect unpack",ISOUtil.hexString(sixteenByteBitMapIn32Bytes,0,16),ISOUtil.hexString(outBytes)); }
public void test01ByteBitmapWithDataWith2ndBitMapBitOn() throws Exception { ISOComponent c = new ISOBitMap(1); int consumed = oneByte.unpack(c, DataWith2ndBitMapBitOn,0); assertEquals("1 bytes bitmap: unpack of 1 byte bitmap should consume 2 bytes in characters",2,consumed); assertEquals("1 bytes bitmap: 1 byte bitmap should result in a bitmap holding fields up to 8",8,((BitSet)c.getValue()).length() - 1); outBytes = oneByte.pack(c); assertEquals("1 bytes bitmap: pack of 1 byte bitmap must produce a result 2 bytes long",2,outBytes.length); assertEquals("1 bytes bitmap: pack of unpacked value should be the same as original", ISOUtil.hexString(DataWith2ndBitMapBitOn,0,2),ISOUtil.hexString(outBytes)); } public void test02ByteBitmapWithDataWith2ndBitMapBitOn() throws Exception
@Test public void test24ByteBitmapWithOnly16BytesUsed() throws Exception { ISOComponent c = new ISOBitMap(1); int consumed = twentyfourBytes.unpack(c, sixteenByteBitMapIn24Bytes,0); assertEquals("16 bytes should be consumed as the 2nd bitmap indicator is on, 3rd is off",16,consumed); assertEquals("24 byte bitmap with just 16 bytes used should have a maximum field of ",128,((BitSet)c.getValue()).length() - 1); outBytes = twentyfourBytes.pack(c); assertEquals("24 Byte (16 bytes used) bitmap pack should reflect unpack",ISOUtil.hexString(sixteenByteBitMapIn24Bytes,0,16),ISOUtil.hexString(outBytes)); }
public void test16ByteBitmapWithDataWith2ndBitMapBitOFF() throws Exception { ISOComponent c = new ISOBitMap(1); int consumed = sixteenBytes.unpack(c, DataWith2ndBitMapBitOff,0); assertEquals("16 bytes bitmap with data with 2nd bit map bit off: unpack of 8 bytes bitmap should consume 32 bytes in characters as the 2nd bitmap indicator is off",16,consumed); assertEquals("16 bytes bitmap with data with 2nd bit map bit off: 16 byte bitmap with 2nd bitmap idicator is off should have a maximum field of 64",64,((BitSet)c.getValue()).length() - 1); outBytes = sixteenBytes.pack(c); assertEquals("16 bytes bitmap with data with 2nd bit map bit off: pack of 64 bits bitmap with 16 bytes packager must produce a result 16 bytes long",16,outBytes.length); assertEquals("16 bytes bitmap with data with 2nd bit map bit off: pack of upacked value should be the same as original", ISOUtil.hexString(DataWith2ndBitMapBitOff,0,16),ISOUtil.hexString(outBytes)); } /*
@Test public void test24ByteBitmapWithOnly8BytesUsed() throws Exception { ISOComponent c = new ISOBitMap(1); int consumed = twentyfourBytes.unpack(c, eightByteBitMapIn24Bytes,0); assertEquals("8 bytes should be consumed as the 2nd bitmap indicator if off",8,consumed); assertEquals("24 byte bitmap with just 8 bytes used should have a maximum field of ",64,((BitSet)c.getValue()).length() - 1); outBytes = twentyfourBytes.pack(c); assertEquals("24 Byte (8 bytes used) bitmap pack should reflect unpack",ISOUtil.hexString(eightByteBitMapIn24Bytes,0,8),ISOUtil.hexString(outBytes)); }
@Test public void testHexStringThrowsArrayIndexOutOfBoundsException() throws Throwable { byte[] b = new byte[3]; try { ISOUtil.hexString(b, 100, 1000); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { assertEquals("ex.getMessage()", "100", ex.getMessage()); } }
public void testTraillingBlanksDroppedwithFS() throws Exception { String value = "123 "; String field = "testafs"; imsg.set(field, value); assertEquals("3132331C", ISOUtil.hexString(imsg .pack().getBytes())); omsg.unpack(imsg.pack().getBytes()); assertEquals("123", omsg.get(field)); }
@Test public void testThirdBitmapPack() throws Exception { byte[] b = ISOUtil.hex2byte("F23C04800AE00000800000000000010863BC780000000010"); BitSet bs1 = ISOUtil.byte2BitSet(b, 0, 192); ISOBitMap bmap = new ISOBitMap(-1); bmap.setValue(bs1); IFB_BITMAP ifb = new IFB_BITMAP(24, "BITMAP"); byte[] b1 = ifb.pack(bmap); assertEquals ("Pack should be equal to unpack", ISOUtil.hexString(b), ISOUtil.hexString(b1)); } }
@Ignore("test currently failing - debug action required TODO: CCB") @Test public void test02ByteBitmap() throws Exception { ISOComponent c = new ISOBitMap(1); int consumed = twoBytes.unpack(c, inBytes,0); assertEquals("2 characters should be consumed irrespective of 2nd, 3rd or any bitmap indicators - actually consumes: "+consumed,2,consumed); assertEquals("2 characters can only result in a bitmap holding fields up to 8",8,((BitSet)c.getValue()).length() - 1); outBytes = twoBytes.pack(c); assertEquals("Pack of two bytes must produce a result 2 bytes long",2,outBytes.length); assertEquals("2 byte bitmap pack should reflect unpack", ISOUtil.hexString(inBytes,0,2),ISOUtil.hexString(outBytes)); }
@Test public void testThirdBitmapPack() throws Exception { byte[] b = ISOUtil.hex2byte("F23C04800AE00000"+"8000000000000108"+"63BC780000000010"); BitSet bs1 = ISOUtil.byte2BitSet(b, 0, 192); ISOBitMap bmap = new ISOBitMap(-1); bmap.setValue(bs1); IFA_BITMAP ifa = new IFA_BITMAP(24, "BITMAP"); byte[] b1 = ifa.pack(bmap); assertEquals ("Pack should be equal to unpack", ISOUtil.hexString(b), new String(b1)); } }
public void testRightPad() throws Exception { String origin = "0123456789ABCDE"; ISOField f = new ISOField(12, origin); IFB_HEX packager = new IFB_HEX(origin.length(), "Should be 00123456789ABCDE", false); ISOField unpack = new ISOField(12); packager.unpack(unpack, packager.pack(f), 0); assertEquals (origin, (String) unpack.getValue()); assertEquals ("0123456789ABCDEF", ISOUtil.hexString(packager.pack(f))); } }
public void testLeftPad() throws Exception { String origin = "0123456789ABCDE"; ISOField f = new ISOField(12, origin); IFB_HEX packager = new IFB_HEX(origin.length(), "Should be 00123456789ABCDE", true); ISOField unpack = new ISOField(12); packager.unpack(unpack, packager.pack(f), 0); assertEquals (origin, (String) unpack.getValue()); assertEquals ("00123456789ABCDE", ISOUtil.hexString(packager.pack(f))); }