source: josm/trunk/src/org/openstreetmap/josm/io/GeoJSONExporter.java@ 6966

Last change on this file since 6966 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.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.BufferedWriter;
7import java.io.File;
8import java.io.FileOutputStream;
9import java.io.IOException;
10import java.io.OutputStreamWriter;
11import java.io.Writer;
12
13import org.openstreetmap.josm.actions.ExtensionFileFilter;
14import org.openstreetmap.josm.gui.layer.Layer;
15import org.openstreetmap.josm.gui.layer.OsmDataLayer;
16import org.openstreetmap.josm.tools.Utils;
17
18public 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.