Search in sources :

Example 6 with NitfFormatException

use of org.codice.imaging.nitf.core.common.NitfFormatException in project alliance by codice.

the class NitfPreStoragePlugin method render.

private BufferedImage render(ContentItem contentItem, Function<Pair<ImageSegment, NitfRenderer>, BufferedImage> imageSegmentFunction) throws IOException, ParseException, NitfFormatException {
    final ThreadLocal<BufferedImage> bufferedImage = new ThreadLocal<>();
    if (contentItem != null) {
        InputStream inputStream = contentItem.getInputStream();
        if (inputStream != null) {
            try {
                NitfRenderer renderer = getNitfRenderer();
                new NitfParserInputFlowImpl().inputStream(inputStream).allData().forEachImageSegment(segment -> {
                    if (bufferedImage.get() == null) {
                        BufferedImage bi = imageSegmentFunction.apply(new ImmutablePair<>(segment, renderer));
                        if (bi != null) {
                            bufferedImage.set(bi);
                        }
                    }
                }).end();
            } finally {
                IOUtils.closeQuietly(inputStream);
            }
        }
    }
    return bufferedImage.get();
}
Also used : J2KImageWriter(com.github.jaiimageio.jpeg2000.impl.J2KImageWriter) IIOImage(javax.imageio.IIOImage) ImageSegment(org.codice.imaging.nitf.core.image.ImageSegment) StringUtils(org.apache.commons.lang.StringUtils) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) J2KImageReaderSpi(com.github.jaiimageio.jpeg2000.impl.J2KImageReaderSpi) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) NitfParserInputFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl) LoggerFactory(org.slf4j.LoggerFactory) PreCreateStoragePlugin(ddf.catalog.content.plugin.PreCreateStoragePlugin) Thumbnails(net.coobird.thumbnailator.Thumbnails) Function(java.util.function.Function) J2KImageWriterSpi(com.github.jaiimageio.jpeg2000.impl.J2KImageWriterSpi) ArrayList(java.util.ArrayList) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ImageWriteParam(javax.imageio.ImageWriteParam) ContentItem(ddf.catalog.content.data.ContentItem) PreUpdateStoragePlugin(ddf.catalog.content.plugin.PreUpdateStoragePlugin) Pair(org.apache.commons.lang3.tuple.Pair) Metacard(ddf.catalog.data.Metacard) Graphics2D(java.awt.Graphics2D) MimeType(javax.activation.MimeType) ImageIO(javax.imageio.ImageIO) ByteSource(com.google.common.io.ByteSource) ParseException(java.text.ParseException) Core(ddf.catalog.data.types.Core) NitfFormatException(org.codice.imaging.nitf.core.common.NitfFormatException) Logger(org.slf4j.Logger) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) IIORegistry(javax.imageio.spi.IIORegistry) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ImageOutputStream(javax.imageio.stream.ImageOutputStream) MimeTypeParseException(javax.activation.MimeTypeParseException) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Attribute(ddf.catalog.data.Attribute) MemoryCacheImageOutputStream(javax.imageio.stream.MemoryCacheImageOutputStream) NitfRenderer(org.codice.imaging.nitf.render.NitfRenderer) J2KImageWriteParam(com.github.jaiimageio.jpeg2000.J2KImageWriteParam) FilenameUtils(org.apache.commons.io.FilenameUtils) InputStream(java.io.InputStream) NitfRenderer(org.codice.imaging.nitf.render.NitfRenderer) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) InputStream(java.io.InputStream) NitfParserInputFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl) BufferedImage(java.awt.image.BufferedImage)

Aggregations

NitfFormatException (org.codice.imaging.nitf.core.common.NitfFormatException)6 BufferedImage (java.awt.image.BufferedImage)4 IOException (java.io.IOException)4 Test (org.junit.Test)4 ByteSource (com.google.common.io.ByteSource)3 ImageSegment (org.codice.imaging.nitf.core.image.ImageSegment)3 NitfParserInputFlowImpl (org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl)3 ContentItem (ddf.catalog.content.data.ContentItem)2 BinaryContent (ddf.catalog.data.BinaryContent)2 Metacard (ddf.catalog.data.Metacard)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ParseException (java.text.ParseException)2 MimeTypeParseException (javax.activation.MimeTypeParseException)2 J2KImageWriteParam (com.github.jaiimageio.jpeg2000.J2KImageWriteParam)1 J2KImageReaderSpi (com.github.jaiimageio.jpeg2000.impl.J2KImageReaderSpi)1 J2KImageWriter (com.github.jaiimageio.jpeg2000.impl.J2KImageWriter)1 J2KImageWriterSpi (com.github.jaiimageio.jpeg2000.impl.J2KImageWriterSpi)1 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)1 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)1