Revision 44395 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/CSVFeatureWriter.java
CSVFeatureWriter.java | ||
---|---|---|
6 | 6 |
package org.gvsig.fmap.dal.store.csv; |
7 | 7 |
|
8 | 8 |
import java.io.File; |
9 |
import java.io.FileOutputStream; |
|
9 | 10 |
import java.io.FileWriter; |
10 | 11 |
import java.io.IOException; |
12 |
import java.io.OutputStreamWriter; |
|
13 |
import java.io.Writer; |
|
11 | 14 |
import java.util.Locale; |
12 | 15 |
import org.gvsig.fmap.dal.DataTypes; |
13 |
import org.gvsig.fmap.dal.feature.Feature; |
|
14 | 16 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
15 | 17 |
import org.gvsig.fmap.dal.feature.FeatureType; |
16 | 18 |
import org.gvsig.fmap.dal.feature.exception.PerformEditingException; |
... | ... | |
35 | 37 |
private boolean calculate_envelope = false; |
36 | 38 |
private CsvListWriter listWriter = null; |
37 | 39 |
private CsvPreference csvpreferences = null; |
38 |
private FileWriter fwriter = null;
|
|
40 |
private Writer writer = null;
|
|
39 | 41 |
private FeatureType ftype; |
40 | 42 |
private File file; |
41 | 43 |
private String[] values; |
... | ... | |
46 | 48 |
private Locale locale = null; |
47 | 49 |
private CSVStoreParameters storeParameters; |
48 | 50 |
private static final Logger logger = LoggerFactory.getLogger(CSVFeatureWriter.class); |
51 |
private String charset = null; |
|
49 | 52 |
|
50 | 53 |
public void initialize(CSVStoreParameters storeParameters, File file, FeatureType ftype, CsvPreference csvpreferences) { |
51 | 54 |
this.file = file; |
... | ... | |
66 | 69 |
} |
67 | 70 |
this.convert = ToolsLocator.getDataTypesManager().getCoercion(org.gvsig.tools.dataTypes.DataTypes.STRING); |
68 | 71 |
this.errorcounts = 0; |
72 |
this.charset = CSVStoreParameters.getCharset(storeParameters); |
|
69 | 73 |
} |
70 | 74 |
|
71 | 75 |
public void beginAppend() { |
72 | 76 |
try { |
73 |
this.fwriter = new FileWriter(file, true); |
|
74 |
this.listWriter = new CsvListWriter(this.fwriter, this.csvpreferences); |
|
77 |
FileOutputStream fos = new FileOutputStream(file, true); |
|
78 |
if (this.charset != null) { |
|
79 |
this.writer = new OutputStreamWriter(fos, this.charset); |
|
80 |
} else { |
|
81 |
this.writer = new OutputStreamWriter(fos); |
|
82 |
} |
|
83 |
this.listWriter = new CsvListWriter(this.writer, this.csvpreferences); |
|
75 | 84 |
if (ftype != null) { |
76 | 85 |
this.descriptors = ftype.getAttributeDescriptors(); |
77 | 86 |
int n = 0; |
... | ... | |
91 | 100 |
|
92 | 101 |
public void begin() { |
93 | 102 |
try { |
94 |
this.fwriter = new FileWriter(file);
|
|
103 |
this.writer = new FileWriter(file); |
|
95 | 104 |
} catch (IOException e) { |
96 | 105 |
logger.warn("Can't open file for write (" + file.getAbsolutePath() + ").", e); |
97 | 106 |
throw new RuntimeException(e); |
98 | 107 |
} |
99 |
this.listWriter = new CsvListWriter(this.fwriter, this.csvpreferences);
|
|
108 |
this.listWriter = new CsvListWriter(this.writer, this.csvpreferences); |
|
100 | 109 |
int n = 0; |
101 | 110 |
for (FeatureAttributeDescriptor descriptor : descriptors) { |
102 | 111 |
if (descriptor.getEvaluator() == null) { |
... | ... | |
195 | 204 |
} |
196 | 205 |
listWriter = null; |
197 | 206 |
} |
198 |
if (fwriter != null) {
|
|
207 |
if (writer != null) { |
|
199 | 208 |
try { |
200 |
fwriter.close();
|
|
209 |
writer.close(); |
|
201 | 210 |
} catch (Exception ex) { |
202 | 211 |
// Ignore error |
203 | 212 |
} |
204 |
fwriter = null;
|
|
213 |
writer = null; |
|
205 | 214 |
} |
206 | 215 |
} |
207 | 216 |
|
Also available in: Unified diff