- System.out.println("Download: Need to download: " + tileUrl);
- try
- {
- HttpURLConnection conn = (HttpURLConnection) tileUrl.openConnection();
-
- // Define streams
- InputStream inStream = null;
-
- conn.setRequestProperty("User-Agent", "GpsPrune v" + GpsPrune.VERSION_NUMBER);
-
- int status = conn.getResponseCode();
- if (status == 200)
- {
- inStream = conn.getInputStream();
- }
- else if (status == 404)
- {
- throw new SrtmSourceException("Tile not found: "+conn.getURL());
- }
- else
- {
- throw new SrtmSourceException("Invalid response from server: " +status+conn.getContent());
- }
-
- return downloadToFile(inStream, getCacheFileName(inTile));
- }
- catch (IOException e)
- {
- throw new SrtmSourceException("Error while downloading tile "+inTile.getTileName()+": "+e.getMessage());
- }
+ InputStream inStream = getStreamToUrl(tileUrl);
+ return readToFile(inStream, getCacheFileName(inTile));