Added unit tests for binaries (in progress). Added BINARY, LLBIN and LLLBIN to the DTD. Added a message template and a parsing template to the test config.

Fixed some problems with the stored values in IsoValues.


git-svn-id: https://j8583.svn.sourceforge.net/svnroot/j8583/j8583@64 db60a039-f72e-0410-b1d2-baa000846441
This commit is contained in:
chochos
2010-12-07 17:14:04 +00:00
parent 3c8cacbb8d
commit ad4f51d3cd
4 changed files with 86 additions and 5 deletions
+20 -4
View File
@@ -76,7 +76,11 @@ public class IsoValue<T> implements Cloneable {
}
} else if (type == IsoType.LLBIN || type == IsoType.LLLBIN) {
if (custom == null) {
length = ((byte[])value).length;
if (value instanceof byte[]) {
length = ((byte[])value).length;
} else {
length = value.toString().length() / 2 + (value.toString().length() % 2);
}
} else {
//TODO special encoder, NO strings
String enc = custom.encodeField(value);
@@ -177,9 +181,17 @@ public class IsoValue<T> implements Cloneable {
} else if (value instanceof Date) {
return type.format((Date)value);
} else if (type == IsoType.BINARY) {
return type.format(encoder == null ? HexCodec.hexEncode((byte[])value) : encoder.encodeField(value), length * 2);
if (value instanceof byte[]) {
return type.format(encoder == null ? HexCodec.hexEncode((byte[])value) : encoder.encodeField(value), length * 2);
} else {
return type.format(encoder == null ? value.toString() : encoder.encodeField(value), length);
}
} else if (type == IsoType.LLBIN || type == IsoType.LLLBIN) {
return encoder == null ? HexCodec.hexEncode((byte[])value) : encoder.encodeField(value);
if (value instanceof byte[]) {
return encoder == null ? HexCodec.hexEncode((byte[])value) : encoder.encodeField(value);
} else {
return encoder == null ? value.toString() : encoder.encodeField(value);
}
}
return encoder == null ? value.toString() : encoder.encodeField(value);
}
@@ -273,7 +285,11 @@ public class IsoValue<T> implements Cloneable {
}
}
if (binary && (type == IsoType.BINARY || type == IsoType.LLBIN || type == IsoType.LLLBIN)) {
outs.write((byte[])value);
if (value instanceof byte[]) {
outs.write((byte[])value);
} else {
outs.write(HexCodec.hexDecode(value.toString()));
}
} else {
//Just write the value as text
outs.write(toString().getBytes());