Changeset 30508 in osm for applications/editors/josm/plugins
- Timestamp:
- 2014-07-01T21:07:01+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java
r30340 r30508 5 5 6 6 import java.awt.Component; 7 import java.io.BufferedReader; 7 8 import java.io.File; 8 9 import java.io.IOException; 9 10 import java.io.InputStream; 11 import java.nio.charset.Charset; 12 import java.nio.charset.IllegalCharsetNameException; 13 import java.nio.charset.StandardCharsets; 14 import java.nio.charset.UnsupportedCharsetException; 15 import java.nio.file.Files; 16 import java.nio.file.Path; 10 17 import java.util.HashMap; 11 18 import java.util.HashSet; … … 168 175 if (file != null) { 169 176 Map params = new HashMap(); 177 Charset charset = null; 170 178 params.put(ShapefileDataStoreFactory.URLP.key, file.toURI().toURL()); 171 179 if (handler != null && handler.getDbfCharset() != null) { 172 params.put(ShapefileDataStoreFactory.DBFCHARSET.key, handler.getDbfCharset()); 180 charset = handler.getDbfCharset(); 181 } else { 182 String path = file.getAbsolutePath(); 183 // See http://gis.stackexchange.com/a/3663/17245 184 path = path.substring(0, path.lastIndexOf('.')) + ".cpg"; 185 Path cpg = new File(path).toPath(); 186 if (Files.exists(cpg)) { 187 try (BufferedReader reader = Files.newBufferedReader(cpg, StandardCharsets.UTF_8)) { 188 charset = Charset.forName(reader.readLine()); 189 } catch (IOException | UnsupportedCharsetException | IllegalCharsetNameException e) { 190 Main.warn(e); 191 } 192 } 193 } 194 if (charset != null) { 195 Main.info("Using charset "+charset); 196 params.put(ShapefileDataStoreFactory.DBFCHARSET.key, charset); 173 197 } 174 198 DataStore dataStore = new ShapefileDataStoreFactory().createDataStore(params);//FIXME … … 202 226 } 203 227 } catch (UserCancelException e) { 204 228 e.printStackTrace(); 205 229 return ds; 206 230 } … … 211 235 } 212 236 } catch (Throwable e) { 213 237 e.printStackTrace(); 214 238 } finally { 215 239 iterator.close(); … … 221 245 } 222 246 } catch (IOException e) { 223 247 e.printStackTrace(); 224 248 throw e; 225 249 } catch (Throwable t) { 226 250 t.printStackTrace(); 227 251 throw new IOException(t); 228 252 }
Note:
See TracChangeset
for help on using the changeset viewer.