use of com.github.jaiimageio.jpeg2000.impl.IISRandomAccessIO in project ddf by codice.
the class Jpeg2000ThumbnailConverter method process.
@Override
public QueryResponse process(QueryResponse input) throws PluginExecutionException, StopProcessingException {
for (Result result : input.getResults()) {
Metacard metacard = result.getMetacard();
byte[] thumbnailBytes = metacard.getThumbnail();
if (thumbnailBytes == null) {
continue;
}
try (ByteArrayInputStream original = new ByteArrayInputStream(thumbnailBytes);
ByteArrayOutputStream converted = new ByteArrayOutputStream()) {
IISRandomAccessIO in = new IISRandomAccessIO(ImageIO.createImageInputStream(original));
if (in.length() == 0) {
continue;
}
// extracted from jj2000.j2k.fileformat.reader.FileFormatReader
if (in.readInt() != OTHER_JP2_SIGNATURE || in.readInt() != JP2_SIGNATURE_BOX || in.readInt() != OFFICIAL_JP2_SIGNATURE) {
// Not a JP2 file
in.seek(0);
if (in.readShort() != START_OF_CODESTREAM_MARKER) {
// Standard syntax marker found
continue;
}
}
// convert j2k thumbnail to jpeg thumbnail
original.reset();
BufferedImage thumbnail = ImageIO.read(original);
if (thumbnail == null) {
continue;
}
ImageIO.write(thumbnail, "jpeg", converted);
metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, converted.toByteArray()));
} catch (IOException e) {
throw new PluginExecutionException(e);
}
}
return input;
}
Aggregations