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