public void testReversability() throws Exception { byte[] origin = new byte[] {0x12, 0x34, 0x56, 0x78}; ISOBinaryField f = new ISOBinaryField(12, origin); IFB_LLLBINARY packager = new IFB_LLLBINARY(100, "Should be 12345678"); ISOBinaryField unpack = new ISOBinaryField(12); packager.unpack(unpack, packager.pack(f), 0); TestUtils.assertEquals(origin, (byte[])unpack.getValue()); }
/** * @param c - the Component to unpack * @param in - input stream * @throws org.jpos.iso.ISOException * @throws java.io.IOException */ @Override public void unpack (ISOComponent c, InputStream in) throws IOException, ISOException { ISOBinaryField f = new ISOBinaryField(0); if(msgPackager instanceof ISOSubFieldPackager) { ISOSubFieldPackager sfp = (ISOSubFieldPackager) msgPackager; f.setFieldNumber(sfp.getFieldNumber()); } fieldPackager.unpack (f, in); if (f.getValue() != null && c instanceof ISOMsg) msgPackager.unpack(c, (byte[]) f.getValue()); }
/** * dump this field to PrintStream. The output is sorta * XML, intended to be easily parsed. * @param p - print stream * @param indent - optional indent string */ public void dump (PrintStream p, String indent) { p.println (indent +"<"+XMLPackager.ISOFIELD_TAG + " " + XMLPackager.ID_ATTR +"=\"" +fieldNumber +"\" "+ XMLPackager.VALUE_ATTR +"=\"" +this.toString() + "\" " + XMLPackager.TYPE_ATTR +"=\"" + XMLPackager.TYPE_BINARY + "\"/>" ); } public String toString() {
/** * @param c - a component * @return packed component * @exception ISOException */ @Override public byte[] pack (ISOComponent c) throws ISOException { if (c instanceof ISOMsg) { ISOMsg m = (ISOMsg) c; m.recalcBitMap(); ISOBinaryField f = new ISOBinaryField(0, msgPackager.pack(m)); if(fieldPackager instanceof TaggedFieldPackagerBase && msgPackager instanceof ISOSubFieldPackager) { ISOSubFieldPackager sfp = (ISOSubFieldPackager) msgPackager; f.setFieldNumber(sfp.getFieldNumber()); } return fieldPackager.pack(f); } return fieldPackager.pack(c); }
/** * component factory * @param fieldNumber - the field number * @return the newly created component */ public ISOComponent createComponent(int fieldNumber) { return new ISOBinaryField (fieldNumber); }
@Test public void testUnpackThrowsNullPointerException() throws Throwable { Base1_BITMAP126 base1_BITMAP126 = new Base1_BITMAP126(100, "testBase1_BITMAP126Description"); ISOComponent c = new ISOBinaryField(100); try { base1_BITMAP126.unpack(c, null, 100); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertNull("(ISOBinaryField) c.getBytes()", ((ISOBinaryField) c).getBytes()); } } }
public ISOComponent createComponent(int fieldNumber) { return new ISOBinaryField (fieldNumber); } public int getMaxPackedLength() {
public void testReversability() throws Exception { byte[] origin = new byte[] {0x12, 0x34, 0x56, 0x78}; ISOBinaryField f = new ISOBinaryField(12, origin); IFA_BINARY packager = new IFA_BINARY(4, "Should be 12345678"); ISOBinaryField unpack = new ISOBinaryField(12); packager.unpack(unpack, packager.pack(f), 0); TestUtils.assertEquals(origin, (byte[])unpack.getValue()); } }
public ISOComponent createComponent(int fieldNumber) { return new ISOBinaryField (fieldNumber); } public int getMaxPackedLength() {
/** * @param c - the Component to unpack * @param b - binary image * @param offset - starting offset within the binary image * @return consumed bytes * @exception ISOException */ @Override public int unpack (ISOComponent c, byte[] b, int offset) throws ISOException { ISOBinaryField f = new ISOBinaryField(0); if(msgPackager instanceof ISOSubFieldPackager) { ISOSubFieldPackager sfp = (ISOSubFieldPackager) msgPackager; f.setFieldNumber(sfp.getFieldNumber()); } int consumed = fieldPackager.unpack(f, b, offset); if (f.getValue() != null && c instanceof ISOMsg) msgPackager.unpack(c, (byte[]) f.getValue()); return consumed; }
public void testReversability() throws Exception { byte[] origin = new byte[] {0x12, 0x34, 0x56, 0x78}; ISOBinaryField f = new ISOBinaryField(12, origin); IFB_LLHFBINARY packager = new IFB_LLHFBINARY(10, "Should be 12345678"); ISOBinaryField unpack = new ISOBinaryField(12); packager.unpack(unpack, packager.pack(f), 0); TestUtils.assertEquals(origin, (byte[])unpack.getValue()); } }
public ISOComponent createComponent(int fieldNumber) { return new ISOBinaryField (fieldNumber); } public int getMaxPackedLength() {
public void testReversability() throws Exception { byte[] origin = new byte[] {0x12, 0x34, 0x56, 0x78}; ISOBinaryField f = new ISOBinaryField(12, origin); IFB_LLLHBINARY packager = new IFB_LLLHBINARY(10, "Should be 12345678"); ISOBinaryField unpack = new ISOBinaryField(12); packager.unpack(unpack, packager.pack(f), 0); TestUtils.assertEquals(origin, (byte[])unpack.getValue()); } }
/** * Creates an ISOBinaryField associated with fldno within this ISOMsg. * * @param fldno field number * @param value field value */ public void set(int fldno, byte[] value) { if (value == null) { unset(fldno); return; } try { set(new ISOBinaryField(fldno, value)); } catch (ISOException ex) {}; //NOPMD: never happens for the given arguments of set methods }
public void testReversability() throws Exception { byte[] origin = new byte[] {0x12, 0x34, 0x56, 0x78}; ISOBinaryField f = new ISOBinaryField(12, origin); IFA_LLLBINARY packager = new IFA_LLLBINARY(4, "Should be 12345678"); ISOBinaryField unpack = new ISOBinaryField(12); packager.unpack(unpack, packager.pack(f), 0); TestUtils.assertEquals(origin, (byte[])unpack.getValue()); } }
throw new SAXException ("invalid field"); if (TYPE_BINARY.equals (type)) { m.set (new ISOBinaryField ( fieldNumber, ISOUtil.hex2byte (
public void testReversability() throws Exception { byte[] origin = new byte[] {0x12, 0x34, 0x56, 0x78}; ISOBinaryField f = new ISOBinaryField(12, origin); IFB_LLBINARY packager = new IFB_LLBINARY(4, "Should be 12345678"); ISOBinaryField unpack = new ISOBinaryField(12); packager.unpack(unpack, packager.pack(f), 0); TestUtils.assertEquals(origin, (byte[])unpack.getValue()); } }
public static void runPack(String packagerName, int len, byte[] data) throws Exception { Class packagerClass = Class.forName(packagerName); ISOFieldPackager packager = (ISOFieldPackager)packagerClass.newInstance(); packager.setLength(len); ISOBinaryField f = new ISOBinaryField(12, data); long start = System.currentTimeMillis(); runPackTest(packager, f); long end = System.currentTimeMillis(); boolean isOldImplementation = packagerClass.getSuperclass().getName().endsWith("ISOFieldPackager") || packagerClass.getSuperclass().getName().endsWith("IF_TBASE"); System.out.println("Pack: " + (isOldImplementation ? "old " : "new ") + packager.getClass().getName() + " = " + (end - start)); }
public void testReversability() throws Exception { byte[] origin = new byte[] {0x12, 0x34, 0x56, 0x78}; ISOBinaryField f = new ISOBinaryField(12, origin); IFB_BINARY packager = new IFB_BINARY(4, "Should be 12345678"); ISOBinaryField unpack = new ISOBinaryField(12); packager.unpack(unpack, packager.pack(f), 0); TestUtils.assertEquals(origin, (byte[])unpack.getValue()); } }
ic = new ISOBinaryField ( fieldNumber, ISOUtil.hex2byte (