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
{
{
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)
{
public boolean isCached(SrtmTile inTile)
{
- return getCacheFileName(inTile).exists();
+ File cachedFileName = getCacheFileName(inTile);
+ return cachedFileName != null &&
+ getCacheFileName(inTile).exists();
}
}