]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - src/tim/prune/function/srtm/SrtmGl1Source.java
Download tiles in chunks
[GpsPrune.git] / src / tim / prune / function / srtm / SrtmGl1Source.java
index 51e6d770cee72fcef87eb19afdf1da633fc31234..f8639b7837a2bdf3ebae19b6837ddb71f759c87e 100644 (file)
@@ -88,10 +88,7 @@ public class SrtmGl1Source extends SrtmSource {
                try
                {
                        HttpURLConnection conn = (HttpURLConnection) tileUrl.openConnection();
-                       long fileLength = 0L;
-
                        // Define streams
-                       FileOutputStream outStream = null;
                        InputStream inStream = null;
 
                        // Documentation about HTTP interface at:
@@ -114,7 +111,6 @@ public class SrtmGl1Source extends SrtmSource {
                                {
                                        // Found the tile, we're good
                                        inStream = conn.getInputStream();
-                                       fileLength = conn.getContentLengthLong();
                                        break;
                                }
                                else if (status == 302)
@@ -133,22 +129,7 @@ public class SrtmGl1Source extends SrtmSource {
                                }
                        }
 
-                       // _progress.setValue(t * 10 + 1);
-                       outStream = new FileOutputStream(outputFile);
-
-                       // Copy all the bytes to the file
-                       int c;
-                       long written = 0L;
-                       while ((c = inStream.read()) != -1)
-                       {
-                               outStream.write(c);
-                               written++;
-                               // _progress.setValue(t * 10 + 1 + (int) ((10 * written) / fileLength));
-                       }
-                       // Make sure streams are closed
-                       try {inStream.close();} catch (Exception e) {}
-                       try {outStream.close();} catch (Exception e) {}
-                       return true;
+                       return downloadToFile(inStream, outputFile);
                }
                catch (IOException e)
                {