use of org.jpos.iso.ISOField in project jPOS by jpos.
the class ISOBaseValidatingPackagerTest method testValidateThrowsNullPOinterException1.
@Test
public void testValidateThrowsNullPOinterException1() throws Throwable {
try {
new ISOBaseValidatingPackager().validate(new ISOField(100, "testISOBaseValidatingPackagerv"));
fail("Expected ClassCastException to be thrown");
} catch (NullPointerException ex) {
assertEquals("ex.getClass()", NullPointerException.class, ex.getClass());
}
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class GICCSubFieldPackager method pack.
public byte[] pack(ISOComponent c) throws ISOException {
try {
int len = 0;
byte[] result;
Map tab = c.getChildren();
List list = new ArrayList();
// Handle first IF_CHAR field
ISOField f0 = (ISOField) tab.get(0);
if (f0 != null) {
String s = (String) f0.getValue();
list.add(s.getBytes());
len += s.getBytes().length;
}
for (int i = 1; i < fld.length; i++) {
Object obj = tab.get(i);
if (obj instanceof ISOComponent) {
ISOComponent f = (ISOComponent) obj;
byte[] b = fld[i].pack(f);
list.add(b);
len += b.length;
}
}
result = new byte[len];
int k = 0;
for (int i = 0; i < list.size(); i++) {
byte[] b = (byte[]) list.get(i);
for (int j = 0; j < b.length; j++) result[k++] = b[j];
}
return result;
} catch (Exception ex) {
throw new ISOException(ex);
}
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class ISOMultiFieldPackager method unpack.
/**
* @param m - the ISOComponent to receive the value consumed from ...
* @param b - the byte[] holding the raw message
* @param offset - the current position within b.
*/
public int unpack(ISOComponent m, byte[] b, int offset) throws ISOException {
ListIterator i = possibles.listIterator();
while (i.hasNext()) {
try {
current = (ISOFieldPackager) i.next();
ISOField f = new ISOField();
int consumed = current.unpack(f, b, offset);
m.setValue(f.getValue());
return consumed;
} catch (ISOException eok) {
current = null;
}
}
throw new ISOException("unpack failed in List process!");
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class ISOMultiFieldPackagerTest method testUnpackList.
public void testUnpackList() throws Exception {
byte[] raw = new byte[] { (byte) 0xF0, (byte) 0xF4, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3, (byte) 0xF4 };
Vector list = new Vector();
list.add(new IFB_LLNUM(10, "Should not be this", true));
list.add(new IFB_LLNUM(10, "Should not be this", true));
list.add(new IFB_LLNUM(10, "Should not be this", true));
list.add(new IFB_LLNUM(10, "Should not be this", true));
list.add(new IFB_LLNUM(10, "Should not be this", true));
list.add(new IFB_LLNUM(10, "Should not be this", true));
list.add(new IFB_LLNUM(10, "Should not be this", true));
list.add(new IFB_LLNUM(10, "Should not be this", true));
list.add(new IFB_LLNUM(10, "Should not be this", true));
list.add(new IFE_LLNUM(10, "Should be 041234"));
list.add(new IFB_LLNUM(10, "Should not be this", true));
ISOMultiFieldPackager packager = new ISOMultiFieldPackager("A List choice", list);
ISOField field = new ISOField();
packager.unpack(field, raw, 0);
assertEquals("1234", (String) field.getValue());
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class ISOMultiFieldPackagerTest method testUnpackArrayfromInputStream.
public void testUnpackArrayfromInputStream() throws Exception {
byte[] raw = new byte[] { (byte) 0xF0, (byte) 0xF4, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3, (byte) 0xF4 };
ISOMultiFieldPackager packager = new ISOMultiFieldPackager("An Array choice", new ISOFieldPackager[] { new IFB_LLNUM(10, "Should not be this", true), new IFE_LLNUM(10, "Should be 041234"), new IFB_LLNUM(10, "Should not be this", true) });
ISOField field = new ISOField();
packager.unpack(field, (InputStream) new ByteArrayInputStream(raw));
assertEquals("1234", (String) field.getValue());
}
Aggregations