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:
@@ -1,6 +1,7 @@
|
||||
package j8583;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.util.Arrays;
|
||||
@@ -22,9 +23,11 @@ public class TestBinaries {
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
mfactAscii.setCharacterEncoding("UTF-8");
|
||||
mfactAscii.setConfigPath("config.xml");
|
||||
mfactBin.setConfigPath("config.xml");
|
||||
mfactAscii.setAssignDate(true);
|
||||
mfactBin.setCharacterEncoding("UTF-8");
|
||||
mfactBin.setConfigPath("config.xml");
|
||||
mfactBin.setAssignDate(true);
|
||||
mfactBin.setUseBinaryMessages(true);
|
||||
}
|
||||
@@ -61,19 +64,19 @@ public class TestBinaries {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessages() throws ParseException {
|
||||
public void testMessages() throws ParseException, UnsupportedEncodingException {
|
||||
//Create a message with both factories
|
||||
IsoMessage ascii = mfactAscii.newMessage(0x600);
|
||||
IsoMessage bin = mfactBin.newMessage(0x600);
|
||||
//HEXencode the binary message, headers should be similar to the ASCII version
|
||||
String hexBin = HexCodec.hexEncode(bin.writeData());
|
||||
String hexAscii = new String(ascii.writeData()).toUpperCase();
|
||||
System.out.printf("bin: %s%nascii: %s%n", hexBin, hexAscii);
|
||||
Assert.assertEquals("0600", hexBin.substring(0, 4));
|
||||
//Should be the same up to the field 42 (first 80 chars)
|
||||
Assert.assertEquals(hexAscii.substring(0, 88), hexBin.substring(0, 88));
|
||||
//Parse both messages
|
||||
IsoMessage ascii2 = mfactAscii.parseMessage(ascii.writeData(), 0);
|
||||
byte[] asciiBuf = ascii.writeData();
|
||||
IsoMessage ascii2 = mfactAscii.parseMessage(asciiBuf, 0);
|
||||
testParsed(ascii2);
|
||||
Assert.assertEquals(ascii.getObjectValue(7).toString(), ascii2.getObjectValue(7).toString());
|
||||
IsoMessage bin2 = mfactBin.parseMessage(bin.writeData(), 0);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package j8583;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.ParseException;
|
||||
|
||||
import org.junit.Assert;
|
||||
@@ -23,6 +25,7 @@ public class TestIsoMessage {
|
||||
@Before
|
||||
public void init() throws IOException {
|
||||
mf = new MessageFactory();
|
||||
mf.setCharacterEncoding("UTF-8");
|
||||
mf.setCustomField(48, new CustomField48());
|
||||
mf.setConfigPath("config.xml");
|
||||
}
|
||||
@@ -60,7 +63,7 @@ public class TestIsoMessage {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncoding() throws ParseException {
|
||||
public void testEncoding() throws Exception {
|
||||
IsoMessage m1 = mf.newMessage(0x200);
|
||||
byte[] buf = m1.writeData();
|
||||
IsoMessage m2 = mf.parseMessage(buf, mf.getIsoHeader(0x200).length());
|
||||
|
||||
Reference in New Issue
Block a user