/** * Delete the file this cache reader is using. * * @return true if this cached reader no longer references an existing file. */ public boolean deleteCacheFile() { boolean result = true; synchronized ( LOCK ) { super.dispose(); File f = file(); if ( f != null ) { if ( f.exists() && f.isFile() ) { result = f.delete(); File metaInfo = GridMetaInfoFile.fileNameFromOptions( f.getParent(), FileUtils.getFilename( f ), null ); if ( metaInfo.exists() ) { boolean mR = metaInfo.delete(); if ( !mR ) { LOG.warn( "Could not delete meta info file for raster cache file: " + f.getAbsolutePath() ); } } } } } return result; }
/** * Writes the metadata file for this grid file. * * @param options * @return the file containing the metainfo * @throws IOException */ public File writeMetadataFile( RasterIOOptions options ) throws IOException { File metaInfo = null; if ( gridFile != null ) { metaInfo = GridMetaInfoFile.fileNameFromOptions( gridFile.getParent(), FileUtils.getFilename( gridFile ), options ); } else { throw new IOException( "No gridfile specified, could not write the info file" ); } GridMetaInfoFile.writeToFile( metaInfo, new GridMetaInfoFile( this.geoRef, this.rows, this.columns, this.tileRasterWidth, this.tileRasterHeight, this.dataInfo ), options ); return metaInfo; }
if ( cacheFile != null && cacheFile.exists() ) { String parent = cacheFile.getParent(); File metaInfo = GridMetaInfoFile.fileNameFromOptions( parent, FileUtils.getFilename( cacheFile ), null ); if ( !metaInfo.exists() ) { LOG.warn(
/** * @param options * @throws IOException * @throws NumberFormatException */ private synchronized void instantiate( File gridFile, RasterIOOptions options ) throws NumberFormatException, IOException { if ( infoFile == null && gridFile != null ) { this.dataLocationId = options == null ? FileUtils.getFilename( gridFile ) : options.get( RasterIOOptions.ORIGIN_OF_RASTER ); File metaInfo = GridMetaInfoFile.fileNameFromOptions( gridFile.getParent(), FileUtils.getFilename( gridFile ), options ); this.instantiate( GridMetaInfoFile.readFromFile( metaInfo, options ), gridFile ); } }
private boolean writeCacheInfo() { boolean result = false; if ( gridWriter != null && file() != null ) { File metaInfo = GridMetaInfoFile.fileNameFromOptions( file().getParent(), FileUtils.getFilename( file() ), null ); boolean[][] tilesOnFiles = new boolean[getTileRows()][getTileColumns()]; for ( int row = 0; row < getTileRows(); ++row ) { for ( int col = 0; col < getTileColumns(); ++col ) { TileEntry entry = getEntry( col, row ); tilesOnFiles[row][col] = ( entry != null && entry.isOnFile() ); } } CacheInfoFile info = new CacheInfoFile( getGeoReference(), getTileRows(), getTileColumns(), getTileRasterWidth(), getTileRasterHeight(), getRasterDataInfo(), getWidth(), getHeight(), tilesOnFiles, file().lastModified() ); try { CacheInfoFile.write( metaInfo, info ); result = true; } catch ( IOException e ) { if ( LOG.isDebugEnabled() ) { LOG.debug( "Writing of info file failed, this will make the cachefile invalid. Reason: {}.", e.getLocalizedMessage(), e ); } else { LOG.debug( "Writing of info file failed, this will make the cachefile invalid. Reason: {}.", e.getLocalizedMessage() ); } } } return result; }