Hi, Adminstrator:
I am doing the shape file map re-projection using Geotools. I found an error when I tried to save the projected feature data to a shape file. I am afraid that it is a bug in Geotools. The error message and source code are attached.The following are the platform and Geotool I used:
Platform: Altix Linux (JDK1.4.2)
Geotools 2.1.1
1)The error messages is as the below:
java.lang.StringIndexOutOfBoundsException: String index out of range: 31
at java.lang.StringBuffer.charAt(StringBuffer.java(Inlined Compiled Code))
at org.geotools.data.shapefile.dbf.DbaseFileWriter$FieldFormatter.getFieldString(DbaseFileWriter.java(Compiled Code))
at org.geotools.data.shapefile.dbf.DbaseFileWriter.fieldString(DbaseFileWriter.java(Compiled Code))
at org.geotools.data.shapefile.dbf.DbaseFileWriter.write(DbaseFileWriter.java(Compiled Code))
at org.geotools.data.shapefile.ShapefileDataStore$Writer.write(ShapefileDataStore.java(Compiled Code
))
at org.geotools.data.shapefile.ShapefileDataStore$Writer.close(ShapefileDataStore.java:1249)
at org.geotools.data.InProcessLockingManager$1.close(InProcessLockingManager.java:343)
at org.geotools.data.AbstractFeatureStore.setFeatures(AbstractFeatureStore.java(Compiled Code))
at MAA_ShapeReaderWriter.write(MAA_ShapeReaderWriter.java:98)
2) the source code:
The input string to DbaseFileWriter.java: public static class FieldFormatter getFieldString() is âáåì àãîéðñèøèéáé
public String getFieldString(int size, String s) {
buffer.replace(0, size, emptyString);
buffer.setLength(size);
int unit=" ".getBytes().length;
//international characters must be accounted for so size != length.
int maxSize=size;
if(s != null) {
buffer.replace(0, size, s);
int currentBytes=s.substring(0, Math.min(size, s.length())).getBytes().length;
if( currentBytes>size ){
char[] c=new char[1];
for( int index=size-1; currentBytes>size; index--){
c[0] = buffer.charAt(index);
String string=new String(c);
buffer.deleteCharAt(index);
currentBytes-=string.getBytes().length;
maxSize--;
}
}else{
if(s.length() < size) {
maxSize=size-(currentBytes-s.length());
for(int i = s.length(); i < size; i++) {
buffer.append(' ');
}
}
}
}
buffer.setLength(maxSize);
System.out.println(buffer.toString().getBytes().length);
return buffer.toString();
}
3) I try the change:
change:
for( int index=size-1; currentBytes>size; index--){
to:
for( int index=buffer.length()-1; currentBytes>size; index--){
No exception caught, but it seems that I lost the attribute info.
