Revision 46054 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/CSVUtils.java
CSVUtils.java | ||
---|---|---|
29 | 29 |
import java.io.FileNotFoundException; |
30 | 30 |
import java.io.FileReader; |
31 | 31 |
import java.io.IOException; |
32 |
import java.io.InputStream; |
|
32 | 33 |
import java.io.InputStreamReader; |
34 |
import java.io.Reader; |
|
33 | 35 |
import java.nio.charset.Charset; |
34 | 36 |
import java.util.Locale; |
35 | 37 |
import java.util.Map; |
36 | 38 |
import org.apache.commons.io.FilenameUtils; |
37 | 39 |
import org.apache.commons.io.IOUtils; |
40 |
import org.apache.commons.io.input.BOMInputStream; |
|
38 | 41 |
import org.apache.commons.lang3.ArrayUtils; |
39 | 42 |
import org.apache.commons.lang3.StringUtils; |
40 | 43 |
import org.gvsig.fmap.dal.DataTypes; |
... | ... | |
69 | 72 |
public static InputStreamReader openFile(File f, String charsetName) throws FileNotFoundException { |
70 | 73 |
String fullFileName = f==null? "NULL":f.getAbsolutePath(); |
71 | 74 |
Charset charset = Charset.defaultCharset(); |
72 |
FileInputStream fis = new FileInputStream(f);
|
|
75 |
InputStream fis = new BOMInputStream(new FileInputStream(f));
|
|
73 | 76 |
if (StringUtils.isNotBlank(charsetName)) { |
74 | 77 |
if (Charset.isSupported(charsetName)) { |
75 | 78 |
try { |
... | ... | |
156 | 159 |
IOUtils.closeQuietly(reader); |
157 | 160 |
} |
158 | 161 |
} |
159 |
public static SimpleReader getSimpleReader(CSVStoreParameters parameters, InputStreamReader in) throws IOException {
|
|
162 |
public static SimpleReader getSimpleReader(CSVStoreParameters parameters, Reader in) throws IOException { |
|
160 | 163 |
SimpleReader reader; |
161 | 164 |
String filename = CSVStoreParameters.getFileName(parameters); |
162 | 165 |
if (FilenameUtils.isExtension(filename, "json")){ |
... | ... | |
195 | 198 |
} |
196 | 199 |
AutomaticDetectionOfTypes.DetectedValue[] types = null; |
197 | 200 |
|
198 |
FileReader in = null;
|
|
201 |
Reader in = null; |
|
199 | 202 |
SimpleReader reader = null; |
200 | 203 |
|
201 | 204 |
try { |
202 |
in = new FileReader(parameters.getFile()); |
|
205 |
in = openFile( |
|
206 |
parameters.getFile(), |
|
207 |
CSVStoreParameters.getCharset(parameters) |
|
208 |
); |
|
203 | 209 |
reader = getSimpleReader(parameters, in); |
204 | 210 |
AutomaticDetectionOfTypes x = new AutomaticDetectionOfTypes( |
205 | 211 |
fullFileName |
Also available in: Unified diff