Class ImageProbe

java.lang.Object
org.apache.tika.parser.enricher.ImageProbe

public final class ImageProbe extends Object
What the checks of one image share: its bytes, read once and left in the stream for the engine, the dimensions its parser recorded, and anything a check chooses to memoize, so two checks that need the decoded pixels decode them once.
Since:
Apache Tika 4.2
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    A computation that may fail to read.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    How much of the start of an image header() reads: enough for a header.
    static final int
    Images longer than this are not read for a check; the checks then admit them.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    The image's bytes, read on first use and left in the stream, or null when it is longer than MAX_BYTES or cannot be read.
    byte[]
    The first HEADER_BYTES of the image (all of it when it is shorter), read on first use and left in the stream: enough for a check that needs only dimensions, so a large image is not read whole for it.
    boolean
    Whether header() is the whole image.
    long
    The image's length in bytes without reading it, or -1 when the stream does not know it or knows only a declared length (a container's or a header's), which may lie.
    <T> T
    memo(String key, ImageProbe.Computation<T> computation)
    A value one check computes and the next reuses; computed once per key.
    The height the image's parser recorded (tiff:ImageLength), or null.
    The width the image's parser recorded (tiff:ImageWidth), or null.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_BYTES

      public static final int MAX_BYTES
      Images longer than this are not read for a check; the checks then admit them.
      See Also:
    • HEADER_BYTES

      public static final int HEADER_BYTES
      How much of the start of an image header() reads: enough for a header.
      See Also:
  • Constructor Details

  • Method Details

    • recordedWidth

      public Integer recordedWidth()
      The width the image's parser recorded (tiff:ImageWidth), or null.
    • recordedHeight

      public Integer recordedHeight()
      The height the image's parser recorded (tiff:ImageLength), or null.
    • length

      public long length() throws IOException
      The image's length in bytes without reading it, or -1 when the stream does not know it or knows only a declared length (a container's or a header's), which may lie.
      Throws:
      IOException
    • header

      public byte[] header() throws IOException
      The first HEADER_BYTES of the image (all of it when it is shorter), read on first use and left in the stream: enough for a check that needs only dimensions, so a large image is not read whole for it. Treat the array as read-only.
      Throws:
      IOException
    • headerIsComplete

      public boolean headerIsComplete() throws IOException
      Whether header() is the whole image.
      Throws:
      IOException
    • bytes

      public byte[] bytes() throws IOException
      The image's bytes, read on first use and left in the stream, or null when it is longer than MAX_BYTES or cannot be read. Treat the array as read-only.
      Throws:
      IOException
    • memo

      public <T> T memo(String key, ImageProbe.Computation<T> computation) throws IOException
      A value one check computes and the next reuses; computed once per key.
      Throws:
      IOException