Unknown Character encoding: not UTF-16BE

Saraswathy
2010-09-27
2013-05-15
  • Saraswathy

    Saraswathy - 2010-09-27

    Hi,

    My xml is either passed as a string or an inputstream dynamically and I wanted to create a VTDNav Object out of it for parsing.

    However, I get a com.ximpleware.EncodingException: Unknown Character encoding: not UTF-16BE exception even though my first line of XML has UTF-8 declaration as
    <?xml version='1.0' encoding='UTF-8'?>

    Without overcoming this issue, I'll not be able to proceed. Please help.

    Here is the stack trace

    17:26:34,762 INFO   --c-
    17:26:34,762 ERROR  com.ximpleware.EncodingException: Unknown Character encoding: not UTF-16BE
    17:26:34,762 ERROR      at com.ximpleware.VTDGen.decide_encoding(VTDGen.java:1405)
    17:26:34,762 ERROR      at com.ximpleware.VTDGen.parse(VTDGen.java:2224)
    17:26:34,762 ERROR      at com.csa.adv12.action.SplitAction1.getResult(Unknown Source)
    17:26:34,762 ERROR      at com.csa.adv12.action.SplitAction1..execute(Unknown Source)
    17:26:34,762 ERROR      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
    17:26:34,778 ERROR      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
    17:26:34,778 ERROR      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    17:26:34,778 ERROR      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    17:26:34,778 ERROR      at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    17:26:34,778 ERROR      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    17:26:34,778 ERROR      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    17:26:34,778 ERROR      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    17:26:34,778 ERROR      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    17:26:34,778 ERROR      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    17:26:34,778 ERROR      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    17:26:34,778 ERROR      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    17:26:34,778 ERROR      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173)
    17:26:34,778 ERROR      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
    17:26:34,778 ERROR      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
    17:26:34,778 ERROR      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    17:26:34,778 ERROR      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    17:26:34,778 ERROR      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
    17:26:34,778 ERROR      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    17:26:34,778 ERROR      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
    17:26:34,778 ERROR      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    17:26:34,778 ERROR      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    17:26:34,778 ERROR      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    17:26:34,778 ERROR      at java.lang.Thread.run(Thread.java:595)

    Thank you.
    Saraswathy.

     
  • jimmy zhang

    jimmy zhang - 2010-09-28

    Can you submit a sample xml file that reproduces this error?

     
  • Saraswathy

    Saraswathy - 2010-09-28

    Ok. Here is background and confession of how I ended up to this exception.

    I initially got a EOFException when I tried to create a VTDNAv object from inputstream.

    :12:25,644 ERROR  com.ximpleware.EOFException: permature EOF reached, XML document incomplete
    :12:25,644 ERROR      at com.ximpleware.VTDGen.<init>(VTDGen.java:1305)

    The way I was constructing a VTDNav object from InputStream was

    1. URL url1 = new URL("http://localhost:8080/Testapp/sample.xml");
    2. byte theBytes = new byte;
    3. ip1.read(theBytes);
    4. vg1.setDoc(theBytes);
    5. vg1.parse(true);
    6. VTDNav vn1 = vg1.getNav();

    When I tried to find the solution online, I stumbled across a Java forum where someone suggested to pass the bytes from the inputStream without calling a read on it to pass it to the parse function of the DocumentBuilder to resolve the EOFException.

    I tried this in my VTD code and commented the line 3 above  //ip1.read(theBytes);  without realizing that I passing empty bytes and resulted in the com.ximpleware.EncodingException: Unknown Character encoding: not UTF-16BE  error.

    So basically, I need help for my original error permature EOF reached, XML document incomplete.

    Thank you.
    Saraswathy.

     
  • jimmy zhang

    jimmy zhang - 2010-09-28

    I replied your email… couldn't reproduce the problem with your submitted xml file..

     
  • jimmy zhang

    jimmy zhang - 2010-09-28

    how big is your file? is it bigger than 1G?

     
  • jimmy zhang

    jimmy zhang - 2010-09-29

    I got bounced email your saraswathy6@users.sourceforge.net isn't working for some reason

     
  • Saraswathy

    Saraswathy - 2010-09-30

    Hi Jimmy,

    Thank you for your timely replies.

    I'm sorry about the bounced email. I need to fix that email issue.

    Regarding my file size it can vary from 30kb - 300 kb and it is not huge.

    I agree with you in the possibility that you might have not reproduced the issue that I saw.

    The issue got resolved by appropriately creating and passing the byte array to the VTDGen's setDoc method.

    The proper way to create the bytearray from the inputstream was

    VTDGen vg = new VTDGen();
    VTDNav vn = null;
            byte theBytes;
           
        try {
            byte buffer = new byte;
            int bytesRead;
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            while ((bytesRead = inp.read(buffer)) != -1)
            {
                output.write(buffer, 0, bytesRead);
            }
           
            vg.setDoc(output.toByteArray());
    output.close();

     
  • Saraswathy

    Saraswathy - 2010-09-30

         I created the VTDNav object from the inputstream this way and it worked.

     
           VTDGen vg = new VTDGen();
           VTDNav vn = null;
            byte theBytes;
           
        try {
            byte buffer = new byte;
            int bytesRead;
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            while ((bytesRead = inp.read(buffer)) != -1)
            {
                output.write(buffer, 0, bytesRead);
            }
           
            vg.setDoc(output.toByteArray());
           output.close();
           vg.parse(true);
          vn = vg.getNav();

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks