Search in sources :

Example 1 with ISOTaggedField

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());
}
Also used : ISOField(org.jpos.iso.ISOField) ISOTaggedField(org.jpos.tlv.ISOTaggedField)

Example 2 with ISOTaggedField

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;
}
Also used : ISOField(org.jpos.iso.ISOField) ISOTaggedField(org.jpos.tlv.ISOTaggedField)

Example 3 with ISOTaggedField

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());
}
Also used : ISOField(org.jpos.iso.ISOField) ISOTaggedField(org.jpos.tlv.ISOTaggedField)

Example 4 with ISOTaggedField

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;
}
Also used : ISOField(org.jpos.iso.ISOField) ISOTaggedField(org.jpos.tlv.ISOTaggedField)

Example 5 with ISOTaggedField

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);
    }
}
Also used : ISOComponent(org.jpos.iso.ISOComponent) ISOException(org.jpos.iso.ISOException) LogEvent(org.jpos.util.LogEvent) ISOTaggedField(org.jpos.tlv.ISOTaggedField) ISOFieldPackager(org.jpos.iso.ISOFieldPackager) ConfigurationException(org.jpos.core.ConfigurationException) UnknownTagNumberException(org.jpos.emv.UnknownTagNumberException) ISOException(org.jpos.iso.ISOException) IOException(java.io.IOException)

Aggregations

ISOTaggedField (org.jpos.tlv.ISOTaggedField)18 ISOField (org.jpos.iso.ISOField)15 IOException (java.io.IOException)4 ISOException (org.jpos.iso.ISOException)4 LogEvent (org.jpos.util.LogEvent)4 ISOComponent (org.jpos.iso.ISOComponent)3 ISOFieldPackager (org.jpos.iso.ISOFieldPackager)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ConfigurationException (org.jpos.core.ConfigurationException)2 UnknownTagNumberException (org.jpos.emv.UnknownTagNumberException)2 Iterator (java.util.Iterator)1 TreeMap (java.util.TreeMap)1 OffsetIndexedComposite (org.jpos.tlv.OffsetIndexedComposite)1