use of org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl in project alliance by codice.
the class ImageInputTransformerTest method testPiatgb.
@Test
public void testPiatgb() throws IOException, NitfFormatException {
File nitfFile = File.createTempFile("nitf-", ".ntf");
try {
createNitfWithPiatgb(nitfFile);
try (InputStream inputStream = new FileInputStream(nitfFile)) {
Metacard metacard = metacardFactory.createMetacard("piatgbTest");
NitfSegmentsFlow nitfSegmentsFlow = new NitfParserInputFlowImpl().inputStream(inputStream).headerOnly();
transformer.transform(nitfSegmentsFlow, metacard);
assertThat(metacard.getAttribute(PiatgbAttribute.TARGET_NAME_ATTRIBUTE.getLongName()).getValue(), is("Canberra Hill"));
}
} finally {
nitfFile.delete();
}
}
use of org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl 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.fluent.impl.NitfParserInputFlowImpl in project alliance by codice.
the class ImagingTest method testImageNitfChipCreationNitf.
@Test
public void testImageNitfChipCreationNitf() throws Exception {
String id = ingestNitfFile(TEST_IMAGE_NITF);
String chippingUrl = SECURE_ROOT + HTTPS_PORT.getPort() + "/chipping/chipping.html?id=" + id + "&source=Alliance";
given().get(chippingUrl).then().assertThat().statusCode(HttpStatus.SC_OK);
final int width = 350;
final int height = 240;
String chippedImageUrl = SERVICE_ROOT + "/catalog/" + id + "?transform=nitf-chip&qualifier=overview&x=" + 300 + "&y=" + 200 + "&w=" + width + "&h=" + height;
InputStream chippedImageStream = given().get(chippedImageUrl).asInputStream();
List<ImageSegment> imageSegments = new LinkedList<>();
try (TemporaryFileBackedOutputStream tfbos = new TemporaryFileBackedOutputStream()) {
IOUtils.copyLarge(chippedImageStream, tfbos);
NitfSegmentsFlow nitfSegmentsFlow = new NitfParserInputFlowImpl().inputStream(tfbos.asByteSource().openBufferedStream()).allData();
nitfSegmentsFlow.forEachImageSegment(imageSegments::add);
}
assertThat(imageSegments, hasSize(1));
assertThat(imageSegments.get(0).getNumberOfColumns(), is((long) width));
assertThat(imageSegments.get(0).getNumberOfRows(), is((long) height));
}
Aggregations