/** * @param c - a component * @return packed component * @exception ISOException */ public byte[] pack (ISOComponent c) throws ISOException { return ISOUtil.bitSet2byte ((BitSet) c.getValue()); } /**
/** * @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(); }
/** * @param c - a component * @return packed component * @exception ISOException */ public byte[] pack (ISOComponent c) throws ISOException { BitSet b = (BitSet) c.getValue(); int len = // bytes needed to encode BitSet (in 8-byte chunks) getLength() >= 8 ? b.length()+62 >>6 <<3 : getLength(); // +62 because we don't use bit 0 in the BitSet return ISOUtil.bitSet2byte (b, len); } /**
@Test(expected = NullPointerException.class) public void testBitSet2byteThrowsNullPointerException() throws Throwable { ISOUtil.bitSet2byte(null); }
@Test public void testBitSet2byte3() throws Throwable { byte[] result = ISOUtil.bitSet2byte(new BitSet(100)); assertEquals("result.length", 0, result.length); }
@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); }
byte[] b = ISOUtil.bitSet2byte (bitMapValue, requiredBitMapLengthInBytes); return ISOUtil.asciiToEbcdic(ISOUtil.hexString(b).getBytes());
@Test public void testBitSet2byte() throws Throwable { byte[] b = new byte[1]; BitSet bmap = new BitSet(); ISOUtil.hex2BitSet(bmap, b, 0); byte[] b2 = new byte[0]; ISOUtil.hex2BitSet(bmap, b2, -1); BitSet b3 = new BitSet(100); b3.or(bmap); byte[] result = ISOUtil.bitSet2byte(b3); assertEquals("result.length", 8, result.length); assertEquals("result[0]", (byte) -16, result[0]); }
@Test public void testBitSetByteHexInteroperability3() throws Throwable { byte[] b = ISOUtil.hex2byte("F23C04800AE00000800000000000010863BC780000000010"); 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 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))); }