public BufferedImage getImage(final Rendition rendition, final Dimension dim) throws IOException { final Asset asset = rendition.getAsset(); final byte[] picture = (byte[]) extractMetadata(asset).getProperty(META_KEY_THUMBNAIL); // if we have an embedded image if (picture != null) { return new Layer(new ByteArrayInputStream(picture), dim).getImage(); } // according to the spec, a thumbnail representation of a document should be generated by // default when the // file is saved. log.warn("Failed to retrieve thumbnail for {}", asset.getPath()); return null; }
public ExtractedMetadata extractMetadata(final Asset asset) { final ZipInputStream zis = new ZipInputStream(new BufferedInputStream(asset.getOriginal().getStream())); final ExtractedMetadata metadata = new ExtractedMetadata(); try { readEntries(zis, metadata, asset); } catch (Exception e) { log.warn("Failed to extract metadata for {} reason: {}", asset.getPath(), e.getMessage()); log.debug("Stack Trace: ", e); } finally { IOUtils.closeQuietly(zis); } setMimetype(metadata, asset); return metadata; }
public ExtractedMetadata extractMetadata(final Asset asset) { ExtractedMetadata metadata = new ExtractedMetadata(); log.debug("extractMetadata: start extracting asset [{}]", asset.getPath()); // extract metadata final InputStream is = asset.getOriginal().getStream(); final ZipInputStream zis = new ZipInputStream(is); final StringBuffer buffer = new StringBuffer(); int count = 0; try { ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { if (!entry.isDirectory()) { buffer.append(entry.getName()).append('\n'); count++; } zis.closeEntry(); } metadata.setMetaDataProperty("Content", buffer.toString()); metadata.setMetaDataProperty("File Count", count); } catch (IOException e) { log.warn("extractMetadata: error while reading ZIP archive [{}]: ", asset.getPath(), e); } catch (IllegalArgumentException iae) { // bug#28534 log.warn("extractMetadata: error while reading ZIP entry [{}]: ", asset.getPath(), iae); } finally { IOUtils.closeQuietly(zis); } // Get XMP execGenericProcessor(asset.getOriginal().getStream(), metadata); setMimetype(metadata, asset); return metadata; }