Search in sources :

Example 6 with ISOField

use of org.jpos.iso.ISOField in project jPOS by jpos.

the class IF_FSTBINARY method unpack.

/**
 * @param c      - the Component to unpack
 * @param b      - binary image
 * @param offset - starting offset within the binary image
 * @return consumed bytes
 * @throws org.jpos.iso.ISOException
 */
public int unpack(ISOComponent c, byte[] b, int offset) throws ISOException {
    if (!(c instanceof ISOField))
        throw new ISOException(c.getClass().getName() + " is not an ISOField");
    int length = -1;
    for (int i = 0; i < getMaxPackedLength(); i++) {
        byte dataByte = b[offset + i];
        if (dataByte == terminator) {
            length = i;
            break;
        }
    }
    if (length >= 0) {
        byte[] value = new byte[length];
        System.arraycopy(b, offset, value, 0, length);
        c.setValue(value);
        return length + 1;
    } else {
        throw new ISOException("Terminating Backslash does not exist");
    }
}
Also used : ISOField(org.jpos.iso.ISOField) ISOException(org.jpos.iso.ISOException)

Example 7 with ISOField

use of org.jpos.iso.ISOField in project jPOS by jpos.

the class IF_FSTCHAR method unpack.

/**
 * @param c      - the Component to unpack
 * @param b      - binary image
 * @param offset - starting offset within the binary image
 * @return consumed bytes
 * @throws org.jpos.iso.ISOException
 */
public int unpack(ISOComponent c, byte[] b, int offset) throws ISOException {
    if (!(c instanceof ISOField))
        throw new ISOException(c.getClass().getName() + " is not an ISOField");
    int length = -1;
    for (int i = 0; i < getMaxPackedLength(); i++) {
        byte dataByte = b[offset + i];
        if ((char) dataByte == terminator) {
            length = i;
            break;
        }
    }
    if (length >= 0) {
        String value = new String(b, offset, length);
        c.setValue(value);
        return length + 1;
    } else {
        throw new ISOException("Terminating Backslash does not exist");
    }
}
Also used : ISOField(org.jpos.iso.ISOField) ISOException(org.jpos.iso.ISOException)

Example 8 with ISOField

use of org.jpos.iso.ISOField in project jPOS by jpos.

the class IF_FSTCHAR 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 ((char) dataByte == terminator) {
            endFound = true;
            break;
        } else {
            buf.put(dataByte);
        }
    }
    if (endFound) {
        byte[] data = byteBufferToBytes(buf);
        String value = new String(data);
        c.setValue(value);
    } 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 9 with ISOField

use of org.jpos.iso.ISOField in project jPOS by jpos.

the class BERTLVPackager method unpackValue.

private ISOComponent unpackValue(String tagNameHex, final byte[] tlvData, int subFieldNumber, int dataLength) throws ISOException, UnknownTagNumberException {
    final int tagNumber = Integer.parseInt(tagNameHex, 16);
    final TLVDataFormat dataFormat = getTagFormatMapper().getFormat(tagNumber);
    ISOComponent value;
    String unpackedValue;
    int uninterpretLength;
    switch(dataFormat) {
        case COMPRESSED_NUMERIC:
            uninterpretLength = getUninterpretLength(dataLength, bcdInterpreterRightPaddedF);
            unpackedValue = bcdInterpreterRightPaddedF.uninterpret(tlvData, 0, uninterpretLength);
            if (unpackedValue.length() > 1 && unpackedValue.charAt(unpackedValue.length() - 1) == 'F') {
                unpackedValue = unpackedValue.substring(0, unpackedValue.length() - 1);
            }
            value = new ISOField(subFieldNumber, unpackedValue);
            break;
        case PACKED_NUMERIC:
        case PACKED_NUMERIC_DATE_YYMMDD:
        case PACKED_NUMERIC_TIME_HHMMSS:
            uninterpretLength = getUninterpretLength(dataLength, bcdInterpreterLeftPaddedZero);
            unpackedValue = bcdInterpreterLeftPaddedZero.uninterpret(tlvData, 0, uninterpretLength);
            if (unpackedValue.length() > 1 && unpackedValue.charAt(0) == '0') {
                unpackedValue = unpackedValue.substring(1);
            }
            value = new ISOField(subFieldNumber, unpackedValue);
            break;
        case ASCII_NUMERIC:
        case ASCII_ALPHA:
        case ASCII_ALPHA_NUMERIC:
        case ASCII_ALPHA_NUMERIC_SPACE:
        case ASCII_ALPHA_NUMERIC_SPECIAL:
            uninterpretLength = getUninterpretLength(dataLength, asciiInterpreter);
            unpackedValue = asciiInterpreter.uninterpret(tlvData, 0, uninterpretLength);
            value = new ISOField(subFieldNumber, unpackedValue);
            break;
        case BINARY:
        case PROPRIETARY:
            value = new ISOBinaryField(subFieldNumber, tlvData);
            break;
        case CONSTRUCTED:
            value = new ISOMsg(subFieldNumber);
            unpack(value, tlvData, true);
            break;
        default:
            throw new IllegalArgumentException("Unknown TLVDataFormat: " + dataFormat);
    }
    return value;
}
Also used : ISOField(org.jpos.iso.ISOField) ISOComponent(org.jpos.iso.ISOComponent) ISOBinaryField(org.jpos.iso.ISOBinaryField) ISOMsg(org.jpos.iso.ISOMsg) TLVDataFormat(org.jpos.tlv.TLVDataFormat)

Example 10 with ISOField

use of org.jpos.iso.ISOField in project jPOS by jpos.

the class VErrorParserTest method testGetVErrors7.

@SuppressWarnings("unchecked")
@Test
public void testGetVErrors7() throws Throwable {
    VErrorParser vErrorParser = new VErrorParser();
    Vector result = vErrorParser.getVErrors(new ISOVField(new ISOField(100)));
    assertEquals("result.size()", 0, result.size());
}
Also used : ISOField(org.jpos.iso.ISOField) ISOVField(org.jpos.iso.ISOVField) Vector(java.util.Vector) Test(org.junit.Test)

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