use of org.jpos.tlv.ISOTaggedField in project jPOS by jpos.
the class IFTA_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.tlv.ISOTaggedField in project jPOS by jpos.
the class IFTA_LLLBINARY 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.tlv.ISOTaggedField in project jPOS by jpos.
the class IFTA_LLLCHAR 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.tlv.ISOTaggedField in project jPOS by jpos.
the class IFTA_LLNUM 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.tlv.ISOTaggedField in project jPOS by jpos.
the class BERTLVPackager method unpack.
public int unpack(ISOComponent m, byte[] b, boolean nested) throws ISOException {
LogEvent evt = new LogEvent(this, "unpack");
try {
if (m.getComposite() == null)
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));
int tlvDataLength = b.length;
int consumed = 0;
int subFieldNumber = 1;
if (!nested && fld.length > 1) {
ISOFieldPackager packager = fld[1];
if (packager != null) {
ISOComponent subField = packager.createComponent(1);
consumed = consumed + packager.unpack(subField, b, consumed);
m.set(subField);
}
subFieldNumber++;
}
while (consumed < tlvDataLength) {
ISOFieldPackager packager;
if (!nested && fld.length > 1 && (packager = fld[fld.length - 1]) != null && packager.getLength() == tlvDataLength - consumed) {
ISOComponent subField = packager.createComponent(fld.length - 1);
consumed = consumed + packager.unpack(subField, b, consumed);
m.set(subField);
subFieldNumber++;
} else {
// Read the Tag per BER
UnpackResult tagUnpackResult = unpackTag(b, consumed);
consumed = consumed + tagUnpackResult.consumed;
final byte[] tagBytes = tagUnpackResult.value;
String tag = ISOUtil.byte2hex(tagBytes).toUpperCase();
UnpackResult lengthUnpackResult = unpackLength(b, consumed);
consumed = consumed + lengthUnpackResult.consumed;
int length = ISOUtil.byte2int(lengthUnpackResult.value);
final ISOComponent tlvSubFieldData;
byte[] value = new byte[length];
if (length > 0) {
System.arraycopy(b, consumed, value, 0, value.length);
}
int uninterpretLength = getUninterpretLength(length, valueInterpreter);
byte[] rawValueBytes = valueInterpreter.uninterpret(value, 0, uninterpretLength);
tlvSubFieldData = unpackValue(tag, rawValueBytes, subFieldNumber, length);
consumed = consumed + length;
ISOTaggedField tlv = new ISOTaggedField(tag, tlvSubFieldData);
m.set(tlv);
subFieldNumber++;
}
}
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);
}
}
Aggregations