use of org.jpos.iso.ISOField in project jPOS by jpos.
the class IFTB_LLBINARY method unpackTag.
protected int unpackTag(ISOComponent c, byte[] tagBytes, int offset) throws ISOException {
ISOField tagField = new ISOField((Integer) c.getKey());
int consumed = getTagPackager().unpack(tagField, tagBytes, offset);
((ISOTaggedField) c).setTag(tagField.getValue().toString());
return consumed;
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class IFTB_LLBINARY method unpackTag.
protected void unpackTag(ISOComponent c, InputStream in) throws ISOException, IOException {
ISOField tagField = new ISOField((Integer) c.getKey());
getTagPackager().unpack(tagField, in);
((ISOTaggedField) c).setTag(tagField.getValue().toString());
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class IF_FSTBINARY method unpack.
public void unpack(ISOComponent c, InputStream in) throws IOException, ISOException {
if (!(c instanceof ISOField))
throw new ISOException(c.getClass().getName() + " is not an ISOField");
boolean endFound = false;
if (in.markSupported()) {
in.mark(getMaxPackedLength());
}
ByteBuffer buf = ByteBuffer.allocate(getMaxPackedLength());
for (int i = 0; i < getMaxPackedLength() && in.available() > 0; i++) {
byte dataByte = (byte) in.read();
if (dataByte == terminator) {
endFound = true;
break;
} else {
buf.put(dataByte);
}
}
if (endFound) {
byte[] data = byteBufferToBytes(buf);
c.setValue(data);
} else {
if (in.markSupported()) {
in.reset();
}
throw new ISOException("Terminating Backslash does not exist");
}
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class TaggedSequencePackager method unpack.
@Override
public int unpack(ISOComponent m, byte[] b) throws ISOException {
LogEvent evt = new LogEvent(this, "unpack");
try {
if (m.getComposite() != m)
throw new ISOException("Can't call packager on non Composite");
if (b.length == 0)
// nothing to do
return 0;
if (// save a few CPU cycle if no logger available
logger != null)
evt.addMessage(ISOUtil.hexString(b));
// Read any non-tlv fields present at beginning of data
PrefixUnpackResult prefixUnpackResult = unpackPrefixes(m, b);
int subFieldId = prefixUnpackResult.getSubFieldId();
int consumed = prefixUnpackResult.getConsumed();
if (subFieldId == 0) {
subFieldId = 1;
}
while (consumed < b.length) {
ISOField tagField = new ISOField(subFieldId);
tagPackager.unpack(tagField, b, consumed);
String tag = tagField.getValue().toString();
ISOFieldPackager fieldPackager = (ISOFieldPackager) packagerMap.get(tag);
if (fieldPackager == null) {
fieldPackager = (ISOFieldPackager) packagerMap.get("default");
}
if (fieldPackager == null) {
throw new ISOException("No default tag packager and no field packager configured for tag: " + tag);
}
int fieldNumber = subFieldId++;
ISOTaggedField taggedField = (ISOTaggedField) fieldPackager.createComponent(fieldNumber);
consumed += fieldPackager.unpack(taggedField, b, consumed);
m.set(taggedField);
}
if (b.length != consumed) {
evt.addMessage("WARNING: unpack len=" + b.length + " consumed=" + consumed);
}
return consumed;
} catch (ISOException e) {
evt.addMessage(e);
throw e;
} catch (Exception e) {
evt.addMessage(e);
throw new ISOException(e);
} finally {
Logger.log(evt);
}
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class CTCSubFieldPackager method pack.
public byte[] pack(ISOComponent c) throws ISOException {
try {
Map tab = c.getChildren();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fld.length; i++) {
ISOField f = (ISOField) tab.get(i);
if (f != null) {
sb.append(new String(fld[i].pack(f)));
}
}
return sb.toString().getBytes();
} catch (Exception ex) {
throw new ISOException(this.getRealm() + ": " + ex.getMessage(), ex);
}
}
Aggregations