Added a new property, characterEncoding, to MessageFactory, IsoMessage, FieldParseInfo and IsoValue. This helps in parsing messages from byte buffers containing extended characters in encodings other than the default for the JVM. Tested with UTF8 on a Mac (which has default Mac OS Roman) and worked fine.
Several methods now have an additional encoding parameter (just a String, not directly a Charset), but the default is always the JVM's default encoding (taken from the property 'file.encoding'). git-svn-id: https://j8583.svn.sourceforge.net/svnroot/j8583/j8583@70 db60a039-f72e-0410-b1d2-baa000846441
This commit is contained in:
@@ -48,6 +48,7 @@ public class IsoMessage {
|
||||
private int etx = -1;
|
||||
/** Flag to enforce secondary bitmap even if empty. */
|
||||
private boolean forceb2;
|
||||
private String encoding = System.getProperty("file.encoding");
|
||||
|
||||
/** Creates a new empty message with no values set. */
|
||||
public IsoMessage() {
|
||||
@@ -66,6 +67,13 @@ public class IsoMessage {
|
||||
return forceb2;
|
||||
}
|
||||
|
||||
public void setCharacterEncoding(String value) {
|
||||
encoding = value;
|
||||
}
|
||||
public String getCharacterEncoding() {
|
||||
return encoding;
|
||||
}
|
||||
|
||||
/** Sets the string to be sent as ISO header, that is, after the length header but before the message type.
|
||||
* This is useful in case an application needs some custom data in the ISO header of each message (very rare). */
|
||||
public void setIsoHeader(String value) {
|
||||
@@ -119,6 +127,7 @@ public class IsoMessage {
|
||||
if (index < 2 || index > 128) {
|
||||
throw new IndexOutOfBoundsException("Field index must be between 2 and 128");
|
||||
}
|
||||
field.setCharacterEncoding(encoding);
|
||||
fields[index] = field;
|
||||
}
|
||||
|
||||
@@ -153,6 +162,7 @@ public class IsoMessage {
|
||||
} else {
|
||||
v = new IsoValue(t, value, encoder);
|
||||
}
|
||||
v.setCharacterEncoding(encoding);
|
||||
fields[index] = v;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user