[
https://issues.apache.org/jira/browse/TIKA-4854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18109453#comment-18109453
]
ASF GitHub Bot commented on TIKA-4854:
--------------------------------------
dschmidt commented on code in PR #3094:
URL: https://github.com/apache/tika/pull/3094#discussion_r3886948448
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/main/java/org/apache/tika/parser/iwork/IWorkPackageParser.java:
##########
@@ -87,12 +91,34 @@ public Set<MediaType> getSupportedTypes(ParseContext
context) {
return supportedTypes;
}
+ /**
+ * The document preview of an iWork '09 package.
+ */
+ public final static String IWORK_THUMBNAIL_ENTRY =
"QuickLook/Thumbnail.jpg";
+
+ /**
+ * Bound on the preview held in memory until the content has been
+ * parsed; a real one is well under a megabyte.
+ */
+ private static final long MAX_THUMBNAIL_BYTES = 20 * 1024 * 1024;
+
public void parse(TikaInputStream tis, ContentHandler handler, Metadata
metadata,
ParseContext context) throws IOException, SAXException,
TikaException {
ZipArchiveInputStream zip = new ZipArchiveInputStream(tis);
ZipArchiveEntry entry = zip.getNextEntry();
+ //the package is read as a stream, so the preview may come before the
+ //content: hold it back and emit it once the content is written
+ byte[] thumbnail = null;
+ XHTMLContentHandler xhtml = null;
while (entry != null) {
+ if (IWORK_THUMBNAIL_ENTRY.equals(entry.getName()) &&
zip.canReadEntryData(entry)) {
+ thumbnail = IOUtils.toByteArray(
+ BoundedInputStream.builder().setInputStream(zip)
+ .setMaxCount(MAX_THUMBNAIL_BYTES).get());
+ entry = zip.getNextEntry();
+ continue;
+ }
Review Comment:
Fixed: the thumbnail's metadata is built first and the entry is only
buffered when shouldParseEmbedded says yes.
> Emit the preview image of iWork '09 and iWork '18 packages as a THUMBNAIL
> embedded resource
> -------------------------------------------------------------------------------------------
>
> Key: TIKA-4854
> URL: https://issues.apache.org/jira/browse/TIKA-4854
> Project: Tika
> Issue Type: Improvement
> Reporter: Dominik Schmidt
> Priority: Major
>
> IWork13PackageParser emits preview.jpg as a THUMBNAIL embedded document. The
> two other iWork package parsers do not emit any embedded documents:
> IWorkPackageParser (iWork '09, QuickLook/Thumbnail.jpg) only parses the index
> XML, and IWork18PackageParser only detects the media type although the
> package carries preview.jpg as well. Both previews should be emitted as
> THUMBNAIL like the '13 one, so a client gets the representative image of
> every iWork file the same way.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)