Dominik Schmidt created TIKA-4873:
-------------------------------------

             Summary:  Set Content-Length on embedded documents where the 
parser already knows it
                 Key: TIKA-4873
                 URL: https://issues.apache.org/jira/browse/TIKA-4873
             Project: Tika
          Issue Type: Improvement
            Reporter: Dominik Schmidt


Several parsers emit embedded documents without a size. A client gets the type,
the name and the resource path, but has to read the bytes to learn how many
there are. Examples: the raw camera previews from RawTiffParser, the audio cover
art from CoverArt, and the motion photo video from TIKA-4869 until it was added
there.

The convention is established elsewhere: ZipParser sets Content-Length from the
zip entry (along with Zip:UncompressedSize), AbstractPOIFSExtractor from the
OLE2 directory entry, AbstractPDF2XHTML from the embedded file specification,
and RTF, PST and WARC do the same. In each of these the parser has the size in
hand before it hands the stream over, and in the cases listed above it does too:
the JPEG preview length comes from the IFD, the cover art length from the ID3 or
MP4 frame.

Content-Length is not only an output. TikaInputStream.get(opener, tmp, metadata)
takes the stream's length from it, so setting it before the embedded parse means
that parse knows the length without spooling to measure it: MP4Parser, for one,
bounds its box allocation with tis.hasLength() ? tis.getLength() : -1.

TIKA-4106 approaches the same gap from the other end, by having the digester
fill the length in. That covers callers who want digests, and only once the
stream has been read; it does not help a caller who only wants to know how big
an attachment is.

Two steps, either of them useful on its own:

1. Set it in the parsers that already know the size, starting with RawTiffParser
   and CoverArt.
2. In ParsingEmbeddedDocumentExtractor.parseEmbedded, fill Content-Length when
   it is blank and tis.hasLength() is true. That costs nothing, never spools,
   and covers every embedded stream that is file or byte array backed, whatever
   parser produced it.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to