Class ImageMetadataReader


  • public class ImageMetadataReader
    extends java.lang.Object
    Reads metadata from any supported file format.

    This class a lightweight wrapper around other, specific metadata processors. During extraction, the file type is determined from the first few bytes of the file. Parsing is then delegated to one of:

    • AviMetadataReader for AVI files
    • BmpMetadataReader for BMP files
    • FileSystemMetadataReader for metadata from the file system when a File is provided
    • GifMetadataReader for GIF files
    • IcoMetadataReader for ICO files
    • JpegMetadataReader for JPEG files
    • Mp4MetadataReader for MPEG-4 files
    • PcxMetadataReader for PCX files
    • PngMetadataReader for PNG files
    • PsdMetadataReader for Photoshop files
    • QuickTimeMetadataReader for QuickTime files
    • RafMetadataReader for RAF files
    • TiffMetadataReader for TIFF and (most) RAW files
    • WavMetadataReader for WAV files
    • WebpMetadataReader for WebP files
    If you know the file type you're working with, you may use one of the above processors directly. For most scenarios it is simpler, more convenient and more robust to use this class.

    FileTypeDetector is used to determine the provided image's file type, and therefore the appropriate metadata reader to use.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void main​(java.lang.String[] args)
      An application entry point.
      static Metadata readMetadata​(java.io.File file)
      Reads Metadata from a File object.
      static Metadata readMetadata​(java.io.InputStream inputStream)
      Reads metadata from an InputStream.
      static Metadata readMetadata​(java.io.InputStream inputStream, long streamLength)
      Reads metadata from an InputStream of known length.
      static Metadata readMetadata​(java.io.InputStream inputStream, long streamLength, FileType fileType)
      Reads metadata from an InputStream of known length and file type.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • readMetadata

        public static Metadata readMetadata​(java.io.InputStream inputStream)
                                     throws ImageProcessingException,
                                            java.io.IOException
        Reads metadata from an InputStream.
        Parameters:
        inputStream - a stream from which the file data may be read. The stream must be positioned at the beginning of the file's data.
        Returns:
        a populated Metadata object containing directories of tags with values and any processing errors.
        Throws:
        ImageProcessingException - if the file type is unknown, or for general processing errors.
        java.io.IOException
      • readMetadata

        public static Metadata readMetadata​(java.io.InputStream inputStream,
                                            long streamLength)
                                     throws ImageProcessingException,
                                            java.io.IOException
        Reads metadata from an InputStream of known length.
        Parameters:
        inputStream - a stream from which the file data may be read. The stream must be positioned at the beginning of the file's data.
        streamLength - the length of the stream, if known, otherwise -1.
        Returns:
        a populated Metadata object containing directories of tags with values and any processing errors.
        Throws:
        ImageProcessingException - if the file type is unknown, or for general processing errors.
        java.io.IOException
      • readMetadata

        public static Metadata readMetadata​(java.io.InputStream inputStream,
                                            long streamLength,
                                            FileType fileType)
                                     throws java.io.IOException,
                                            ImageProcessingException
        Reads metadata from an InputStream of known length and file type.
        Parameters:
        inputStream - a stream from which the file data may be read. The stream must be positioned at the beginning of the file's data.
        streamLength - the length of the stream, if known, otherwise -1.
        fileType - the file type of the data stream.
        Returns:
        a populated Metadata object containing directories of tags with values and any processing errors.
        Throws:
        ImageProcessingException - if the file type is unknown, or for general processing errors.
        java.io.IOException
      • readMetadata

        public static Metadata readMetadata​(java.io.File file)
                                     throws ImageProcessingException,
                                            java.io.IOException
        Reads Metadata from a File object.
        Parameters:
        file - a file from which the image data may be read.
        Returns:
        a populated Metadata object containing directories of tags with values and any processing errors.
        Throws:
        ImageProcessingException - for general processing errors.
        java.io.IOException
      • main

        public static void main​(java.lang.String[] args)
                         throws MetadataException,
                                java.io.IOException
        An application entry point. Takes the name of one or more files as arguments and prints the contents of all metadata directories to System.out.

        If -thumb is passed, then any thumbnail data will be written to a file with name of the input file having .thumb.jpg appended.

        If -markdown is passed, then output will be in markdown format.

        If -hex is passed, then the ID of each tag will be displayed in hexadecimal.

        Parameters:
        args - the command line arguments
        Throws:
        MetadataException
        java.io.IOException