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);
}
}
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");
}
}
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());
}
Aggregations