use of org.jpos.tlv.TLVDataFormat 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.tlv.TLVDataFormat in project jPOS by jpos.
the class BERTLVPackager method packValue.
protected byte[] packValue(String tagNameHex, final ISOComponent c) throws ISOException, UnknownTagNumberException {
final int tagNumber = Integer.parseInt(tagNameHex, 16);
final TLVDataFormat dataFormat = getTagFormatMapper().getFormat(tagNumber);
String tagValue;
byte[] packedValue;
if (c.getComposite() == null) {
if (c.getValue() instanceof String) {
tagValue = (String) c.getValue();
switch(dataFormat) {
case COMPRESSED_NUMERIC:
packedValue = new byte[bcdInterpreterRightPaddedF.getPackedLength(tagValue.length())];
bcdInterpreterRightPaddedF.interpret(tagValue, packedValue, 0);
break;
case PACKED_NUMERIC:
case PACKED_NUMERIC_DATE_YYMMDD:
case PACKED_NUMERIC_TIME_HHMMSS:
packedValue = new byte[bcdInterpreterLeftPaddedZero.getPackedLength(tagValue.length())];
bcdInterpreterLeftPaddedZero.interpret(tagValue, packedValue, 0);
break;
case ASCII_NUMERIC:
case ASCII_ALPHA:
case ASCII_ALPHA_NUMERIC:
case ASCII_ALPHA_NUMERIC_SPACE:
case ASCII_ALPHA_NUMERIC_SPECIAL:
packedValue = new byte[asciiInterpreter.getPackedLength(tagValue.length())];
asciiInterpreter.interpret(tagValue, packedValue, 0);
break;
case BINARY:
case PROPRIETARY:
packedValue = new byte[literalInterpreter.getPackedLength(tagValue.length())];
literalInterpreter.interpret(tagValue, packedValue, 0);
break;
case CONSTRUCTED:
throw new IllegalArgumentException("CONSTRUCTED tag value should be a composite ISOComponent");
// break;
default:
throw new IllegalArgumentException("Unknown TLVDataFormat: " + dataFormat);
}
} else {
packedValue = c.getBytes();
}
} else {
if (TLVDataFormat.CONSTRUCTED.equals(dataFormat) || TLVDataFormat.PROPRIETARY.equals(dataFormat)) {
packedValue = pack(c, true, 0, c.getMaxField());
} else {
throw new IllegalArgumentException("Composite ISOComponent should be used only for CONSTRUCTED data type");
}
}
return packedValue;
}
Aggregations