private void processBlocks( IMapDatabaseCallback mapDatabaseCallback, QueryParameters queryParameters, SubFileParameter subFileParameter) throws IOException { boolean queryIsWater = true; // boolean queryReadWaterInfo = false; // read and process all blocks from top to bottom and from left to right for (long row = queryParameters.fromBlockY; row <= queryParameters.toBlockY; ++row) { for (long column = queryParameters.fromBlockX; column <= queryParameters.toBlockX; ++column) { // calculate the actual block number of the needed block in the // file long blockNumber = row * subFileParameter.blocksWidth + column; // get the current index entry long currentBlockIndexEntry = sDatabaseIndexCache.getIndexEntry(subFileParameter, blockNumber); // check if the current query would still return a water tile if (queryIsWater) { // check the water flag of the current block in its index // entry queryIsWater &= (currentBlockIndexEntry & BITMASK_INDEX_WATER) != 0; // queryReadWaterInfo = true; } // get and check the current block pointer long currentBlockPointer = currentBlockIndexEntry & BITMASK_INDEX_OFFSET; if (currentBlockPointer < 1 || currentBlockPointer > subFileParameter.subFileSize) { LOG.warning("invalid current block pointer: " + currentBlockPointer); LOG.warning("subFileSize: " + subFileParameter.subFileSize); return; } long nextBlockPointer; // check if the current block is the last block in the file if (blockNumber + 1 == subFileParameter.numberOfBlocks) { // set the next block pointer to the end of the file nextBlockPointer = subFileParameter.subFileSize; } else { // get and check the next block pointer nextBlockPointer = sDatabaseIndexCache.getIndexEntry(subFileParameter, blockNumber + 1) & BITMASK_INDEX_OFFSET; if (nextBlockPointer < 1 || nextBlockPointer > subFileParameter.subFileSize) { LOG.warning("invalid next block pointer: " + nextBlockPointer); LOG.warning("sub-file size: " + subFileParameter.subFileSize); return; } } // calculate the size of the current block int currentBlockSize = (int) (nextBlockPointer - currentBlockPointer); if (currentBlockSize < 0) { LOG.warning("current block size must not be negative: " + currentBlockSize); return; } else if (currentBlockSize == 0) { // the current block is empty, continue with the next block continue; } else if (currentBlockSize > ReadBuffer.MAXIMUM_BUFFER_SIZE) { // the current block is too large, continue with the next // block LOG.warning("current block size too large: " + currentBlockSize); continue; } else if (currentBlockPointer + currentBlockSize > mFileSize) { LOG.warning("current block largher than file size: " + currentBlockSize); return; } // seek to the current block in the map file mInputFile.seek(subFileParameter.startAddress + currentBlockPointer); // read the current block into the buffer if (!mReadBuffer.readFromFile(currentBlockSize)) { // skip the current block LOG.warning("reading current block has failed: " + currentBlockSize); return; } // calculate the top-left coordinates of the underlying tile double tileLatitudeDeg = MercatorProjection.tileYToLatitude( subFileParameter.boundaryTileTop + row, subFileParameter.baseZoomLevel); double tileLongitudeDeg = MercatorProjection.tileXToLongitude( subFileParameter.boundaryTileLeft + column, subFileParameter.baseZoomLevel); mTileLatitude = (int) (tileLatitudeDeg * 1000000); mTileLongitude = (int) (tileLongitudeDeg * 1000000); try { processBlock(queryParameters, subFileParameter, mapDatabaseCallback); } catch (ArrayIndexOutOfBoundsException e) { LOG.log(Level.SEVERE, null, e); } } } // the query is finished, was the water flag set for all blocks? // if (queryIsWater && queryReadWaterInfo) { // Tag[] tags = new Tag[1]; // tags[0] = TAG_NATURAL_WATER; // // System.arraycopy(WATER_TILE_COORDINATES, 0, mWayNodes, // mWayNodePosition, 8); // mWayNodePosition += 8; // mapDatabaseCallback.renderWaterBackground(tags, wayDataContainer); // } }