X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2Fsrtm%2FSrtmSource.java;h=0791cd833c28fc7a2acd14cb4901a1a675d3cae2;hp=5651a3f314656b155e979056ba1deafd0a6cb671;hb=641d7703cc141e71696979992923f4bcbb1806a9;hpb=94113b9f5f037cd56c07cca5f69f7f56620d84ef diff --git a/src/tim/prune/function/srtm/SrtmSource.java b/src/tim/prune/function/srtm/SrtmSource.java index 5651a3f..0791cd8 100644 --- a/src/tim/prune/function/srtm/SrtmSource.java +++ b/src/tim/prune/function/srtm/SrtmSource.java @@ -15,6 +15,21 @@ public abstract class SrtmSource { public abstract int getRowSize(SrtmTile inTile); protected abstract String getSourceExtension(); + protected int[] slurpTileHeigths(ZipInputStream inStream, int tileSize) + throws IOException + { + int[] heights = new int[tileSize]; + // Read entire file contents into one byte array + for (int i = 0; i < heights.length; i++) + { + heights[i] = inStream.read() * 256 + inStream.read(); + if (heights[i] >= 32768) {heights[i] -= 65536;} + } + // Close stream + inStream.close(); + return heights; + } + public int[] getTileHeights(SrtmTile inTile) throws SrtmSourceException { @@ -33,16 +48,7 @@ public abstract class SrtmSource { { throw new SrtmSourceException("Tile file "+cacheFileName+" does not have the expected size"); } - int[] heights = new int[tileSize]; - // Read entire file contents into one byte array - for (int i = 0; i < heights.length; i++) - { - heights[i] = inStream.read() * 256 + inStream.read(); - if (heights[i] >= 32768) {heights[i] -= 65536;} - } - // Close stream - inStream.close(); - return heights; + return slurpTileHeigths(inStream, tileSize); } catch (IOException e) { @@ -64,6 +70,8 @@ public abstract class SrtmSource { public boolean isCached(SrtmTile inTile) { - return getCacheFileName(inTile).exists(); + File cachedFileName = getCacheFileName(inTile); + return cachedFileName != null && + getCacheFileName(inTile).exists(); } }