@Override public BufferResult read( RasterRect rect, ByteBuffer buffer ) throws IOException { return reader == null ? null : reader.read( rect, buffer ); }
@Override public void dispose() { if ( reader != null ) { reader.dispose(); } } }
/** * @param metaData * a ImageIO meta data object * @param definedRasterOrigLoc */ public MetaDataReader( IIOMetadata metaData, OriginLocation definedRasterOrigLoc, int factor ) { this.metaData = metaData; this.factor = factor; if ( metaData != null ) { init( definedRasterOrigLoc ); } }
/** * Returns the height of the raster associated with the reader * * @return raster height */ public int getRows() { synchronized ( LOCK ) { if ( height == -1 && !heightReadFailed && findReaderForIO() ) { try { height = reader.getHeight( imageIndex ); } catch ( IOException e ) { LOG.debug( "couldn't open image for height:" + e.getMessage(), e ); this.heightReadFailed = true; } resetStream(); } } return height; }
@Override public void write( AbstractRaster raster, OutputStream out, RasterIOOptions options ) throws IOException { LOG.debug( "writing to stream with ImageIO" ); String format = options != null ? options.get( RasterIOOptions.OPT_FORMAT ) : null; if ( "geotiff".equals( format ) ) { GeoTiffWriter.save( raster, out ); } else { IIORasterDataWriter.saveRasterDataToStream( raster.getAsSimpleRaster().getRasterData(), out, format ); } }
@Override public AbstractRaster load( InputStream stream, RasterIOOptions options ) throws IOException { String imageIndex = options.get( RasterIOOptions.IMAGE_INDEX ); reader = new IIORasterDataReader( stream, options, imageIndex == null ? 0 : Integer.parseInt( imageIndex ) ); return loadFromReader( reader, options ); }
@Override public RasterReader getRasterReader( String type ) { if ( SUPPORTED_TYPES_READ.contains( type.toLowerCase() ) ) { return new IIORasterReader(); } return null; }
@Override public File file() { return reader == null ? null : reader.file(); }
/** * @return true if random access is easy for the image io reader. */ public boolean getReadTiles() { boolean result = false; synchronized ( LOCK ) { if ( findReaderForIO() ) { try { result = reader != null ? reader.isRandomAccessEasy( imageIndex ) : false; } catch ( IOException e ) { // just do nothing. } } } return result; }
@Override public boolean shouldCreateCacheFile() { return reader == null ? true : reader.shouldCreateCacheFile(); }
@Override public RasterDataInfo getRasterDataInfo() { return reader == null ? null : reader.getRasterDataInfo(); }
@Override public boolean canReadTiles() { return reader == null ? false : reader.getReadTiles(); }
@Override public RasterWriter getRasterWriter( String type ) { if ( SUPPORTED_TYPES_WRITE.contains( type.toLowerCase() ) ) { return new IIORasterWriter(); } return null; }
private void init( OriginLocation definedRasterOrigLoc ) { if ( metaData.getNativeMetadataFormatName().equals( TIFF_MD_FORMAT ) || metaData.getNativeMetadataFormatName().equals( "it_geosolutions_imageioimpl_plugins_tiff_image_1.0" ) ) { initGeoTIFF( definedRasterOrigLoc ); } }
/** * Returns the height of the raster associated with the reader * * @return raster height */ public int getColumns() { synchronized ( LOCK ) { if ( width == -1 && !widthReadFailed && findReaderForIO() ) { try { width = reader.getWidth( imageIndex ); } catch ( IOException e ) { LOG.debug( "couldn't open image for width:" + e.getMessage(), e ); this.widthReadFailed = true; } resetStream(); } } return width; }
@Override public AbstractRaster load( File file, RasterIOOptions options ) throws IOException { String imageIndex = options.get( RasterIOOptions.IMAGE_INDEX ); LOG.debug( "reading " + file + " with ImageIO" ); reader = new IIORasterDataReader( file, options, imageIndex == null ? 0 : Integer.parseInt( imageIndex ) ); AbstractRaster r = loadFromReader( reader, options ); return r; }
/** * loads the raster * * @param tileBaseDir * @return the loaded simpleraster * @throws IOException */ public AbstractRaster loadRaster( String tileBaseDir ) throws IOException { File file = new File( getFullFileName( tileBaseDir ) ); RasterReader reader = new IIORasterReader(); RasterIOOptions options = RasterIOOptions.forFile( file, getEnvelope() ); return reader.load( file, options ); }
/** * * @return true if the imageio thinks the file can be accessed easily */ boolean shouldCreateCacheFile() { boolean result = true; try { synchronized ( LOCK ) { if ( findReaderForIO() ) { result = !reader.isRandomAccessEasy( imageIndex ); } } } catch ( IOException e ) { LOG.debug( "Could not get easy access information from the imagereader, using configured value for using cache: " + result, e ); } return result; }
/** * @return the raw metadata of the raster */ protected IIOMetadata getMetaData() { // md == null, // 1. didn't read the metadata // 2. the reader couldn't read it, just do not try again. // 3. synchronized ( LOCK ) { if ( metaData == null && !metadataReadFailed && findReaderForIO() ) { try { metaData = reader.getImageMetadata( 0 ); } catch ( IOException e ) { LOG.debug( "couldn't open metadata:" + e.getMessage(), e ); this.metadataReadFailed = true; } resetStream(); } } return metaData; }