/** * Instantiates this grid reader with the given information. * * @param infoFile * @param gridFile */ protected synchronized void instantiate( GridMetaInfoFile infoFile, File gridFile ) { super.instantiate( infoFile ); this.gridFile = gridFile; // set the location id to the grid files file name. if ( this.dataLocationId == null && gridFile != null ) { this.dataLocationId = FileUtils.getFilename( this.gridFile ); } // if ( gridFile != null ) { // // set the tiles per blob depend on the gridFile size (if not full etc.) // setTilesPerBlob( (int) ( gridFile.length() / getBytesPerTile() ) ); // } LOG.debug( "Tiles in grid blob (" + gridFile + "): " + getTilesPerBlob() ); }
@Override protected void read( int columnId, int rowId, ByteBuffer buffer ) throws IOException { int tileId = getTileId( columnId, rowId ); long begin = System.currentTimeMillis(); int tileInBlob = tileId % getTilesPerBlob(); // transfer the data from the blob try { synchronized ( LOCK ) { FileChannel channel = getFileChannel(); // MappedByteBuffer map = channel.map( MapMode.READ_ONLY, tileInBlob * getBytesPerTile(), // buffer.remaining() ); // buffer.put( map ); // map. // LOG.debug( "Tile id: {} -> pos in blob: {}", tileId, +tileInBlob ); channel.position( tileInBlob * getBytesPerTile() ); channel.read( buffer ); closeReadStream(); } // rewinding is not an option, buffer.rewind(); } catch ( IOException e ) { LOG.error( "Error reading tile data from blob: " + e.getMessage(), e ); } long elapsed = System.currentTimeMillis() - begin; if ( LOG.isDebugEnabled() ) { LOG.debug( "Loading of tile ({}x{}) in {} ms.", new Object[] { infoFile.getTileRasterWidth(), infoFile.getTileRasterHeight(), elapsed } ); } }
long filePos = ( ( tileId % getTilesPerBlob() ) * getBytesPerTile() );
if ( getTilesPerBlob() != expectedTilesPerBlob ) { LOG.error( "the number of tiles in the blob are wrong." ); super.setTilesPerBlob( expectedTilesPerBlob );