Search in sources :

Example 46 with ISOField

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

Example 47 with ISOField

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

Example 48 with ISOField

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");
    }
}
Also used : ISOField(org.jpos.iso.ISOField) ISOException(org.jpos.iso.ISOException) ByteBuffer(java.nio.ByteBuffer)

Example 49 with ISOField

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

Example 50 with ISOField

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);
    }
}
Also used : ISOField(org.jpos.iso.ISOField) ISOException(org.jpos.iso.ISOException) Map(java.util.Map) ISOVException(org.jpos.iso.validator.ISOVException) ISOException(org.jpos.iso.ISOException)

Aggregations

ISOField (org.jpos.iso.ISOField)50 Test (org.junit.Test)18 ISOException (org.jpos.iso.ISOException)15 ISOTaggedField (org.jpos.tlv.ISOTaggedField)15 IFB_LLNUM (org.jpos.iso.IFB_LLNUM)6 IFE_LLNUM (org.jpos.iso.IFE_LLNUM)6 ISOMsg (org.jpos.iso.ISOMsg)6 ISOMultiFieldPackager (org.jpos.iso.packager.ISOMultiFieldPackager)6 ISOComponent (org.jpos.iso.ISOComponent)5 ISOFieldPackager (org.jpos.iso.ISOFieldPackager)5 ISOVField (org.jpos.iso.ISOVField)5 Vector (java.util.Vector)4 FileInputStream (java.io.FileInputStream)3 Map (java.util.Map)3 ISOBinaryField (org.jpos.iso.ISOBinaryField)3 ByteBuffer (java.nio.ByteBuffer)2 ISOVError (org.jpos.iso.ISOVError)2 GenericPackager (org.jpos.iso.packager.GenericPackager)2 GenericTagSequence (org.jpos.tlv.GenericTagSequence)2 LiteralTagValue (org.jpos.tlv.LiteralTagValue)2