use of org.codice.imaging.nitf.render.NitfRenderer 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();
}
use of org.codice.imaging.nitf.render.NitfRenderer in project alliance by codice.
the class PreStoragePluginTest method testRunTimeException.
@Test
public void testRunTimeException() throws IOException, PluginExecutionException {
NitfRenderer nitfRenderer = mock(NitfRenderer.class);
NitfPreStoragePlugin nitfPreStoragePlugin = new NitfPreStoragePlugin() {
@Override
NitfRenderer getNitfRenderer() {
return nitfRenderer;
}
};
when(nitfRenderer.render(any(ImageSegment.class))).thenThrow(RuntimeException.class);
CreateStorageRequest result = nitfPreStoragePlugin.process(createStorageRequest);
assertThat(result.getContentItems(), is(createStorageRequest.getContentItems()));
}
Aggregations