use of it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl in project imageio-ext by geosolutions-it.
the class TestImageInputStream method imageInputStreamExtInvalidContructor3.
/**
* Test if <code>FileNotFoundException</code> is thrown when a directory is passed.
*/
@Test
public void imageInputStreamExtInvalidContructor3() {
try {
URI fileURI = getClass().getResource(directoryName).toURI();
File file = new File(fileURI);
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 TestImageInputStream method imageInputStreamExtValidContructor.
/**
* Test if no exception is thrown when valid arguments are used.
*/
@Test
public void imageInputStreamExtValidContructor() {
try {
URI fileURI = getClass().getResource(directoryName + "/" + fileName).toURI();
File file = new File(fileURI);
new FileImageInputStreamExtImpl(file);
} 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 TIFFImageReader method setInput.
public void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata) {
super.setInput(input, seekForwardOnly, ignoreMetadata);
// Clear all local values based on the previous stream contents.
resetLocal();
if (input != null) {
if (!(input instanceof ImageInputStream)) {
throw new IllegalArgumentException("input not an ImageInputStream!");
}
this.stream = (ImageInputStream) input;
// Check for external masks/overviews
if (input instanceof FileImageInputStreamExtImpl) {
FileImageInputStreamExtImpl stream = (FileImageInputStreamExtImpl) input;
// Getting File path
File inputFile = stream.getFile();
if (inputFile != null) {
// Getting Parent
File parent = inputFile.getParentFile();
// Getting Mask file name
File mask = new File(parent, inputFile.getName() + MASK_SUFFIX);
// Check if exists and can be read
if (mask.exists() && mask.canRead()) {
externalMask = mask;
// Getting external Mask Overviews
File mskOverviews = new File(mask.getAbsolutePath() + OVR_SUFFIX);
// Check if the file exists and can be read
if (mskOverviews.exists() && mskOverviews.canRead()) {
maskOverviews = mskOverviews;
}
}
// Getting Overviews file name
File ovr = new File(parent, inputFile.getName() + OVR_SUFFIX);
// Check if exists and can be read
if (ovr.exists() && ovr.canRead()) {
externalOverviews = ovr;
}
}
}
} else {
this.stream = null;
}
// Creating the New DatasetLayout for handling Overviews and Masking
layout = new TiffDatasetLayoutImpl();
}
use of it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl in project imageio-ext by geosolutions-it.
the class NITFImageWriter method write.
@Override
public void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param) throws IOException {
// Headers and segments initialization
NITFImageWriteParam nitfParam = null;
HeaderWrapper header = null;
Map<String, Map<String, String>> extensionsMap = null;
ShapeFileWrapper shape = null;
List<TextWrapper> texts = null;
WriteCompression compression = null;
List<ImageWrapper> inputImages = null;
if (param != null && param instanceof NITFImageWriteParam) {
nitfParam = (NITFImageWriteParam) param;
NITFProperties nitfMetadata = nitfParam.getNitfProperties();
if (nitfMetadata != null) {
header = nitfMetadata.getHeader();
shape = nitfMetadata.getShape();
texts = nitfMetadata.getTextsWrapper();
inputImages = nitfMetadata.getImagesWrapper();
}
compression = nitfParam.getWriteCompression();
}
ImageWrapper imageW = inputImages.get(0);
RenderedImage ri = imageW.getImage();
final boolean isJP2 = (compression != null && compression != WriteCompression.UNCOMPRESSED);
FileImageInputStreamExt jp2Stream = null;
File tempFile = null;
try {
Record record = new Record(Version.NITF_21);
if (isJP2) {
// Proceeding with jp2 compression
if (JP2_TEMP_FOLDER != null) {
tempFile = File.createTempFile("jp2compressed", ".jpc", new File(JP2_TEMP_FOLDER));
}
String parentPath = outputFile.getParent();
String name = FilenameUtils.getBaseName(outputFile.getCanonicalPath());
tempFile = new File(parentPath + File.separatorChar + name + ".j2c");
prepareJP2Image(ri, tempFile, compression);
jp2Stream = new FileImageInputStreamExtImpl(tempFile);
}
// populating the file header
initFileHeader(record, header);
// adding an image segment to the record
addImageSegment(record, inputImages, jp2Stream, compression);
if (texts != null && !texts.isEmpty()) {
// adding a text segment if present
addTextSegment(record, texts);
}
if (!writeNITF(record, inputImages, shape, jp2Stream, texts)) {
throw new IOException("Unable to successfully write");
}
} catch (Throwable t) {
IOException ioe = new IOException();
ioe.initCause(t);
throw ioe;
} finally {
// Releasing resources
if (jp2Stream != null) {
try {
jp2Stream.close();
} catch (Throwable thr) {
// Eat exception
}
}
if (tempFile != null) {
try {
tempFile.delete();
} catch (Throwable thr) {
}
}
}
// record.destruct();
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Successfully wrote NITF: " + outputFile);
}
}
use of it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl in project imageio-ext by geosolutions-it.
the class GeoTiffVrtTest method read.
/**
* Test Read exploiting JAI-ImageIO tools capabilities
*
* @throws FileNotFoundException
* @throws IOException
*/
@Test
public void read() throws FileNotFoundException, IOException {
if (!isGDALAvailable) {
return;
}
final ParameterBlockJAI pbjImageRead;
String fileName = "utmByte.tif.vrt";
final File file = TestData.file(this, fileName);
pbjImageRead = new ParameterBlockJAI("ImageRead");
pbjImageRead.setParameter("Input", new FileImageInputStreamExtImpl(file));
pbjImageRead.setParameter("Reader", new VRTImageReaderSpi().createReaderInstance());
RenderedOp image = JAI.create("ImageRead", pbjImageRead);
if (TestData.isInteractiveTest())
Viewer.visualizeAllInformation(image, "", true);
else
Assert.assertNotNull(image.getTiles());
}
Aggregations