Last change
on this file since 6992 was 6552, checked in by simon04, 10 years ago |
Refactoring: introduce Utils.UTF_8 charset to avoid handling of UnsupportedEncodingException
According to the Javadoc of Charset , every implementation of the Java
platform is required to support UTF-8.
|
File size:
1.4 KB
|
Line | |
---|
1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.io.BufferedWriter;
|
---|
7 | import java.io.File;
|
---|
8 | import java.io.FileOutputStream;
|
---|
9 | import java.io.IOException;
|
---|
10 | import java.io.OutputStreamWriter;
|
---|
11 | import java.io.Writer;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.actions.ExtensionFileFilter;
|
---|
14 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
15 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
16 | import org.openstreetmap.josm.tools.Utils;
|
---|
17 |
|
---|
18 | public class GeoJSONExporter extends FileExporter {
|
---|
19 |
|
---|
20 | public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
|
---|
21 | "json,geojson", "json", tr("GeoJSON Files") + " (*.json *.geojson)");
|
---|
22 |
|
---|
23 | public GeoJSONExporter() {
|
---|
24 | super(FILE_FILTER);
|
---|
25 | }
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public void exportData(File file, Layer layer) throws IOException {
|
---|
29 | if (layer instanceof OsmDataLayer) {
|
---|
30 | String json = new GeoJSONWriter((OsmDataLayer) layer).write();
|
---|
31 | Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), Utils.UTF_8));
|
---|
32 | try {
|
---|
33 | out.write(json);
|
---|
34 | } finally {
|
---|
35 | Utils.close(out);
|
---|
36 | }
|
---|
37 | } else {
|
---|
38 | throw new IllegalArgumentException(tr("Layer ''{0}'' not supported", layer.getClass().toString()));
|
---|
39 | }
|
---|
40 | }
|
---|
41 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.