Search in sources :

Example 11 with FileImageInputStreamExtImpl

use of it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl in project imageio-ext by geosolutions-it.

the class StringImageInputStreamSpi method createInputStreamInstance.

/**
 * @see javax.imageio.spi.ImageInputStreamSpi#createInputStreamInstance(java.lang.Object,
 *      boolean, java.io.File)
 */
public ImageInputStream createInputStreamInstance(Object input, boolean useCache, File cacheDir) throws IOException {
    // is it a String?
    if (!(input instanceof String)) {
        if (LOGGER.isLoggable(Level.FINE))
            LOGGER.fine("The provided input is not a valid String.");
        return null;
    }
    final String sourceString = ((String) input);
    // 
    try {
        // the needed checks are done inside the constructor
        final URL tempURL = new URL(sourceString);
        return new URLImageInputStreamSpi().createInputStreamInstance(tempURL, ImageIO.getUseCache(), ImageIO.getCacheDirectory());
    } catch (Throwable e) {
        if (LOGGER.isLoggable(Level.FINE))
            LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
    }
    // 
    // as a FILE
    // 
    final File tempFile = new File(sourceString);
    try {
        // the needed checks are done inside the constructor
        return new FileImageInputStreamExtImpl(tempFile);
    } catch (Throwable e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : FileImageInputStreamExtImpl(it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl) File(java.io.File) URL(java.net.URL)

Example 12 with FileImageInputStreamExtImpl

use of it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl in project imageio-ext by geosolutions-it.

the class TestImageInputStream method imageInputStreamExtInvalidContructor2.

/**
 *  Test if <code>FileNotFoundException</code> is thrown when a non-existing file is passed.
 */
@Test
public void imageInputStreamExtInvalidContructor2() {
    try {
        File file = new File("this/file/is/invalid");
        new FileImageInputStreamExtImpl(file);
        Assert.fail("FileNotFoundException must be thrown.");
    } catch (FileNotFoundException e) {
    // OK
    } catch (Exception e) {
        Assert.fail(e.getClass().getSimpleName() + " should not be thrown");
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) FileImageInputStreamExtImpl(it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl) File(java.io.File) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) HeadlessException(java.awt.HeadlessException) Test(org.junit.Test)

Example 13 with FileImageInputStreamExtImpl

use of it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl in project imageio-ext by geosolutions-it.

the class GeoTiffTest method readWithWarp.

/**
 * Test Read exploiting JAI-ImageIO tools capabilities
 * and GDAL warp.
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@Test
public void readWithWarp() throws FileNotFoundException, IOException {
    if (!isGDALAvailable) {
        return;
    }
    final ParameterBlockJAI pbjImageRead;
    String fileName = "utmByte.tif";
    final File file = TestData.file(this, fileName);
    SpatialReference destinationReference = new SpatialReference();
    destinationReference.SetProjCS("UTM 17 (WGS84) in northern hemisphere.");
    destinationReference.SetWellKnownGeogCS("WGS84");
    destinationReference.SetUTM(17, 1);
    GDALImageReadParam readParam = new GDALImageReadParam();
    readParam.setDestinationWkt(destinationReference.ExportToWkt());
    readParam.setResampleAlgorithm(ResampleAlgorithm.CUBIC);
    pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", new FileImageInputStreamExtImpl(file));
    pbjImageRead.setParameter("Reader", new GeoTiffImageReaderSpi().createReaderInstance());
    pbjImageRead.setParameter("ReadParam", readParam);
    RenderedOp image = JAI.create("ImageRead", pbjImageRead);
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image, "", true);
    else
        Assert.assertNotNull(image.getTiles());
}
Also used : RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) SpatialReference(org.gdal.osr.SpatialReference) FileImageInputStreamExtImpl(it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl) GDALImageReadParam(it.geosolutions.imageio.gdalframework.GDALImageReadParam) File(java.io.File) AbstractGDALTest(it.geosolutions.imageio.gdalframework.AbstractGDALTest) Test(org.junit.Test)

Aggregations

FileImageInputStreamExtImpl (it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl)13 File (java.io.File)12 Test (org.junit.Test)9 IOException (java.io.IOException)7 FileImageInputStreamExt (it.geosolutions.imageio.stream.input.FileImageInputStreamExt)4 AbstractGDALTest (it.geosolutions.imageio.gdalframework.AbstractGDALTest)3 HeadlessException (java.awt.HeadlessException)3 FileNotFoundException (java.io.FileNotFoundException)3 MalformedURLException (java.net.MalformedURLException)3 ParameterBlockJAI (javax.media.jai.ParameterBlockJAI)3 RenderedOp (javax.media.jai.RenderedOp)3 TIFFImageReader (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader)2 TIFFImageReaderSpi (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi)2 MetadataNode (it.geosolutions.imageioimpl.plugins.tiff.TIFFStreamMetadata.MetadataNode)2 Rectangle (java.awt.Rectangle)2 BufferedImage (java.awt.image.BufferedImage)2 URI (java.net.URI)2 ImageReadParam (javax.imageio.ImageReadParam)2 IIOMetadata (javax.imageio.metadata.IIOMetadata)2 IIOMetadataNode (javax.imageio.metadata.IIOMetadataNode)2