src/main/java/de/blau/android/osm/OsmGpxApi.java
/**
     * Download a track
     * 
     * We currently force gpx format download which will lead to multiple appended GPX tracks for multi-file archives
     * 
     * @param server the Server object for the API instance to use
     * @param id id of the track to download
     * @param destination director to write the file/dir to
     * @param name file name to use
     * @return a Uri pointing to the file or directory
     */
Download a track

We currently force gpx format download which will lead to multiple appended GPX tracks for multi-file archives


Download a track We currently force gpx format download which will lead to multiple appended GPX tracks for multi - file archives
@Nullable
    public static Uri downloadTrack(@NonNull Server server, long id, @NonNull String destination, @Nullable String name) {
        try (Response response = server.openConnectionForAuthenticatedAccess(getDownloadTrackUrl(server, id), Server.HTTP_GET, (RequestBody) null)) {
            Server.checkResponseCode(response);
            ResponseBody body = response.body();
            String fileName = name;
            if (fileName == null) {
                String contentDisposition = response.header(CONTENT_DISPOSITION_HEADER);
                if (contentDisposition != null) {
                    try {
                        fileName = ContentDispositionFileNameParser.parse(contentDisposition);
                    } catch (IllegalArgumentException e) {
                        Log.e(DEBUG_TAG, "Problem parsing header ", e);
                    }
                }
                if (fileName == null) {
                    fileName = Long.toString(System.currentTimeMillis());
                }
            }
            if (!fileName.endsWith(FileExtensions.GPX)) { 
                fileName = fileName + "." + FileExtensions.GPX;
            }
            File output = new File(destination, fileName);
            try (OutputStream fileStream = new FileOutputStream(output)) {
                StreamUtils.copy(body.byteStream(), fileStream);
            }
            return Uri.fromFile(output);
        } catch (IOException | NumberFormatException e) {
            Log.e(DEBUG_TAG, "Problem downloading GPX track ", e);
        }
        return null;
    }
@ Nullable public static Uri downloadTrack ( @ NonNull Server server , long id , @ NonNull String destination , @ Nullable String name ) { try ( Response response = server . openConnectionForAuthenticatedAccess ( getDownloadTrackUrl ( server , id ) , Server . HTTP_GET , ( RequestBody ) null ) ) { Server . checkResponseCode ( response ) ; ResponseBody body = response . body ( ) ; String fileName = name ; if ( fileName == null ) { String contentDisposition = response . header ( CONTENT_DISPOSITION_HEADER ) ; if ( contentDisposition != null ) { try { fileName = ContentDispositionFileNameParser . parse ( contentDisposition ) ; } catch ( IllegalArgumentException e ) { Log . e ( DEBUG_TAG , "Problem parsing header " , e ) ; } } if ( fileName == null ) { fileName = Long . toString ( System . currentTimeMillis ( ) ) ; } } if ( ! fileName . endsWith ( FileExtensions . GPX ) ) { fileName = fileName + "." + FileExtensions . GPX ; } File output = new File ( destination , fileName ) ; try ( OutputStream fileStream = new FileOutputStream ( output ) ) { StreamUtils . copy ( body . byteStream ( ) , fileStream ) ; } return Uri . fromFile ( output ) ; } catch ( IOException | NumberFormatException e ) { Log . e ( DEBUG_TAG , "Problem downloading GPX track " , e ) ; } return null ; }
Download a track
Download a track
// as we force GPX format, .gpx should be added if missing