Java 8 ImageReaderSpi - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ImageReaderSpi class.

This code example shows how to use the following methods:getFileSuffixes, getFormatNames, getMIMETypes
        Assert.assertTrue(extensions.containsAll(possibleExt));
 
        // Creation of a NetCDFReaderSPI objectfor checking if it supports the GRIB extension 
        ImageReaderSpi spi = new NetCDFImageReaderSpi();
        // Selection of the suffixes, formatNames and mimetypes from the spi object 
        List<String> suffixes = Arrays.asList(spi.getFileSuffixes());
        List<String> formatNames = Arrays.asList(spi.getFormatNames());
        List<String> MIMETypes = Arrays.asList(spi.getMIMETypes());
        // Creation of similar lists containing the values for the grib format 
        List<String> gribSuffixes = Arrays.asList(new String[] { "grib", "grb", "grb2" });
        List<String> gribFormatNames = Arrays.asList(new String[] { "grib", "grib2", "GRIB",
                "GRIB2" }); 
        List<String> gribMIMETypes = Arrays.asList(new String[] { "application/octet-stream" });
        // Check if the grib informations are present 
        Assert.assertTrue(suffixes.containsAll(gribSuffixes));
        Assert.assertTrue(formatNames.containsAll(gribFormatNames));
        Assert.assertTrue(MIMETypes.containsAll(gribMIMETypes));
    } 
 
    /** 
6
CodeRank
This code example shows how to use the following methods:deregisterServiceProvider, getServiceProviderByClass, registerServiceProvider
            // If JRE contains imageio.jar in lib/ext, get spi classes and unregister them 
            spiClass = Class.forName(clazz.getName(), true, ClassLoader.getSystemClassLoader());
        } catch (ClassNotFoundException e) {
        } 
        if (spiClass != null) {
            Object spi = registry.getServiceProviderByClass(spiClass);
            if (spi != null) { 
                registry.deregisterServiceProvider(spi);
            } 
        } 
        try { 
            // Resister again the spi classes with the bundle classloader 
            registry.registerServiceProvider(clazz.newInstance());
        } catch (Exception e) {
            e.printStackTrace();
        } 
    } 
 
    public static void unRegisterServiceProvider(Class clazz) {
        Object spi = registry.getServiceProviderByClass(clazz);
5
CodeRank
This code example shows how to use the following methods:registerServiceProvider
    public ImageReader createReaderInstance(Object extension) {
        return new JPEGImageReader(this);
    } 
 
    public static void registerSpis(IIORegistry reg) {
        reg.registerServiceProvider(getReaderSpi(), ImageReaderSpi.class);
    } 
 
    public static synchronized JPEGImageReaderSpi getReaderSpi() { 
        if (readerSpi == null)
            readerSpi = new JPEGImageReaderSpi();
        return readerSpi;
    } 
} 
3
CodeRank
This code example shows how to use the following methods:canDecodeInput
        // Check if the grib file is accepted by the NetCDF driver 
        AbstractGridFormat format = new GRIBFormat();
        Assert.assertTrue(format.accepts(file));
        // Check if the netcdf reader spi object can read the input file 
        ImageReaderSpi spi = new NetCDFImageReaderSpi();
        Assert.assertTrue(spi.canDecodeInput(file));
    } 
     
    @Test
    public void testImage() throws FileNotFoundException, IOException {
        // Selection of the input file 
        File file = TestData.file(this, "sampleGrib.grb2");
        // Creation of a NetCDF reader for the grib data 
        NetCDFReader reader = new NetCDFReader(file, null);
        Assert.assertNotNull(reader);
 
        try { 
            // Selection of the coverage names 
            String[] coverageNames = reader.getGridCoverageNames();
            // Check if almost one coverage is present 
5
CodeRank
This code example shows how to use the following methods:canDecodeInput
				if (reader != null)
					spi = reader.getOriginatingProvider();
				else 
					return false; 
			} 
            return spi.canDecodeInput(stream);
        } catch (IOException e) {
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
            } 
            return false; 
        } 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:canDecodeInput
     * @see org.geotools.data.coverage.grid.AbstractGridFormat#accepts(java.lang.Object input) 
     */ 
    @Override 
    public boolean accepts(Object input,Hints hints) {
        try { 
            return spi.canDecodeInput(input);
        } catch (IOException e) {
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
            } 
            return false; 
        } 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getInputTypes
        return delegateProvider.getDescription(locale);
    } 
 
    @Override 
    public Class[] getInputTypes() {
        return delegateProvider.getInputTypes();
    } 
} 
3
CodeRank
This code example shows how to use the following methods:canDecodeInput
     * @see org.geotools.data.coverage.grid.AbstractGridFormat#accepts(java.lang.Object input) 
     */ 
    @Override 
    public boolean accepts(Object input,Hints hints) {
        try { 
            return spi.canDecodeInput(input);
        } catch (IOException e) {
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
            } 
            return false; 
        } 
    } 
     
    /** 
     * Return a ParameterGroup with default General Parameter Descriptors. 
     * @param mInfo Set of properties info 
     * @return a {@link ParameterGroup} with Default {@link GeneralParameterDescriptors}. 
     */ 
    protected static ParameterGroup getDefaultParameterGroup(Map<String,String> mInfo){
5
CodeRank
This code example shows how to use the following methods:createReaderInstance
        if(newSpi!=null){
            // Creation of the associated Writer 
            ImageReader reader = null;
            ImageInputStream stream = null;
            try { 
                reader = newSpi.createReaderInstance();
                if (source instanceof FileResource) { 
                    // file 
                    stream= new FileImageInputStreamExtImpl(((FileResource)source).getFile());
                    // Image reading 
                    reader.setInput(stream);
                    return reader.read(0);                    
                } else { 
                    // create a stream and move on 
                    source=((Resource)source).getInputStream(); 
                } 
                 
                // Check if the input object is an InputStream 
                if (source instanceof InputStream) {
                    // Use of the ImageInputStreamAdapter 
4
CodeRank
This code example shows how to use the following methods:canDecodeInput
 
    @Test
    public void testProviderNotMatchJPEG() throws IOException {
        // This JPEG contains PICT magic bytes at locations a PICT would normally have them. 
        // We should not claim to be able read it. 
        assertFalse(sProvider.canDecodeInput(
                new TestData(getClassLoaderResource("/jpeg/R-7439-1151526181.jpeg"), 
                new Dimension(386, 396)
        ))); 
    } 
} 
3
CodeRank
See Code Examples for Java 8 ImageReaderSpi Methods: