001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.io.importexport;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.io.File;
007import java.io.IOException;
008import java.io.InputStream;
009
010import org.openstreetmap.josm.actions.ExtensionFileFilter;
011import org.openstreetmap.josm.gui.io.importexport.GpxImporter.GpxImporterData;
012import org.openstreetmap.josm.io.rtklib.RtkLibPosReader;
013
014/**
015 * File importer allowing to import RTKLib files (*.pos files).
016 * @since 15247
017 */
018public class RtkLibImporter extends GpxLikeImporter<RtkLibPosReader> {
019
020    /**
021     * The RtkLib file filter (*.pos files).
022     */
023    public static final ExtensionFileFilter FILE_FILTER = ExtensionFileFilter.newFilterWithArchiveExtensions(
024            "pos", "pos", tr("RTKLib Positioning Solution Files"), false);
025
026    /**
027     * Constructs a new {@code RtkLibImporter}.
028     */
029    public RtkLibImporter() {
030        super(FILE_FILTER, RtkLibPosReader.class);
031    }
032
033    /**
034     * Replies the new GPX and marker layers corresponding to the specified RTKLib file.
035     * @param is input stream to RTKLib data
036     * @param associatedFile RTKLib file
037     * @param gpxLayerName The GPX layer name
038     * @return the new GPX and marker layers corresponding to the specified RTKLib file
039     * @throws IOException if an I/O error occurs
040     */
041    public static GpxImporterData loadLayers(InputStream is, final File associatedFile,
042                                             final String gpxLayerName) throws IOException {
043        final RtkLibPosReader r = buildAndParse(is, RtkLibPosReader.class);
044        final boolean parsedProperly = r.getNumberOfCoordinates() > 0;
045        r.getGpxData().storageFile = associatedFile;
046        return GpxImporter.loadLayers(r.getGpxData(), parsedProperly, gpxLayerName);
047    }
048}