Search in sources :

Example 6 with FileImageInputStreamExtImpl

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");
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) FileImageInputStreamExtImpl(it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl) URI(java.net.URI) 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 7 with FileImageInputStreamExtImpl

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");
    }
}
Also used : FileImageInputStreamExtImpl(it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl) URI(java.net.URI) 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 8 with FileImageInputStreamExtImpl

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();
}
Also used : ImageInputStream(javax.imageio.stream.ImageInputStream) FileImageInputStreamExtImpl(it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl) File(java.io.File)

Example 9 with FileImageInputStreamExtImpl

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);
    }
}
Also used : NITFProperties(it.geosolutions.imageio.plugins.nitronitf.wrapper.NITFProperties) ShapeFileWrapper(it.geosolutions.imageio.plugins.nitronitf.wrapper.ShapeFileWrapper) IOException(java.io.IOException) TextWrapper(it.geosolutions.imageio.plugins.nitronitf.wrapper.TextWrapper) ImageWrapper(it.geosolutions.imageio.plugins.nitronitf.wrapper.ImageWrapper) FileImageInputStreamExt(it.geosolutions.imageio.stream.input.FileImageInputStreamExt) HeaderWrapper(it.geosolutions.imageio.plugins.nitronitf.wrapper.HeaderWrapper) Record(nitf.Record) FileImageInputStreamExtImpl(it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl) RenderedImage(java.awt.image.RenderedImage) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) File(java.io.File) WriteCompression(it.geosolutions.imageio.plugins.nitronitf.NITFUtilities.WriteCompression)

Example 10 with FileImageInputStreamExtImpl

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());
}
Also used : RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) FileImageInputStreamExtImpl(it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl) 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