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");
}
}
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");
}
}
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");
}
}
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;
}
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());
}
Aggregations