Class ReadMetadataUtilities

Object
ReadMetadataUtilities

public class ReadMetadataUtilities extends Object
Reads various image properties from tags in Metadata.
Author:
Owen Feehan
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T extends com.drew.metadata.Directory>
    Optional<com.drew.metadata.Directory>
    findDirectoryWithName(com.drew.metadata.Metadata metadata, Class<T> directoryType, String directoryName)
    Finds the first Directory in the metadata with type directoryType and whose name is equal to directoryName.
    static Optional<Date>
    readDate(com.drew.metadata.Directory directory, int tag)
    Reads a metadata entry of type Date from a Directory.
    static <T extends com.drew.metadata.Directory>
    Optional<ZonedDateTime>
    readDate(com.drew.metadata.Metadata metadata, Class<T> directoryType, int[] tagsAcqusitionDate, int[] tagsTimezoneOffset)
    Reads a metadata entry of type Date from the first directory of type directoryType.
    readFromWidthHeightTags(com.drew.metadata.Directory directory, int tagWidth, int tagHeight)
    Reads two metadata entries, representing width and height, and use them to form a Extent.
    static <T extends com.drew.metadata.Directory>
    Optional<Extent>
    readFromWidthHeightTags(com.drew.metadata.Metadata metadata, Class<T> directoryType, int tagWidth, int tagHeight)
    Reads two metadata entries, representing width and height, and use them to form a Extent.
    readInt(com.drew.metadata.Directory directory, int tag)
    Reads a metadata entry of type int from a Directory.
    static <T extends com.drew.metadata.Directory>
    Optional<Integer>
    readInt(com.drew.metadata.Metadata metadata, Class<T> directoryType, int tag)
    Reads a metadata entry of type int from the first directory of type directoryType.
    static Optional<com.drew.metadata.Metadata>
    Reads metadata, if it exists, from an image.

    Methods inherited from class java.lang.Object

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

    • readMetadata

      public static Optional<com.drew.metadata.Metadata> readMetadata(Path path) throws ImageIOException
      Reads metadata, if it exists, from an image.
      Parameters:
      path - the path to the image.
      Returns:
      the metadata, if it exists.
      Throws:
      ImageIOException - if something goes wrong processing the metadata.
    • findDirectoryWithName

      public static <T extends com.drew.metadata.Directory> Optional<com.drew.metadata.Directory> findDirectoryWithName(com.drew.metadata.Metadata metadata, Class<T> directoryType, String directoryName)
      Finds the first Directory in the metadata with type directoryType and whose name is equal to directoryName.
      Type Parameters:
      T - directory-type to find
      Parameters:
      metadata - the metadata to read from.
      directoryType - class corresponding to T.
      directoryName - the name of the directory, which must match, case insensitive.
      Returns:
      the first directory that matches, if it exists.
    • readInt

      public static <T extends com.drew.metadata.Directory> Optional<Integer> readInt(com.drew.metadata.Metadata metadata, Class<T> directoryType, int tag)
      Reads a metadata entry of type int from the first directory of type directoryType.
      Type Parameters:
      T - directory-type to find
      Parameters:
      metadata - the metadata to read from.
      directoryType - class corresponding to T.
      tag - a unique identifier from the metadata-extractor library identifying which tag to read.
      Returns:
      the value of the tag, or Optional.empty() if it does not exist.
    • readDate

      public static <T extends com.drew.metadata.Directory> Optional<ZonedDateTime> readDate(com.drew.metadata.Metadata metadata, Class<T> directoryType, int[] tagsAcqusitionDate, int[] tagsTimezoneOffset)
      Reads a metadata entry of type Date from the first directory of type directoryType.

      If no timezone offset is specified in the metadata, the current time-zone is used.

      Type Parameters:
      T - directory-type to find
      Parameters:
      metadata - the metadata to read from.
      directoryType - class corresponding to T.
      tagsAcqusitionDate - unique identifiers from the metadata-extractor library identifying which tag(s) to read (in order). Once a single tag is found, no further tags are tried.
      tagsTimezoneOffset - similar to tagsAcqusitionDate but instead identifies a time-zone offset.
      Returns:
      the value of the tag, or Optional.empty() if it does not exist.
    • readInt

      public static Optional<Integer> readInt(com.drew.metadata.Directory directory, int tag)
      Reads a metadata entry of type int from a Directory.
      Parameters:
      directory - the directory to read from.
      tag - a unique identifier from the metadata-extractor library identifying which tag to read.
      Returns:
      the value of the tag, or Optional.empty() if it does not exist.
    • readDate

      public static Optional<Date> readDate(com.drew.metadata.Directory directory, int tag)
      Reads a metadata entry of type Date from a Directory.
      Parameters:
      directory - the directory to read from.
      tag - a unique identifier from the metadata-extractor library identifying which tag to read.
      Returns:
      the value of the tag, or Optional.empty() if it does not exist.
    • readFromWidthHeightTags

      public static <T extends com.drew.metadata.Directory> Optional<Extent> readFromWidthHeightTags(com.drew.metadata.Metadata metadata, Class<T> directoryType, int tagWidth, int tagHeight) throws ImageIOException
      Reads two metadata entries, representing width and height, and use them to form a Extent.

      The first directory of type directoryType is used for the tags.

      Type Parameters:
      T - directory-type to find
      Parameters:
      metadata - the metadata to read from.
      directoryType - class corresponding to T.
      tagWidth - a unique identifier from the metadata-extractor library identifying the width tag.
      tagHeight - a unique identifier from the metadata-extractor library identifying the height tag.
      Returns:
      the value of the tag, or Optional.empty() if it does not exist.
      Throws:
      ImageIOException - if the metadata is errored (but not if it is absent).
    • readFromWidthHeightTags

      public static Optional<Extent> readFromWidthHeightTags(com.drew.metadata.Directory directory, int tagWidth, int tagHeight) throws ImageIOException
      Reads two metadata entries, representing width and height, and use them to form a Extent.
      Parameters:
      directory - the directory to read tags from.
      tagWidth - a unique identifier from the metadata-extractor library identifying the width tag.
      tagHeight - a unique identifier from the metadata-extractor library identifying the height tag.
      Returns:
      the value of the tag, or Optional.empty() if it does not exist.
      Throws:
      ImageIOException - if the metadata is errored (but not if it is absent).