Revision 6926
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/dbf/DbaseFile.java | ||
---|---|---|
13 | 13 |
import java.io.FileNotFoundException; |
14 | 14 |
import java.io.IOException; |
15 | 15 |
import java.io.RandomAccessFile; |
16 |
import java.io.UnsupportedEncodingException; |
|
16 | 17 |
import java.nio.ByteBuffer; |
17 | 18 |
import java.nio.channels.FileChannel; |
19 |
import java.nio.charset.Charset; |
|
18 | 20 |
|
19 | 21 |
import com.iver.utiles.bigfile.BigByteBuffer2; |
20 | 22 |
|
... | ... | |
35 | 37 |
private int recordOffset; |
36 | 38 |
private ByteBuffer cachedRecord = null; |
37 | 39 |
private byte[] bytesCachedRecord = null; |
40 |
|
|
41 |
private Charset chars; |
|
38 | 42 |
|
43 |
|
|
39 | 44 |
// Retrieve number of records in the DbaseFile |
40 | 45 |
public int getRecordCount() { |
41 | 46 |
return myHeader.getNumRecords(); |
... | ... | |
84 | 89 |
* @param fieldId DOCUMENT ME! |
85 | 90 |
* |
86 | 91 |
* @return DOCUMENT ME! |
92 |
* @throws UnsupportedEncodingException |
|
87 | 93 |
*/ |
88 |
public String getStringFieldValue(int rowIndex, int fieldId) { |
|
94 |
public String getStringFieldValue(int rowIndex, int fieldId) throws UnsupportedEncodingException {
|
|
89 | 95 |
int fieldOffset = myHeader.getFieldDescription(fieldId).myFieldDataAddress; |
90 | 96 |
byte[] data = new byte[myHeader.getFieldLength(fieldId)]; |
91 | 97 |
if (rowIndex != posActual) |
... | ... | |
106 | 112 |
cachedRecord.get(data); |
107 | 113 |
|
108 | 114 |
|
109 |
return new String(data); |
|
115 |
return new String(data, chars.name());
|
|
110 | 116 |
|
111 | 117 |
} |
112 | 118 |
|
... | ... | |
303 | 309 |
// create the header to contain the header information. |
304 | 310 |
myHeader = new DbaseFileHeader(); |
305 | 311 |
myHeader.readHeader(buffer); |
312 |
chars = Charset.forName("ISO-8859-1"); |
|
306 | 313 |
bytesCachedRecord = new byte[myHeader.getRecordLength()]; |
307 | 314 |
} |
308 | 315 |
|
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/dbf/DBFDriver.java | ||
---|---|---|
6 | 6 |
import java.io.FileOutputStream; |
7 | 7 |
import java.io.IOException; |
8 | 8 |
import java.io.RandomAccessFile; |
9 |
import java.io.UnsupportedEncodingException; |
|
9 | 10 |
import java.nio.channels.FileChannel; |
10 | 11 |
import java.nio.channels.WritableByteChannel; |
11 | 12 |
import java.sql.Types; |
... | ... | |
110 | 111 |
} |
111 | 112 |
*/ |
112 | 113 |
} else if ((fieldType == 'F') || (fieldType == 'N')) { |
113 |
String strValue = dbf.getStringFieldValue((int) rowIndex, fieldId) |
|
114 |
.trim(); |
|
114 |
String strValue; |
|
115 |
try { |
|
116 |
strValue = dbf.getStringFieldValue((int) rowIndex, fieldId) |
|
117 |
.trim(); |
|
118 |
} catch (UnsupportedEncodingException e1) { |
|
119 |
e1.printStackTrace(); |
|
120 |
throw new DriverException(e1); |
|
121 |
} |
|
115 | 122 |
|
116 | 123 |
if (strValue.length() == 0) { |
117 | 124 |
return null; |
... | ... | |
124 | 131 |
} |
125 | 132 |
return ValueFactory.createValue(value); |
126 | 133 |
} else if (fieldType == 'C') { |
127 |
return ValueFactory.createValue(dbf.getStringFieldValue( |
|
128 |
(int) rowIndex, fieldId).trim()); |
|
134 |
try { |
|
135 |
return ValueFactory.createValue(dbf.getStringFieldValue( |
|
136 |
(int) rowIndex, fieldId).trim()); |
|
137 |
} catch (UnsupportedEncodingException e) { |
|
138 |
throw new DriverException(e); |
|
139 |
} |
|
129 | 140 |
} else if (fieldType == 'D') { |
130 |
String date = dbf.getStringFieldValue((int) rowIndex, fieldId).trim(); |
|
141 |
String date; |
|
142 |
try { |
|
143 |
date = dbf.getStringFieldValue((int) rowIndex, fieldId).trim(); |
|
144 |
} catch (UnsupportedEncodingException e1) { |
|
145 |
throw new DriverException(e1); |
|
146 |
} |
|
131 | 147 |
// System.out.println(rowIndex + " data=" + date); |
132 | 148 |
if (date.length() == 0) { |
133 | 149 |
return null; |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/DbaseFileNIO.java | ||
---|---|---|
43 | 43 |
import java.io.File; |
44 | 44 |
import java.io.FileInputStream; |
45 | 45 |
import java.io.IOException; |
46 |
import java.io.UnsupportedEncodingException; |
|
46 | 47 |
import java.nio.ByteBuffer; |
48 |
import java.nio.CharBuffer; |
|
47 | 49 |
import java.nio.channels.FileChannel; |
50 |
import java.nio.charset.Charset; |
|
51 |
import java.nio.charset.CharsetDecoder; |
|
48 | 52 |
|
49 |
import com.iver.utiles.bigfile.BigByteBuffer; |
|
50 | 53 |
import com.iver.utiles.bigfile.BigByteBuffer2; |
51 | 54 |
|
52 | 55 |
|
... | ... | |
60 | 63 |
private FileInputStream fin; |
61 | 64 |
private FileChannel channel; |
62 | 65 |
private BigByteBuffer2 buffer; |
66 |
|
|
67 |
CharBuffer charBuffer; |
|
68 |
CharsetDecoder decoder; |
|
69 |
Charset chars; |
|
70 |
|
|
63 | 71 |
|
64 | 72 |
/** |
65 | 73 |
* Retrieve number of records in the DbaseFile |
... | ... | |
114 | 122 |
* @param fieldId N?mero de columna. |
115 | 123 |
* |
116 | 124 |
* @return String. |
125 |
* @throws UnsupportedEncodingException |
|
117 | 126 |
*/ |
118 |
public String getStringFieldValue(int rowIndex, int fieldId) { |
|
127 |
public String getStringFieldValue(int rowIndex, int fieldId) throws UnsupportedEncodingException {
|
|
119 | 128 |
int recordOffset = (myHeader.getRecordLength() * rowIndex) + |
120 | 129 |
myHeader.getHeaderLength() + 1; |
121 | 130 |
|
... | ... | |
129 | 138 |
buffer.position(recordOffset + fieldOffset); |
130 | 139 |
|
131 | 140 |
byte[] data = new byte[myHeader.getFieldLength(fieldId)]; |
141 |
|
|
142 |
// ByteBuffer byteBuffer = ByteBuffer.wrap(data); |
|
143 |
|
|
144 |
|
|
132 | 145 |
buffer.get(data); |
133 |
|
|
134 |
return new String(data); |
|
146 |
return new String(data, chars.name()); |
|
135 | 147 |
} |
136 | 148 |
|
137 | 149 |
/** |
... | ... | |
357 | 369 |
// create the header to contain the header information. |
358 | 370 |
myHeader = new DbaseFileHeaderNIO(); |
359 | 371 |
myHeader.readHeader(buffer); |
372 |
|
|
373 |
charBuffer = CharBuffer.allocate(myHeader.getRecordLength() - 1); |
|
374 |
chars = Charset.forName("ISO-8859-1"); |
|
375 |
decoder = chars.newDecoder(); |
|
376 |
|
|
360 | 377 |
} |
361 | 378 |
|
362 | 379 |
/** |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/DbaseFileWriterNIO.java | ||
---|---|---|
67 | 67 |
import java.nio.MappedByteBuffer; |
68 | 68 |
import java.nio.channels.FileChannel; |
69 | 69 |
import java.nio.channels.WritableByteChannel; |
70 |
import java.nio.charset.Charset; |
|
70 | 71 |
import java.text.FieldPosition; |
71 | 72 |
import java.text.NumberFormat; |
72 | 73 |
import java.util.Calendar; |
... | ... | |
105 | 106 |
private final String NULL_STRING = ""; |
106 | 107 |
private final String NULL_DATE = " "; |
107 | 108 |
|
109 |
// TODO: READ HEADER AND STABLIST THE RIGHT CHARSET |
|
110 |
private Charset charset = Charset.forName("ISO-8859-1"); |
|
111 |
|
|
108 | 112 |
/** Create a DbaseFileWriter using the specified header and writing to the given |
109 | 113 |
* channel. |
110 | 114 |
* @param header The DbaseFileHeader to write. |
... | ... | |
156 | 160 |
// } |
157 | 161 |
|
158 | 162 |
|
159 |
buffer.put(fieldString.getBytes()); |
|
163 |
buffer.put(fieldString.getBytes(charset.name()));
|
|
160 | 164 |
|
161 | 165 |
} |
162 | 166 |
|
Also available in: Unified diff