开发者

"Invalid byte 1 of 1-byte UTF-8 sequence" error

开发者 https://www.devze.com 2023-01-01 11:01 出处:网络
My error is: \"Invalid byte 1 of 1-byte U开发者_如何学GoTF-8 sequence\". I am calling a Java method using Blaze DS.Your XML document has a BOM marker, because it was created with a Windows program.

My error is: "Invalid byte 1 of 1-byte U开发者_如何学GoTF-8 sequence".

I am calling a Java method using Blaze DS.


Your XML document has a BOM marker, because it was created with a Windows program.

Java does not support this out of the box.

Regarding BOM: http://www.unicode.org/faq/utf_bom.html

So either make sure your XML Document has no BOM marker, (if it is your ds config file), or use something like this in your InputStream:

(not my code) http://koti.mbnet.fi/akini/java/unicodereader/UnicodeInputStream.java.txt

Usage pattern:
 String enc = "ISO-8859-1"; // or NULL to use systemdefault
 FileInputStream fis = new FileInputStream(file);
 UnicodeInputStream uin = new UnicodeInputStream(fis, enc);
 enc = uin.getEncoding(); // check and skip possible BOM bytes
 InputStreamReader in;
 if (enc == null) in = new InputStreamReader(uin);
 else in = new InputStreamReader(uin, enc);


Hi Nithi Make sure that "remoting-config.xml" destination id and source name are correct.


not enough details in the question.

my guess, looks like you are trying to read something as UTF-8 encoded and it is not valid UTF-8 encoded.


ByteArrayInputStream test = new ByteArrayInputStream( xml.trim().getBytes() );
Document document = null;
try {
    document = dbf.newDocumentBuilder().parse( test );
} catch ( Exception e ) {
    System.out.println( "Fehler 1" + e.getMessage()) ;
    try {
        test.close();
        // ... that works: String xml_x = FkString.replace( xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" );
        // Replace UTF-8 to UTF8 ... works
        String xml_x = FkString.replace( xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<?xml version=\"1.0\" encoding=\"UTF8\"?>" );
        test = new ByteArrayInputStream( xml_x.trim().getBytes() );
        document = dbf.newDocumentBuilder().parse( test );
    } catch ( Exception e1 ) {
        System.out.println( "Fehler 2" + e1.getMessage()) ;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消