public void dispose() { leaveStreamOpen( false ); try { closeReadStream(); } catch ( IOException e ) { if ( LOG.isDebugEnabled() ) { LOG.debug( "(Stack) Exception occurred: " + e.getLocalizedMessage(), e ); } else { LOG.error( "Exception occurred: " + e.getLocalizedMessage() ); } } }
@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 } ); } }
@Override public BufferResult read( RasterRect rect, ByteBuffer resultBuffer ) throws IOException { BufferResult res = null; RasterRect fRect = snapToGrid( rect ); if ( fRect != null ) { int[] minCRmaxCR = getIntersectingTiles( fRect ); if ( minCRmaxCR == null ) { return null; } int size = fRect.width * fRect.height * sampleSize; if ( resultBuffer == null ) { resultBuffer = ByteBufferPool.allocate( size, false ); } synchronized ( LOCK ) { FileChannel channel = getFileChannel(); RasterRect tmpRect = new RasterRect( 0, 0, fRect.width, fRect.height ); for ( int col = minCRmaxCR[0]; col <= minCRmaxCR[2]; ++col ) { for ( int row = minCRmaxCR[1]; row <= minCRmaxCR[3]; ++row ) { readValuesFromTile( col, row, fRect, channel, resultBuffer ); } } res = new BufferResult( tmpRect, resultBuffer ); closeReadStream(); } } return res; }