Java代码(SAX解析器)在Windows和UNIX上的行为有何不同? [英] Java code ( SAX parser ) behave differently on windows and UNIX why ?

查看:72
本文介绍了Java代码(SAX解析器)在Windows和UNIX上的行为有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





问题 - >实际上我在Unix机器上面临xml解析(SAX Parser)的问题。在Windows和Unix机器上,相同的Jar / Java-Code表现不同,为什么? :(



Windows机器 - >工作正常,使用SAX Parser加载巨大的xml文件,正确读取所有值并填充相同的值.Charset.defaultCharset() windows-1252



Unix机器 - >然后创建JAR并在Unix上部署 - > tomcat并执行jar。

试图加载相同的巨大xml文件但注意到某些值或字符填充为空或不完整,如

国家名称填充为ysia而不是Malaysia或交易日期填充为3 PM而不是18/09/2016 03:31:23 PM.Charset.defaultCharset()UTF-8



问题仅适用于Unix,因为当我加载在Windows或我的本地eclipse中使用相同的xml它工作正常并且所有值都正确填充。



我还尝试修改我的代码并将编码设置为UTF-8用于inputSteamReader但是仍然在unix框中没有正确读取值。



注意:xml中没有特殊字符。 o注意到一件事,当我在其他xml文件中取出相同的记录(那些值没有正确填充)并加载到具有相同jar的unix机器时,它工作正常。这意味着在使用大量数据加载这些记录时会出现问题。 :(



请建议,应该解决什么问题?



我尝试过的:



我已将编码更改为UTF-8但仍未解决问题。

Hi,

Issue --> Actually I am facing issue with xml parsing (SAX Parser) in Unix Machine. Same Jar/Java-Code behave differently on windows and Unix Machine, why ? :(

Windows Machine --> works fine , Using SAX Parser to load huge xml file , Read all values correctly and populate same values. Charset.defaultCharset() windows-1252

Unix Machine --> After then created JAR and deployed at Unix --> tomcat and execute the jar.
Tried to load same huge xml file But noticed that some values or characters are populated empty or incomplete like
Country Name populated as "ysia" instead of "Malaysia" or transaction Date populate as "3 PM" instead of "18/09/2016 03:31:23 PM". Charset.defaultCharset() UTF-8

Issue is only with Unix , Because when I load same xml at windows or my local eclipse it works fine and all values populate correctly.

Also I tried to modify my code and set encoding as UTF-8 for inputSteamReader but still it's not read value correctly at unix box.

Note : There is no special characters in xml. Also noticed one thing that when I take out same records (those value not populated correctly) in other xml file and load in unix machine with same jar it works fine. It means issues occur while load these records with huge data. :(

Please suggest , What should be the solution ?

What I have tried:

I have changed the encoding to UTF-8 but still problem not resolved.

推荐答案

After modify the code as below it worked fine...

public void startElement(String uri, String localName, String qName, 
    Attributes attributes) throws SAXException {
  if(qName.equalsIgnoreCase("customerName")){ 
    chars.setLength(0); 
  }
  tmpValue = null;
} 


public void characters(char[] ac, int i, int j) throws SAXException {
  chars.append(ac, i, j);
  if (tmpValue == null) {
    tmpValue = new String(ac, i, j);
  } else {
    tmpValue += new String(ac, i, j);
  }
}

public void endElement(String s, String s1, String element) throws SAXException {
  if (element.equalsIgnoreCase("transactionDate") && tmpValue != null) {          
    obj.setTransactionDate(tmpValue.trim()); 
  }
}


这篇关于Java代码(SAX解析器)在Windows和UNIX上的行为有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆