]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - src/tim/prune/function/srtm/SrtmViewfinderSource.java
Download tiles in chunks
[GpsPrune.git] / src / tim / prune / function / srtm / SrtmViewfinderSource.java
index 17790ae2f2b1cc3cee89bc4d7cad52fcb3104ac2..a25e9c4e95b55b68341a520df62ad19f54aac00e 100644 (file)
@@ -130,15 +130,12 @@ public class SrtmViewfinderSource extends SrtmSource {
                throws SrtmSourceException
        {
                URL tileUrl = buildUrl(inTile);
-               File outputFile = getCacheFileName(inTile);
                System.out.println("Download: Need to download: " + tileUrl);
-
                try
                {
                        HttpURLConnection conn = (HttpURLConnection) tileUrl.openConnection();
 
                        // Define streams
-                       FileOutputStream outStream = null;
                        InputStream inStream = null;
 
                        conn.setRequestProperty("User-Agent", "GpsPrune v" + GpsPrune.VERSION_NUMBER);
@@ -157,17 +154,7 @@ public class SrtmViewfinderSource extends SrtmSource {
                                throw new SrtmSourceException("Invalid response from server: " +status+conn.getContent());
                        }
 
-                       outStream = new FileOutputStream(outputFile);
-
-                       int c;
-                       while ((c = inStream.read()) != -1)
-                       {
-                               outStream.write(c);
-                       }
-                       // Make sure streams are closed
-                       try {inStream.close();} catch (Exception e) {}
-                       try {outStream.close();} catch (Exception e) {}
-                       return true;
+                       return downloadToFile(inStream, getCacheFileName(inTile));
                }
                catch (IOException e)
                {