Hi,
I have a proble with Mina.
I receive from a 3rd party application a message containing a hexa char
"DC". When I try to decode, I get an error. The character should be Ü. Here
is a simple application that shows my problem:
package javaapplication3;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoAcceptor;
import org.apache.mina.common.SimpleByteBufferAllocator;
/**
*
* @author ciprian_b
*/
public class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
//String s2 = "C,NAÜ,LA0";
byte[] b2 = new byte[3];
b2[0] = (byte)0x02;
b2[1] = (byte)220;
b2[2] = (byte)0x03;
ByteBuffer buf = ByteBuffer.wrap(b2);
java.lang.System.out.println("buf: " + buf.getHexDump());
//org.apache.mina.common.ByteBuffer bf =
org.apache.mina.common.ByteBuffer.wrap(s2.getBytes());
//getFactoredMessages(buf,
java.nio.charset.Charset.forName("UTF-8").newDecoder());
test(buf, java.nio.charset.Charset.forName("UTF-8").newDecoder());
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void test(ByteBuffer buffer, CharsetDecoder decoder){
try {
java.nio.CharBuffer cBuffer = decoder.decode(buffer.buf());
java.lang.String msgStr = new java.lang.String(cBuffer.array());
} catch (CharacterCodingException ex) {
ex.printStackTrace();
}
}
}
I have the following error:
java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(CoderResult.java:260)
at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:771)
at javaapplication3.Main.test(Main.java:59)
at javaapplication3.Main.main(Main.java:51)
Thank you for your help
Cipri