Encoding problem from shapefile attribute reader
------------------------------------------------
Key: GEOT-1210
URL: http://jira.codehaus.org/browse/GEOT-1210
Project: GeoTools
Issue Type: Bug
Components: data versioning postgis
Environment: Windows XP SP2 Simplified Chinese version, J2SE 1.5.0_08
Reporter: Min Feng
Fix For: 2.3.0
Attachments: TestChineseChar.zip, TestShapefileDbf.java
I try to read my shapefile using GeoTools, but the returned Chinese characters
from attribute have encoding problem: all the attribute strings are encoded
into ISO-8859-1 not the right local encoding. I tracked into the source codes,
and found that the encoding is set to "ISO-8859-1" in DbaseFileReader.java:
205 charBuffer = CharBuffer.allocate(header .getRecordLength() - 1);
206 Charset chars = Charset.forName("ISO-8859-1" );
207 decoder = chars.newDecoder();
However, the default encoding can not be changed, because it may lead to wrong
record length (each Chinese character occupy two bytes). Finally, I added some
codes to decode the string type attribute from ISO-8859-1 to local encoding
(line 449), and it works.
443 // set up the new indexes for start and end
444 charBuffer .position(start).limit(end + 1);
445 String s = charBuffer.toString();
446
448 // decode string from ISO-8859-1 to default encoding
449 s = new String(s.getBytes("ISO-8859-1" ));
450
I hope the codes maybe help for resolving Asian languages encoding problem for
shapefile dbf reader!
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel