X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2Fsrtm%2FSrtm3Source.java;h=7e869f1d81f24cb3b2d1ea8f479fc228df12f650;hp=cc0da79b1c790f85e4a21ca473ea06b8bd457c9d;hb=4891d3eb6337b7b814485cab78583b0608183554;hpb=860ae36b24e22ff49b23cc5e3b51e9bd5520712b diff --git a/src/tim/prune/function/srtm/Srtm3Source.java b/src/tim/prune/function/srtm/Srtm3Source.java index cc0da79..7e869f1 100644 --- a/src/tim/prune/function/srtm/Srtm3Source.java +++ b/src/tim/prune/function/srtm/Srtm3Source.java @@ -1,14 +1,11 @@ package tim.prune.function.srtm; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; -import java.net.HttpURLConnection; -import tim.prune.GpsPrune; import tim.prune.I18nManager; public class Srtm3Source extends SrtmSource { @@ -59,7 +56,7 @@ public class Srtm3Source extends SrtmSource { return buffer; } } - catch (java.io.IOException e) { + catch (IOException e) { System.err.println("Exception trying to read srtmtiles.dat : " + e.getMessage()); } finally @@ -111,37 +108,8 @@ public class Srtm3Source 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 - 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, outputFile); - } - catch (IOException e) - { - throw new SrtmSourceException("Error while downloading tile "+inTile.getTileName()+": "+e.getMessage()); - } + InputStream inStream = getStreamToUrl(tileUrl); + return readToFile(inStream, getCacheFileName(inTile)); } public int getRowSize(SrtmTile inTile)