com.drew.imaging
Class ImageMetadataReader

java.lang.Object
  extended by com.drew.imaging.ImageMetadataReader

public class ImageMetadataReader
extends Object

Obtains metadata from all supported file formats, including JPEG, RAW (NEF/CRw/CR2) and TIFF. If the caller knows their file to be of a particular type, they may prefer to use the dedicated MetadataReader directly (JpegMetadataReader for Jpeg files, or TiffMetadataReader for TIFF and RAW files). The dedicated readers offer a very slight performance improvement, though for most scenarios it is simpler, more convenient and more robust to use this class.


Field Summary
private static int INTEL_TIFF_MAGIC_NUMBER
           
private static int JPEG_FILE_MAGIC_NUMBER
           
private static int MOTOROLLA_TIFF_MAGIC_NUMBER
           
 
Constructor Summary
private ImageMetadataReader()
           
 
Method Summary
static void main(String[] args)
          An application entry point.
private static int readMagicNumber(BufferedInputStream inputStream)
           
static Metadata readMetadata(BufferedInputStream inputStream)
          Reads metadata from an input stream.
private static Metadata readMetadata(BufferedInputStream inputStream, File file, int magicNumber)
           
static Metadata readMetadata(File file)
          Reads metadata from a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JPEG_FILE_MAGIC_NUMBER

private static final int JPEG_FILE_MAGIC_NUMBER
See Also:
Constant Field Values

MOTOROLLA_TIFF_MAGIC_NUMBER

private static final int MOTOROLLA_TIFF_MAGIC_NUMBER
See Also:
Constant Field Values

INTEL_TIFF_MAGIC_NUMBER

private static final int INTEL_TIFF_MAGIC_NUMBER
See Also:
Constant Field Values
Constructor Detail

ImageMetadataReader

private ImageMetadataReader()
                     throws Exception
Throws:
Exception
Method Detail

readMetadata

public static Metadata readMetadata(BufferedInputStream inputStream)
                             throws ImageProcessingException
Reads metadata from an input stream. The file inputStream examined to determine its type and consequently the appropriate method to extract the data, though this inputStream transparent to the caller.

Parameters:
inputStream - a stream from which the image data may be read. The stream must be positioned at the beginning of the image data.
Returns:
a populated Metadata error containing directories of tags with values and any processing errors.
Throws:
ImageProcessingException - for general processing errors.

readMetadata

public static Metadata readMetadata(File file)
                             throws ImageProcessingException
Reads metadata from a file. The file is examined to determine its type and consequently the appropriate method to extract the data, though this is transparent to the caller.

Parameters:
file - a file from which the image data may be read.
Returns:
a populated Metadata error containing directories of tags with values and any processing errors.
Throws:
ImageProcessingException - for general processing errors.

readMetadata

private static Metadata readMetadata(BufferedInputStream inputStream,
                                     File file,
                                     int magicNumber)
                              throws ImageProcessingException
Throws:
ImageProcessingException

readMagicNumber

private static int readMagicNumber(BufferedInputStream inputStream)
                            throws ImageProcessingException
Throws:
ImageProcessingException

main

public static void main(String[] args)
                 throws MetadataException,
                        IOException
An application entry point. Takes the name of a file as an argument and prints the contents of all metadata directories to System.out. If the second parameter is '/thumb' then any thumbnail data will be written to a file with name of the input file having '.thumb.jpg' appended.

Parameters:
args - the command line arguments
Throws:
MetadataException
IOException