@Override public RasterWriter getRasterWriter( String type ) { if ( type != null && FORMATS.contains( type.toLowerCase() ) ) { return new GridWriter(); } return null; }
@Override public void write( AbstractRaster raster, File gridFile, RasterIOOptions options ) throws IOException { if ( gridFile == null ) { throw new IOException( "No grid file given." ); } if ( envelope == null || ( this.gridFile != null && !this.gridFile.getAbsoluteFile().equals( gridFile.getAbsoluteFile() ) ) ) { instantiate( raster, gridFile, options ); } write( raster, options ); }
private ByteBufferRasterData readData( int column, int row ) throws IOException { synchronized ( LOCK ) { ByteBuffer buffer = tileData.getByteBuffer(); buffer.clear(); long position = calcFilePosition( column, row ); // transfer the data from the blob FileChannel channel = getReadChannel(); channel.position( position ); channel.read( buffer ); closeReadStream(); buffer.rewind(); return tileData; // return new PixelInterleavedRasterData( new RasterRect( 0, 0, tileRasterWidth, tileRasterHeight ), // tileRasterWidth, tileRasterHeight, this.dataInfo ); } }
/** * Signals the gridfile reader that it should (not) close the stream after a read. * * @param yesNo */ public void leaveStreamOpen( boolean yesNo ) { // System.out.println( "trying enter yesno: " + Thread.currentThread().getName() ); synchronized ( LOCK ) { this.leaveStreamOpen = yesNo; // System.out.println( "entered yesno: " + Thread.currentThread().getName() ); if ( !this.leaveStreamOpen ) { try { closeWriteStream(); closeReadStream(); } catch ( IOException e ) { LOG.debug( "Could not close stream because: {}", e.getLocalizedMessage(), e ); } } // System.out.println( "leaving yesno: " + Thread.currentThread().getName() ); } }
BandType.BLUE }, DataType.BYTE, InterleaveType.PIXEL ); try { GridWriter gw = new GridWriter( 1, 1, tileEnvelope, gRef, newCacheFile, rdi ); if ( gw.getTileRasterWidth() != imageWidth ) { gw.setTileRasterWidth( imageWidth ); if ( gw.getTileRasterHeight() != imageHeight ) { gw.setTileRasterHeight( imageHeight ); gw.writeEntireFile( imageBuffer ); File gmf = gw.writeMetadataFile( null ); if ( gmf != null ) { gmf.deleteOnExit();
int minColumn = getColumn( env.getMin().get0() ); int minRow = getRow( env.getMax().get1() ); int maxColumn = getColumn( env.getMax().get0() ); int maxRow = getRow( env.getMin().get1() ); this.leaveStreamOpen( true ); for ( int row = minRow; row <= maxRow; row++ ) { for ( int column = minColumn; column <= maxColumn; column++ ) { write( raster, column, row ); this.leaveStreamOpen( false ); this.closeWriteStream(); this.closeReadStream(); writeMetadataFile( options );
int rows = (int) Math.ceil( (double) height / tileHeight ); GridWriter gridWriter = new GridWriter( columns, rows, renv, geoRef, tmpGridFile, raster.getRasterDataInfo() ); FilteredResultWiter resultWriter = new FilteredResultWiter( gridWriter ); gridWriter.writeMetadataFile( null );
Envelope tileEnvelope = getTileEnvelope( column, row ); ByteBufferRasterData fileData = readData( column, row ); long position = calcFilePosition( column, row ); FileChannel fileChannel = getWriteChannel(); FileLock lock = fileChannel.lock( position, position + bytesPerTile, false ); fileChannel.position( position ); fileChannel.write( buffer ); lock.release(); closeWriteStream();
+ " Mb)" ); try { GridWriter writer = new GridWriter( columns, rows, renv, rasterReference, heixelFile, inf ); writer.write( raster, options ); } catch ( IOException e ) { e.printStackTrace();
/** * @param row * @param column * @param tileBuffer * @return true if the writing of the tile was successful. * @throws IOException */ public boolean writeTile( int column, int row, ByteBuffer tileBuffer ) throws IOException { if ( tileBuffer == null || tileBuffer.capacity() != this.bytesPerTile ) { throw new IllegalArgumentException( "Wrong number of bytes." ); } synchronized ( LOCK ) { long position = calcFilePosition( column, row ); FileChannel fileChannel = getWriteChannel(); FileLock lock = fileChannel.lock( position, position + bytesPerTile, false ); fileChannel.position( position ); tileBuffer.rewind(); fileChannel.write( tileBuffer ); lock.release(); closeWriteStream(); } return true; }
/** * @param newBytes * @throws IOException */ public void writeEntireFile( ByteBuffer newBytes ) throws IOException { if ( newBytes.capacity() != this.bytesPerTile ) { throw new IllegalArgumentException( "byte buffer is to small, required bytes:" + ( this.bytesPerTile ) + ", provided bytes: " + newBytes.capacity() ); } synchronized ( LOCK ) { FileChannel fileChannel = getWriteChannel(); FileLock lock = fileChannel.lock(); fileChannel.position( 0 ); newBytes.rewind(); fileChannel.write( newBytes ); lock.release(); closeWriteStream(); } }
LOG.info( "Writing tile: {} to temporary file. (Queue size: {})", filteredResult.first, outputStack.size() ); gridWriter.write( filteredResult.second, null ); LOG.info( "(flushing the queue) Writing tile: {} to temporary file. (Queue size: {})", filteredResult.first, outputStack.size() ); gridWriter.write( filteredResult.second, null );
private CacheRasterReader( CacheInfoFile readValues, File cacheFile, RasterReader reader, RasterCache cacheManager ) { this.cachedReader = reader; // GridMetaInfoFile gmif = readValues.gmif; this.cacheManager = cacheManager; if ( this.cacheManager == null ) { // get the default cache manager this.cacheManager = RasterCache.getInstance(); } super.instantiate( readValues, cacheFile ); try { this.gridWriter = new GridWriter( getTileColumns(), getTileRows(), getEnvelope(), getGeoReference(), cacheFile, getRasterDataInfo() ); } catch ( IOException e ) { LOG.warn( "Could not create a cache file writer because: {}. Only in memory caching is enabled.", e.getLocalizedMessage() ); } tiles = instantiateTiles(); }
try { LOG.debug( "Writing to file: " + cacheFile.getAbsolutePath() ); this.gridWriter = new GridWriter( getTileColumns(), getTileRows(), getEnvelope(), getGeoReference(), cacheFile, getRasterDataInfo() ); } catch ( IOException e ) {