Index: trunk/src/com/drew/imaging/jpeg/JpegMetadataReader.java
===================================================================
--- trunk/src/com/drew/imaging/jpeg/JpegMetadataReader.java	(revision 6127)
+++ trunk/src/com/drew/imaging/jpeg/JpegMetadataReader.java	(revision 8132)
@@ -1,4 +1,4 @@
 /*
- * Copyright 2002-2012 Drew Noakes
+ * Copyright 2002-2015 Drew Noakes
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,46 +16,76 @@
  * More information about this project is available at:
  *
- *    http://drewnoakes.com/code/exif/
- *    http://code.google.com/p/metadata-extractor/
+ *    https://drewnoakes.com/code/exif/
+ *    https://github.com/drewnoakes/metadata-extractor
  */
 package com.drew.imaging.jpeg;
 
-import com.drew.lang.ByteArrayReader;
-import com.drew.lang.annotations.NotNull;
-import com.drew.metadata.Metadata;
-import com.drew.metadata.exif.ExifReader;
-import com.drew.metadata.iptc.IptcReader;
-import com.drew.metadata.jpeg.JpegCommentReader;
-import com.drew.metadata.jpeg.JpegDirectory;
-import com.drew.metadata.jpeg.JpegReader;
-
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import com.drew.lang.StreamReader;
+import com.drew.lang.annotations.NotNull;
+import com.drew.lang.annotations.Nullable;
+import com.drew.metadata.Metadata;
+//import com.drew.metadata.adobe.AdobeJpegReader;
+import com.drew.metadata.exif.ExifReader;
+//import com.drew.metadata.icc.IccReader;
+import com.drew.metadata.iptc.IptcReader;
+//import com.drew.metadata.jfif.JfifReader;
+import com.drew.metadata.jpeg.JpegCommentReader;
+import com.drew.metadata.jpeg.JpegReader;
+//import com.drew.metadata.photoshop.PhotoshopReader;
+//import com.drew.metadata.xmp.XmpReader;
 
 /**
- * Obtains all available metadata from Jpeg formatted files.
+ * Obtains all available metadata from JPEG formatted files.
  *
- * @author Drew Noakes http://drewnoakes.com
+ * @author Drew Noakes https://drewnoakes.com
  */
 public class JpegMetadataReader
 {
-    // TODO investigate supporting javax.imageio
-//    public static Metadata readMetadata(IIOMetadata metadata) throws JpegProcessingException {}
-//    public static Metadata readMetadata(ImageInputStream in) throws JpegProcessingException{}
-//    public static Metadata readMetadata(IIOImage image) throws JpegProcessingException{}
-//    public static Metadata readMetadata(ImageReader reader) throws JpegProcessingException{}
+    public static final Iterable<JpegSegmentMetadataReader> ALL_READERS = Arrays.asList(
+            new JpegReader(),
+            new JpegCommentReader(),
+            //new JfifReader(),
+            new ExifReader(),
+            //new XmpReader(),
+            //new IccReader(),
+            //new PhotoshopReader(),
+            new IptcReader()//,
+            //new AdobeJpegReader()
+    );
 
     @NotNull
-    public static Metadata readMetadata(@NotNull InputStream inputStream) throws JpegProcessingException
+    public static Metadata readMetadata(@NotNull InputStream inputStream, @Nullable Iterable<JpegSegmentMetadataReader> readers) throws JpegProcessingException, IOException
     {
-        return readMetadata(inputStream, true);
+        Metadata metadata = new Metadata();
+        process(metadata, inputStream, readers);
+        return metadata;
     }
 
     @NotNull
-    public static Metadata readMetadata(@NotNull InputStream inputStream, final boolean waitForBytes) throws JpegProcessingException
+    public static Metadata readMetadata(@NotNull InputStream inputStream) throws JpegProcessingException, IOException
     {
-        JpegSegmentReader segmentReader = new JpegSegmentReader(inputStream, waitForBytes);
-        return extractMetadataFromJpegSegmentReader(segmentReader.getSegmentData());
+        return readMetadata(inputStream, null);
+    }
+
+    @NotNull
+    public static Metadata readMetadata(@NotNull File file, @Nullable Iterable<JpegSegmentMetadataReader> readers) throws JpegProcessingException, IOException
+    {
+        InputStream inputStream = null;
+        try
+        {
+            inputStream = new FileInputStream(file);
+            return readMetadata(inputStream, readers);
+        } finally {
+            if (inputStream != null)
+                inputStream.close();
+        }
     }
 
@@ -63,54 +93,41 @@
     public static Metadata readMetadata(@NotNull File file) throws JpegProcessingException, IOException
     {
-        JpegSegmentReader segmentReader = new JpegSegmentReader(file);
-        return extractMetadataFromJpegSegmentReader(segmentReader.getSegmentData());
+        return readMetadata(file, null);
     }
 
-    @NotNull
-    public static Metadata extractMetadataFromJpegSegmentReader(@NotNull JpegSegmentData segmentReader)
+    public static void process(@NotNull Metadata metadata, @NotNull InputStream inputStream) throws JpegProcessingException, IOException
     {
-        final Metadata metadata = new Metadata();
+        process(metadata, inputStream, null);
+    }
 
-        // Loop through looking for all SOFn segments.  When we find one, we know what type of compression
-        // was used for the JPEG, and we can process the JPEG metadata in the segment too.
-        for (byte i = 0; i < 16; i++) {
-            // There are no SOF4 or SOF12 segments, so don't bother
-            if (i == 4 || i == 12)
-                continue;
-            // Should never have more than one SOFn for a given 'n'.
-            byte[] jpegSegment = segmentReader.getSegment((byte)(JpegSegmentReader.SEGMENT_SOF0 + i));
-            if (jpegSegment == null)
-                continue;
-            JpegDirectory directory = metadata.getOrCreateDirectory(JpegDirectory.class);
-            directory.setInt(JpegDirectory.TAG_JPEG_COMPRESSION_TYPE, i);
-            new JpegReader().extract(new ByteArrayReader(jpegSegment), metadata);
-            break;
-        }
+    public static void process(@NotNull Metadata metadata, @NotNull InputStream inputStream, @Nullable Iterable<JpegSegmentMetadataReader> readers) throws JpegProcessingException, IOException
+    {
+        if (readers == null)
+            readers = ALL_READERS;
 
-        // There should never be more than one COM segment.
-        byte[] comSegment = segmentReader.getSegment(JpegSegmentReader.SEGMENT_COM);
-        if (comSegment != null)
-            new JpegCommentReader().extract(new ByteArrayReader(comSegment), metadata);
-
-        // Loop through all APP1 segments, checking the leading bytes to identify the format of each.
-        for (byte[] app1Segment : segmentReader.getSegments(JpegSegmentReader.SEGMENT_APP1)) {
-            if (app1Segment.length > 3 && "EXIF".equalsIgnoreCase(new String(app1Segment, 0, 4)))
-                new ExifReader().extract(new ByteArrayReader(app1Segment), metadata);
-
-            //if (app1Segment.length > 27 && "http://ns.adobe.com/xap/1.0/".equalsIgnoreCase(new String(app1Segment, 0, 28)))
-            //    new XmpReader().extract(new ByteArrayReader(app1Segment), metadata);
-        }
-
-        // Loop through all APPD segments, checking the leading bytes to identify the format of each.
-        for (byte[] appdSegment : segmentReader.getSegments(JpegSegmentReader.SEGMENT_APPD)) {
-            if (appdSegment.length > 12 && "Photoshop 3.0".compareTo(new String(appdSegment, 0, 13))==0) {
-                //new PhotoshopReader().extract(new ByteArrayReader(appdSegment), metadata);
-            } else {
-                // TODO might be able to check for a leading 0x1c02 for IPTC data...
-                new IptcReader().extract(new ByteArrayReader(appdSegment), metadata);
+        Set<JpegSegmentType> segmentTypes = new HashSet<JpegSegmentType>();
+        for (JpegSegmentMetadataReader reader : readers) {
+            for (JpegSegmentType type : reader.getSegmentTypes()) {
+                segmentTypes.add(type);
             }
         }
 
-        return metadata;
+        JpegSegmentData segmentData = JpegSegmentReader.readSegments(new StreamReader(inputStream), segmentTypes);
+
+        processJpegSegmentData(metadata, readers, segmentData);
+    }
+
+    public static void processJpegSegmentData(Metadata metadata, Iterable<JpegSegmentMetadataReader> readers, JpegSegmentData segmentData)
+    {
+        // Pass the appropriate byte arrays to each reader.
+        for (JpegSegmentMetadataReader reader : readers) {
+            for (JpegSegmentType segmentType : reader.getSegmentTypes()) {
+                for (byte[] segmentBytes : segmentData.getSegments(segmentType)) {
+                    if (reader.canProcess(segmentBytes, segmentType)) {
+                        reader.extract(segmentBytes, metadata, segmentType);
+                    }
+                }
+            }
+        }
     }
 
@@ -120,3 +137,2 @@
     }
 }
-
Index: trunk/src/com/drew/imaging/jpeg/JpegProcessingException.java
===================================================================
--- trunk/src/com/drew/imaging/jpeg/JpegProcessingException.java	(revision 6127)
+++ trunk/src/com/drew/imaging/jpeg/JpegProcessingException.java	(revision 8132)
@@ -1,4 +1,4 @@
 /*
- * Copyright 2002-2012 Drew Noakes
+ * Copyright 2002-2015 Drew Noakes
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,6 +16,6 @@
  * More information about this project is available at:
  *
- *    http://drewnoakes.com/code/exif/
- *    http://code.google.com/p/metadata-extractor/
+ *    https://drewnoakes.com/code/exif/
+ *    https://github.com/drewnoakes/metadata-extractor
  */
 package com.drew.imaging.jpeg;
@@ -25,7 +25,7 @@
 
 /**
- * An exception class thrown upon unexpected and fatal conditions while processing a Jpeg file.
+ * An exception class thrown upon unexpected and fatal conditions while processing a JPEG file.
  *
- * @author Drew Noakes http://drewnoakes.com
+ * @author Drew Noakes https://drewnoakes.com
  */
 public class JpegProcessingException extends ImageProcessingException
Index: trunk/src/com/drew/imaging/jpeg/JpegSegmentData.java
===================================================================
--- trunk/src/com/drew/imaging/jpeg/JpegSegmentData.java	(revision 6127)
+++ trunk/src/com/drew/imaging/jpeg/JpegSegmentData.java	(revision 8132)
@@ -1,4 +1,4 @@
 /*
- * Copyright 2002-2012 Drew Noakes
+ * Copyright 2002-2015 Drew Noakes
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,6 +16,6 @@
  * More information about this project is available at:
  *
- *    http://drewnoakes.com/code/exif/
- *    http://code.google.com/p/metadata-extractor/
+ *    https://drewnoakes.com/code/exif/
+ *    https://github.com/drewnoakes/metadata-extractor
  */
 package com.drew.imaging.jpeg;
@@ -24,24 +24,23 @@
 import com.drew.lang.annotations.Nullable;
 
-import java.io.*;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
 
 /**
- * Holds a collection of Jpeg data segments.  This need not necessarily be all segments
- * within the Jpeg.  For example, it may be convenient to store only the non-image
- * segments when analysing (or serializing) metadata.
- * <p/>
- * Segments are keyed via their segment marker (a byte).  Where multiple segments use the
- * same segment marker, they will all be stored and available.
- *
- * @author Drew Noakes http://drewnoakes.com
+ * Holds a collection of JPEG data segments.  This need not necessarily be all segments
+ * within the JPEG. For example, it may be convenient to store only the non-image
+ * segments when analysing metadata.
+ * <p>
+ * Segments are keyed via their {@link JpegSegmentType}. Where multiple segments use the
+ * same segment type, they will all be stored and available.
+ * <p>
+ * Each segment type may contain multiple entries. Conceptually the model is:
+ * <code>Map&lt;JpegSegmentType, Collection&lt;byte[]&gt;&gt;</code>. This class provides
+ * convenience methods around that structure.
+ *
+ * @author Drew Noakes https://drewnoakes.com
  */
-public class JpegSegmentData implements Serializable
+public class JpegSegmentData
 {
-    private static final long serialVersionUID = 7110175216435025451L;
-    
-    /** A map of byte[], keyed by the segment marker */
+    // TODO key this on JpegSegmentType rather than Byte, and hopefully lose much of the use of 'byte' with this class
     @NotNull
     private final HashMap<Byte, List<byte[]>> _segmentDataMap = new HashMap<Byte, List<byte[]>>(10);
@@ -49,71 +48,129 @@
     /**
      * Adds segment bytes to the collection.
-     * @param segmentMarker
-     * @param segmentBytes
-     */
-    @SuppressWarnings({ "MismatchedQueryAndUpdateOfCollection" })
-    public void addSegment(byte segmentMarker, @NotNull byte[] segmentBytes)
-    {
-        final List<byte[]> segmentList = getOrCreateSegmentList(segmentMarker);
-        segmentList.add(segmentBytes);
-    }
-
-    /**
-     * Gets the first Jpeg segment data for the specified marker.
-     * @param segmentMarker the byte identifier for the desired segment
+     *
+     * @param segmentType  the type of the segment being added
+     * @param segmentBytes the byte array holding data for the segment being added
+     */
+    @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"})
+    public void addSegment(byte segmentType, @NotNull byte[] segmentBytes)
+    {
+        getOrCreateSegmentList(segmentType).add(segmentBytes);
+    }
+
+    /**
+     * Gets the set of JPEG segment type identifiers.
+     */
+    public Iterable<JpegSegmentType> getSegmentTypes()
+    {
+        Set<JpegSegmentType> segmentTypes = new HashSet<JpegSegmentType>();
+
+        for (Byte segmentTypeByte : _segmentDataMap.keySet())
+        {
+            JpegSegmentType segmentType = JpegSegmentType.fromByte(segmentTypeByte);
+            if (segmentType == null) {
+                throw new IllegalStateException("Should not have a segmentTypeByte that is not in the enum: " + Integer.toHexString(segmentTypeByte));
+            }
+            segmentTypes.add(segmentType);
+        }
+
+        return segmentTypes;
+    }
+
+    /**
+     * Gets the first JPEG segment data for the specified type.
+     *
+     * @param segmentType the JpegSegmentType for the desired segment
      * @return a byte[] containing segment data or null if no data exists for that segment
      */
     @Nullable
-    public byte[] getSegment(byte segmentMarker)
-    {
-        return getSegment(segmentMarker, 0);
-    }
-
-    /**
-     * Gets segment data for a specific occurrence and marker.  Use this method when more than one occurrence
-     * of segment data for a given marker exists.
-     * @param segmentMarker identifies the required segment
-     * @param occurrence the zero-based index of the occurrence
-     * @return the segment data as a byte[], or null if no segment exists for the marker & occurrence
-     */
-    @Nullable
-    public byte[] getSegment(byte segmentMarker, int occurrence)
-    {
-        final List<byte[]> segmentList = getSegmentList(segmentMarker);
-
-        if (segmentList==null || segmentList.size()<=occurrence)
-            return null;
-        else
-            return segmentList.get(occurrence);
-    }
-
-    /**
-     * Returns all instances of a given Jpeg segment.  If no instances exist, an empty sequence is returned.
-     *
-     * @param segmentMarker a number which identifies the type of Jpeg segment being queried
-     * @return zero or more byte arrays, each holding the data of a Jpeg segment
-     */
-    @NotNull
-    public Iterable<byte[]> getSegments(byte segmentMarker)
-    {
-        final List<byte[]> segmentList = getSegmentList(segmentMarker);
-        return segmentList==null ? new ArrayList<byte[]>() : segmentList;
-    }
-
-    @Nullable
-    public List<byte[]> getSegmentList(byte segmentMarker)
-    {
-        return _segmentDataMap.get(Byte.valueOf(segmentMarker));
-    }
-
-    @NotNull
-    private List<byte[]> getOrCreateSegmentList(byte segmentMarker)
+    public byte[] getSegment(byte segmentType)
+    {
+        return getSegment(segmentType, 0);
+    }
+
+    /**
+     * Gets the first JPEG segment data for the specified type.
+     *
+     * @param segmentType the JpegSegmentType for the desired segment
+     * @return a byte[] containing segment data or null if no data exists for that segment
+     */
+    @Nullable
+    public byte[] getSegment(@NotNull JpegSegmentType segmentType)
+    {
+        return getSegment(segmentType.byteValue, 0);
+    }
+
+    /**
+     * Gets segment data for a specific occurrence and type.  Use this method when more than one occurrence
+     * of segment data for a given type exists.
+     *
+     * @param segmentType identifies the required segment
+     * @param occurrence  the zero-based index of the occurrence
+     * @return the segment data as a byte[], or null if no segment exists for the type &amp; occurrence
+     */
+    @Nullable
+    public byte[] getSegment(@NotNull JpegSegmentType segmentType, int occurrence)
+    {
+        return getSegment(segmentType.byteValue, occurrence);
+    }
+
+    /**
+     * Gets segment data for a specific occurrence and type.  Use this method when more than one occurrence
+     * of segment data for a given type exists.
+     *
+     * @param segmentType identifies the required segment
+     * @param occurrence  the zero-based index of the occurrence
+     * @return the segment data as a byte[], or null if no segment exists for the type &amp; occurrence
+     */
+    @Nullable
+    public byte[] getSegment(byte segmentType, int occurrence)
+    {
+        final List<byte[]> segmentList = getSegmentList(segmentType);
+
+        return segmentList != null && segmentList.size() > occurrence
+                ? segmentList.get(occurrence)
+                : null;
+    }
+
+    /**
+     * Returns all instances of a given JPEG segment.  If no instances exist, an empty sequence is returned.
+     *
+     * @param segmentType a number which identifies the type of JPEG segment being queried
+     * @return zero or more byte arrays, each holding the data of a JPEG segment
+     */
+    @NotNull
+    public Iterable<byte[]> getSegments(@NotNull JpegSegmentType segmentType)
+    {
+        return getSegments(segmentType.byteValue);
+    }
+
+    /**
+     * Returns all instances of a given JPEG segment.  If no instances exist, an empty sequence is returned.
+     *
+     * @param segmentType a number which identifies the type of JPEG segment being queried
+     * @return zero or more byte arrays, each holding the data of a JPEG segment
+     */
+    @NotNull
+    public Iterable<byte[]> getSegments(byte segmentType)
+    {
+        final List<byte[]> segmentList = getSegmentList(segmentType);
+        return segmentList == null ? new ArrayList<byte[]>() : segmentList;
+    }
+
+    @Nullable
+    private List<byte[]> getSegmentList(byte segmentType)
+    {
+        return _segmentDataMap.get(segmentType);
+    }
+
+    @NotNull
+    private List<byte[]> getOrCreateSegmentList(byte segmentType)
     {
         List<byte[]> segmentList;
-        if (_segmentDataMap.containsKey(segmentMarker)) {
-            segmentList = _segmentDataMap.get(segmentMarker);
+        if (_segmentDataMap.containsKey(segmentType)) {
+            segmentList = _segmentDataMap.get(segmentType);
         } else {
             segmentList = new ArrayList<byte[]>();
-            _segmentDataMap.put(segmentMarker, segmentList);
+            _segmentDataMap.put(segmentType, segmentList);
         }
         return segmentList;
@@ -121,11 +178,23 @@
 
     /**
-     * Returns the count of segment data byte arrays stored for a given segment marker.
-     * @param segmentMarker identifies the required segment
+     * Returns the count of segment data byte arrays stored for a given segment type.
+     *
+     * @param segmentType identifies the required segment
      * @return the segment count (zero if no segments exist).
      */
-    public int getSegmentCount(byte segmentMarker)
-    {
-        final List<byte[]> segmentList = getSegmentList(segmentMarker);
+    public int getSegmentCount(@NotNull JpegSegmentType segmentType)
+    {
+        return getSegmentCount(segmentType.byteValue);
+    }
+
+    /**
+     * Returns the count of segment data byte arrays stored for a given segment type.
+     *
+     * @param segmentType identifies the required segment
+     * @return the segment count (zero if no segments exist).
+     */
+    public int getSegmentCount(byte segmentType)
+    {
+        final List<byte[]> segmentList = getSegmentList(segmentType);
         return segmentList == null ? 0 : segmentList.size();
     }
@@ -133,76 +202,69 @@
     /**
      * Removes a specified instance of a segment's data from the collection.  Use this method when more than one
-     * occurrence of segment data for a given marker exists.
-     * @param segmentMarker identifies the required segment
-     * @param occurrence the zero-based index of the segment occurrence to remove.
-     */
-    @SuppressWarnings({ "MismatchedQueryAndUpdateOfCollection" })
-    public void removeSegmentOccurrence(byte segmentMarker, int occurrence)
-    {
-        final List<byte[]> segmentList = _segmentDataMap.get(Byte.valueOf(segmentMarker));
+     * occurrence of segment data exists for a given type exists.
+     *
+     * @param segmentType identifies the required segment
+     * @param occurrence  the zero-based index of the segment occurrence to remove.
+     */
+    @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"})
+    public void removeSegmentOccurrence(@NotNull JpegSegmentType segmentType, int occurrence)
+    {
+        removeSegmentOccurrence(segmentType.byteValue, occurrence);
+    }
+
+    /**
+     * Removes a specified instance of a segment's data from the collection.  Use this method when more than one
+     * occurrence of segment data exists for a given type exists.
+     *
+     * @param segmentType identifies the required segment
+     * @param occurrence  the zero-based index of the segment occurrence to remove.
+     */
+    @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"})
+    public void removeSegmentOccurrence(byte segmentType, int occurrence)
+    {
+        final List<byte[]> segmentList = _segmentDataMap.get(segmentType);
         segmentList.remove(occurrence);
     }
 
     /**
-     * Removes all segments from the collection having the specified marker.
-     * @param segmentMarker identifies the required segment
-     */
-    public void removeSegment(byte segmentMarker)
-    {
-        _segmentDataMap.remove(Byte.valueOf(segmentMarker));
-    }
-
-    /**
-     * Determines whether data is present for a given segment marker.
-     * @param segmentMarker identifies the required segment
+     * Removes all segments from the collection having the specified type.
+     *
+     * @param segmentType identifies the required segment
+     */
+    public void removeSegment(@NotNull JpegSegmentType segmentType)
+    {
+        removeSegment(segmentType.byteValue);
+    }
+
+    /**
+     * Removes all segments from the collection having the specified type.
+     *
+     * @param segmentType identifies the required segment
+     */
+    public void removeSegment(byte segmentType)
+    {
+        _segmentDataMap.remove(segmentType);
+    }
+
+    /**
+     * Determines whether data is present for a given segment type.
+     *
+     * @param segmentType identifies the required segment
      * @return true if data exists, otherwise false
      */
-    public boolean containsSegment(byte segmentMarker)
-    {
-        return _segmentDataMap.containsKey(Byte.valueOf(segmentMarker));
-    }
-
-    /**
-     * Serialises the contents of a JpegSegmentData to a file.
-     * @param file to file to write from
-     * @param segmentData the data to write
-     * @throws IOException if problems occur while writing
-     */
-    public static void toFile(@NotNull File file, @NotNull JpegSegmentData segmentData) throws IOException
-    {
-        FileOutputStream fileOutputStream = null;
-        try
-        {
-            fileOutputStream = new FileOutputStream(file);
-            new ObjectOutputStream(fileOutputStream).writeObject(segmentData);
-        }
-        finally
-        {
-            if (fileOutputStream!=null)
-                fileOutputStream.close();
-        }
-    }
-
-    /**
-     * Deserialises the contents of a JpegSegmentData from a file.
-     * @param file the file to read from
-     * @return the JpegSegmentData as read
-     * @throws IOException if problems occur while reading
-     * @throws ClassNotFoundException if problems occur while deserialising
-     */
-    @NotNull
-    public static JpegSegmentData fromFile(@NotNull File file) throws IOException, ClassNotFoundException
-    {
-        ObjectInputStream inputStream = null;
-        try
-        {
-            inputStream = new ObjectInputStream(new FileInputStream(file));
-            return (JpegSegmentData)inputStream.readObject();
-        }
-        finally
-        {
-            if (inputStream!=null)
-                inputStream.close();
-        }
+    public boolean containsSegment(@NotNull JpegSegmentType segmentType)
+    {
+        return containsSegment(segmentType.byteValue);
+    }
+
+    /**
+     * Determines whether data is present for a given segment type.
+     *
+     * @param segmentType identifies the required segment
+     * @return true if data exists, otherwise false
+     */
+    public boolean containsSegment(byte segmentType)
+    {
+        return _segmentDataMap.containsKey(segmentType);
     }
 }
Index: trunk/src/com/drew/imaging/jpeg/JpegSegmentMetadataReader.java
===================================================================
--- trunk/src/com/drew/imaging/jpeg/JpegSegmentMetadataReader.java	(revision 8132)
+++ trunk/src/com/drew/imaging/jpeg/JpegSegmentMetadataReader.java	(revision 8132)
@@ -0,0 +1,32 @@
+package com.drew.imaging.jpeg;
+
+import com.drew.lang.annotations.NotNull;
+import com.drew.metadata.Metadata;
+
+/**
+ * Defines an object that extracts metadata from in JPEG segments.
+ */
+public interface JpegSegmentMetadataReader
+{
+    /**
+     * Gets the set of JPEG segment types that this reader is interested in.
+     */
+    @NotNull
+    public Iterable<JpegSegmentType> getSegmentTypes();
+
+    /**
+     * Gets a value indicating whether the supplied byte data can be processed by this reader. This is not a guarantee
+     * that no errors will occur, but rather a best-effort indication of whether the parse is likely to succeed.
+     * Implementations are expected to check things such as the opening bytes, data length, etc.
+     */
+    public boolean canProcess(@NotNull final byte[] segmentBytes, @NotNull final JpegSegmentType segmentType);
+
+    /**
+     * Extracts metadata from a JPEG segment's byte array and merges it into the specified {@link Metadata} object.
+     *
+     * @param segmentBytes The byte array from which the metadata should be extracted.
+     * @param metadata The {@link Metadata} object into which extracted values should be merged.
+     * @param segmentType The {@link JpegSegmentType} being read.
+     */
+    public void extract(@NotNull final byte[] segmentBytes, @NotNull final Metadata metadata, @NotNull final JpegSegmentType segmentType);
+}
Index: trunk/src/com/drew/imaging/jpeg/JpegSegmentReader.java
===================================================================
--- trunk/src/com/drew/imaging/jpeg/JpegSegmentReader.java	(revision 6127)
+++ trunk/src/com/drew/imaging/jpeg/JpegSegmentReader.java	(revision 8132)
@@ -1,4 +1,4 @@
 /*
- * Copyright 2002-2012 Drew Noakes
+ * Copyright 2002-2015 Drew Noakes
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,278 +16,153 @@
  * More information about this project is available at:
  *
- *    http://drewnoakes.com/code/exif/
- *    http://code.google.com/p/metadata-extractor/
+ *    https://drewnoakes.com/code/exif/
+ *    https://github.com/drewnoakes/metadata-extractor
  */
 package com.drew.imaging.jpeg;
 
+import com.drew.lang.SequentialReader;
+import com.drew.lang.StreamReader;
 import com.drew.lang.annotations.NotNull;
 import com.drew.lang.annotations.Nullable;
 
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
 
 /**
- * Performs read functions of Jpeg files, returning specific file segments.
- * @author  Drew Noakes http://drewnoakes.com
+ * Performs read functions of JPEG files, returning specific file segments.
+ * <p>
+ * JPEG files are composed of a sequence of consecutive JPEG 'segments'. Each is identified by one of a set of byte
+ * values, modelled in the {@link JpegSegmentType} enumeration. Use <code>readSegments</code> to read out the some
+ * or all segments into a {@link JpegSegmentData} object, from which the raw JPEG segment byte arrays may be accessed.
+ *
+ * @author Drew Noakes https://drewnoakes.com
  */
 public class JpegSegmentReader
 {
-    // TODO add a findAvailableSegments() method
-    // TODO add more segment identifiers
-    // TODO add a getSegmentDescription() method, returning for example 'App1 application data segment, commonly containing Exif data'
-
-    @NotNull
-    private final JpegSegmentData _segmentData;
-
     /**
      * Private, because this segment crashes my algorithm, and searching for it doesn't work (yet).
      */
-    private static final byte SEGMENT_SOS = (byte)0xDA;
+    private static final byte SEGMENT_SOS = (byte) 0xDA;
 
     /**
      * Private, because one wouldn't search for it.
      */
-    private static final byte MARKER_EOI = (byte)0xD9;
-
-    /** APP0 Jpeg segment identifier -- JFIF data (also JFXX apparently). */
-    public static final byte SEGMENT_APP0 = (byte)0xE0;
-    /** APP1 Jpeg segment identifier -- where Exif data is kept.  XMP data is also kept in here, though usually in a second instance. */
-    public static final byte SEGMENT_APP1 = (byte)0xE1;
-    /** APP2 Jpeg segment identifier. */
-    public static final byte SEGMENT_APP2 = (byte)0xE2;
-    /** APP3 Jpeg segment identifier. */
-    public static final byte SEGMENT_APP3 = (byte)0xE3;
-    /** APP4 Jpeg segment identifier. */
-    public static final byte SEGMENT_APP4 = (byte)0xE4;
-    /** APP5 Jpeg segment identifier. */
-    public static final byte SEGMENT_APP5 = (byte)0xE5;
-    /** APP6 Jpeg segment identifier. */
-    public static final byte SEGMENT_APP6 = (byte)0xE6;
-    /** APP7 Jpeg segment identifier. */
-    public static final byte SEGMENT_APP7 = (byte)0xE7;
-    /** APP8 Jpeg segment identifier. */
-    public static final byte SEGMENT_APP8 = (byte)0xE8;
-    /** APP9 Jpeg segment identifier. */
-    public static final byte SEGMENT_APP9 = (byte)0xE9;
-    /** APPA (App10) Jpeg segment identifier -- can hold Unicode comments. */
-    public static final byte SEGMENT_APPA = (byte)0xEA;
-    /** APPB (App11) Jpeg segment identifier. */
-    public static final byte SEGMENT_APPB = (byte)0xEB;
-    /** APPC (App12) Jpeg segment identifier. */
-    public static final byte SEGMENT_APPC = (byte)0xEC;
-    /** APPD (App13) Jpeg segment identifier -- IPTC data in here. */
-    public static final byte SEGMENT_APPD = (byte)0xED;
-    /** APPE (App14) Jpeg segment identifier. */
-    public static final byte SEGMENT_APPE = (byte)0xEE;
-    /** APPF (App15) Jpeg segment identifier. */
-    public static final byte SEGMENT_APPF = (byte)0xEF;
-    /** Start Of Image segment identifier. */
-    public static final byte SEGMENT_SOI = (byte)0xD8;
-    /** Define Quantization Table segment identifier. */
-    public static final byte SEGMENT_DQT = (byte)0xDB;
-    /** Define Huffman Table segment identifier. */
-    public static final byte SEGMENT_DHT = (byte)0xC4;
-    /** Start-of-Frame Zero segment identifier. */
-    public static final byte SEGMENT_SOF0 = (byte)0xC0;
-    /** Jpeg comment segment identifier. */
-    public static final byte SEGMENT_COM = (byte)0xFE;
+    private static final byte MARKER_EOI = (byte) 0xD9;
 
     /**
-     * Creates a JpegSegmentReader for a specific file.
-     * @param file the Jpeg file to read segments from
+     * Processes the provided JPEG data, and extracts the specified JPEG segments into a {@link JpegSegmentData} object.
+     * <p>
+     * Will not return SOS (start of scan) or EOI (end of image) segments.
+     *
+     * @param file a {@link File} from which the JPEG data will be read.
+     * @param segmentTypes the set of JPEG segments types that are to be returned. If this argument is <code>null</code>
+     *                     then all found segment types are returned.
      */
-    @SuppressWarnings({ "ConstantConditions" })
-    public JpegSegmentReader(@NotNull File file) throws JpegProcessingException, IOException
+    @NotNull
+    public static JpegSegmentData readSegments(@NotNull File file, @Nullable Iterable<JpegSegmentType> segmentTypes) throws JpegProcessingException, IOException
     {
-        if (file==null)
-            throw new NullPointerException();
-
-        InputStream inputStream = null;
+        FileInputStream stream = null;
         try {
-            inputStream = new FileInputStream(file);
-            _segmentData = readSegments(new BufferedInputStream(inputStream), false);
+            stream = new FileInputStream(file);
+            return readSegments(new StreamReader(stream), segmentTypes);
         } finally {
-            if (inputStream != null)
-                inputStream.close();
+            if (stream != null) {
+                stream.close();
+            }
         }
     }
 
     /**
-     * Creates a JpegSegmentReader for a byte array.
-     * @param fileContents the byte array containing Jpeg data
+     * Processes the provided JPEG data, and extracts the specified JPEG segments into a {@link JpegSegmentData} object.
+     * <p>
+     * Will not return SOS (start of scan) or EOI (end of image) segments.
+     *
+     * @param reader a {@link SequentialReader} from which the JPEG data will be read. It must be positioned at the
+     *               beginning of the JPEG data stream.
+     * @param segmentTypes the set of JPEG segments types that are to be returned. If this argument is <code>null</code>
+     *                     then all found segment types are returned.
      */
-    @SuppressWarnings({ "ConstantConditions" })
-    public JpegSegmentReader(@NotNull byte[] fileContents) throws JpegProcessingException
+    @NotNull
+    public static JpegSegmentData readSegments(@NotNull final SequentialReader reader, @Nullable Iterable<JpegSegmentType> segmentTypes) throws JpegProcessingException, IOException
     {
-        if (fileContents==null)
-            throw new NullPointerException();
+        // Must be big-endian
+        assert (reader.isMotorolaByteOrder());
 
-        BufferedInputStream stream = new BufferedInputStream(new ByteArrayInputStream(fileContents));
-        _segmentData = readSegments(stream, false);
+        // first two bytes should be JPEG magic number
+        final int magicNumber = reader.getUInt16();
+        if (magicNumber != 0xFFD8) {
+            throw new JpegProcessingException("JPEG data is expected to begin with 0xFFD8 (ÿØ) not 0x" + Integer.toHexString(magicNumber));
+        }
+
+        Set<Byte> segmentTypeBytes = null;
+        if (segmentTypes != null) {
+            segmentTypeBytes = new HashSet<Byte>();
+            for (JpegSegmentType segmentType : segmentTypes) {
+                segmentTypeBytes.add(segmentType.byteValue);
+            }
+        }
+
+        JpegSegmentData segmentData = new JpegSegmentData();
+
+        do {
+            // Find the segment marker. Markers are zero or more 0xFF bytes, followed
+            // by a 0xFF and then a byte not equal to 0x00 or 0xFF.
+
+            final short segmentIdentifier = reader.getUInt8();
+
+            // We must have at least one 0xFF byte
+            if (segmentIdentifier != 0xFF)
+                throw new JpegProcessingException("Expected JPEG segment start identifier 0xFF, not 0x" + Integer.toHexString(segmentIdentifier).toUpperCase());
+
+            // Read until we have a non-0xFF byte. This identifies the segment type.
+            byte segmentType = reader.getInt8();
+            while (segmentType == (byte)0xFF)
+                segmentType = reader.getInt8();
+
+            if (segmentType == 0)
+                throw new JpegProcessingException("Expected non-zero byte as part of JPEG marker identifier");
+
+            if (segmentType == SEGMENT_SOS) {
+                // The 'Start-Of-Scan' segment's length doesn't include the image data, instead would
+                // have to search for the two bytes: 0xFF 0xD9 (EOI).
+                // It comes last so simply return at this point
+                return segmentData;
+            }
+
+            if (segmentType == MARKER_EOI) {
+                // the 'End-Of-Image' segment -- this should never be found in this fashion
+                return segmentData;
+            }
+
+            // next 2-bytes are <segment-size>: [high-byte] [low-byte]
+            int segmentLength = reader.getUInt16();
+
+            // segment length includes size bytes, so subtract two
+            segmentLength -= 2;
+
+            if (segmentLength < 0)
+                throw new JpegProcessingException("JPEG segment size would be less than zero");
+
+            // Check whether we are interested in this segment
+            if (segmentTypeBytes == null || segmentTypeBytes.contains(segmentType)) {
+                byte[] segmentBytes = reader.getBytes(segmentLength);
+                assert (segmentLength == segmentBytes.length);
+                segmentData.addSegment(segmentType, segmentBytes);
+            } else {
+                // Some if the JPEG is truncated, just return what data we've already gathered
+                if (!reader.trySkip(segmentLength)) {
+                    return segmentData;
+                }
+            }
+
+        } while (true);
     }
 
-    /**
-     * Creates a JpegSegmentReader for an InputStream.
-     * @param inputStream the InputStream containing Jpeg data
-     */
-    @SuppressWarnings({ "ConstantConditions" })
-    public JpegSegmentReader(@NotNull InputStream inputStream, boolean waitForBytes) throws JpegProcessingException
+    private JpegSegmentReader() throws Exception
     {
-        if (inputStream==null)
-            throw new NullPointerException();
-
-        BufferedInputStream bufferedInputStream = inputStream instanceof BufferedInputStream
-                ? (BufferedInputStream)inputStream
-                : new BufferedInputStream(inputStream);
-
-        _segmentData = readSegments(bufferedInputStream, waitForBytes);
-    }
-
-    /**
-     * Reads the first instance of a given Jpeg segment, returning the contents as
-     * a byte array.
-     * @param segmentMarker the byte identifier for the desired segment
-     * @return the byte array if found, else null
-     */
-    @Nullable
-    public byte[] readSegment(byte segmentMarker)
-    {
-        return readSegment(segmentMarker, 0);
-    }
-
-    /**
-     * Reads the Nth instance of a given Jpeg segment, returning the contents as a byte array.
-     * 
-     * @param segmentMarker the byte identifier for the desired segment
-     * @param occurrence the occurrence of the specified segment within the jpeg file
-     * @return the byte array if found, else null
-     */
-    @Nullable
-    public byte[] readSegment(byte segmentMarker, int occurrence)
-    {
-        return _segmentData.getSegment(segmentMarker, occurrence);
-    }
-
-    /**
-     * Returns all instances of a given Jpeg segment.  If no instances exist, an empty sequence is returned.
-     *
-     * @param segmentMarker a number which identifies the type of Jpeg segment being queried
-     * @return zero or more byte arrays, each holding the data of a Jpeg segment
-     */
-    @NotNull
-    public Iterable<byte[]> readSegments(byte segmentMarker)
-    {
-        return _segmentData.getSegments(segmentMarker);
-    }
-
-    /**
-     * Returns the number of segments having the specified JPEG segment marker.
-     * @param segmentMarker the JPEG segment identifying marker.
-     * @return the count of matching segments.
-     */
-    public final int getSegmentCount(byte segmentMarker)
-    {
-        return _segmentData.getSegmentCount(segmentMarker);
-    }
-
-    /**
-     * Returns the JpegSegmentData object used by this reader.
-     * @return the JpegSegmentData object.
-     */
-    @NotNull
-    public final JpegSegmentData getSegmentData()
-    {
-        return _segmentData;
-    }
-
-    @NotNull
-    private JpegSegmentData readSegments(@NotNull final BufferedInputStream jpegInputStream, boolean waitForBytes) throws JpegProcessingException
-    {
-        JpegSegmentData segmentData = new JpegSegmentData();
-
-        try {
-            int offset = 0;
-            // first two bytes should be jpeg magic number
-            byte[] headerBytes = new byte[2];
-            if (jpegInputStream.read(headerBytes, 0, 2)!=2)
-                throw new JpegProcessingException("not a jpeg file");
-            final boolean hasValidHeader = (headerBytes[0] & 0xFF) == 0xFF && (headerBytes[1] & 0xFF) == 0xD8;
-            if (!hasValidHeader)
-                throw new JpegProcessingException("not a jpeg file");
-
-            offset += 2;
-            do {
-                // need four bytes from stream for segment header before continuing
-                if (!checkForBytesOnStream(jpegInputStream, 4, waitForBytes))
-                    throw new JpegProcessingException("stream ended before segment header could be read");
-
-                // next byte is 0xFF
-                byte segmentIdentifier = (byte)(jpegInputStream.read() & 0xFF);
-                if ((segmentIdentifier & 0xFF) != 0xFF) {
-                    throw new JpegProcessingException("expected jpeg segment start identifier 0xFF at offset " + offset + ", not 0x" + Integer.toHexString(segmentIdentifier & 0xFF));
-                }
-                offset++;
-                // next byte is <segment-marker>
-                byte thisSegmentMarker = (byte)(jpegInputStream.read() & 0xFF);
-                offset++;
-                // next 2-bytes are <segment-size>: [high-byte] [low-byte]
-                byte[] segmentLengthBytes = new byte[2];
-                if (jpegInputStream.read(segmentLengthBytes, 0, 2) != 2)
-                    throw new JpegProcessingException("Jpeg data ended unexpectedly.");
-                offset += 2;
-                int segmentLength = ((segmentLengthBytes[0] << 8) & 0xFF00) | (segmentLengthBytes[1] & 0xFF);
-                // segment length includes size bytes, so subtract two
-                segmentLength -= 2;
-                if (!checkForBytesOnStream(jpegInputStream, segmentLength, waitForBytes))
-                    throw new JpegProcessingException("segment size would extend beyond file stream length");
-                if (segmentLength < 0)
-                    throw new JpegProcessingException("segment size would be less than zero");
-                byte[] segmentBytes = new byte[segmentLength];
-                if (jpegInputStream.read(segmentBytes, 0, segmentLength) != segmentLength)
-                    throw new JpegProcessingException("Jpeg data ended unexpectedly.");
-                offset += segmentLength;
-                if ((thisSegmentMarker & 0xFF) == (SEGMENT_SOS & 0xFF)) {
-                    // The 'Start-Of-Scan' segment's length doesn't include the image data, instead would
-                    // have to search for the two bytes: 0xFF 0xD9 (EOI).
-                    // It comes last so simply return at this point
-                    return segmentData;
-                } else if ((thisSegmentMarker & 0xFF) == (MARKER_EOI & 0xFF)) {
-                    // the 'End-Of-Image' segment -- this should never be found in this fashion
-                    return segmentData;
-                } else {
-                    segmentData.addSegment(thisSegmentMarker, segmentBytes);
-                }
-            } while (true);
-        } catch (IOException ioe) {
-            throw new JpegProcessingException("IOException processing Jpeg file: " + ioe.getMessage(), ioe);
-        } finally {
-            try {
-                if (jpegInputStream != null) {
-                    jpegInputStream.close();
-                }
-            } catch (IOException ioe) {
-                throw new JpegProcessingException("IOException processing Jpeg file: " + ioe.getMessage(), ioe);
-            }
-        }
-    }
-
-    private boolean checkForBytesOnStream(@NotNull BufferedInputStream stream, int bytesNeeded, boolean waitForBytes) throws IOException
-    {
-        // NOTE  waiting is essential for network streams where data can be delayed, but it is not necessary for byte[] or filesystems
-
-        if (!waitForBytes)
-            return bytesNeeded <= stream.available();
-
-        int count = 40; // * 100ms = approx 4 seconds
-        while (count > 0) {
-            if (bytesNeeded <= stream.available())
-               return true;
-            try {
-                Thread.sleep(100);
-            } catch (InterruptedException e) {
-                // continue
-            }
-            count--;
-        }
-        return false;
+        throw new Exception("Not intended for instantiation.");
     }
 }
Index: trunk/src/com/drew/imaging/jpeg/JpegSegmentType.java
===================================================================
--- trunk/src/com/drew/imaging/jpeg/JpegSegmentType.java	(revision 8132)
+++ trunk/src/com/drew/imaging/jpeg/JpegSegmentType.java	(revision 8132)
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2002-2015 Drew Noakes
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ *
+ * More information about this project is available at:
+ *
+ *    https://drewnoakes.com/code/exif/
+ *    https://github.com/drewnoakes/metadata-extractor
+ */
+package com.drew.imaging.jpeg;
+
+import com.drew.lang.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * An enumeration of the known segment types found in JPEG files.
+ *
+ * @author Drew Noakes https://drewnoakes.com
+ */
+public enum JpegSegmentType
+{
+    /** APP0 JPEG segment identifier -- JFIF data (also JFXX apparently). */
+    APP0((byte)0xE0, true),
+
+    /** APP1 JPEG segment identifier -- where Exif data is kept.  XMP data is also kept in here, though usually in a second instance. */
+    APP1((byte)0xE1, true),
+
+    /** APP2 JPEG segment identifier. */
+    APP2((byte)0xE2, true),
+
+    /** APP3 JPEG segment identifier. */
+    APP3((byte)0xE3, true),
+
+    /** APP4 JPEG segment identifier. */
+    APP4((byte)0xE4, true),
+
+    /** APP5 JPEG segment identifier. */
+    APP5((byte)0xE5, true),
+
+    /** APP6 JPEG segment identifier. */
+    APP6((byte)0xE6, true),
+
+    /** APP7 JPEG segment identifier. */
+    APP7((byte)0xE7, true),
+
+    /** APP8 JPEG segment identifier. */
+    APP8((byte)0xE8, true),
+
+    /** APP9 JPEG segment identifier. */
+    APP9((byte)0xE9, true),
+
+    /** APPA (App10) JPEG segment identifier -- can hold Unicode comments. */
+    APPA((byte)0xEA, true),
+
+    /** APPB (App11) JPEG segment identifier. */
+    APPB((byte)0xEB, true),
+
+    /** APPC (App12) JPEG segment identifier. */
+    APPC((byte)0xEC, true),
+
+    /** APPD (App13) JPEG segment identifier -- IPTC data in here. */
+    APPD((byte)0xED, true),
+
+    /** APPE (App14) JPEG segment identifier. */
+    APPE((byte)0xEE, true),
+
+    /** APPF (App15) JPEG segment identifier. */
+    APPF((byte)0xEF, true),
+
+    /** Start Of Image segment identifier. */
+    SOI((byte)0xD8, false),
+
+    /** Define Quantization Table segment identifier. */
+    DQT((byte)0xDB, false),
+
+    /** Define Huffman Table segment identifier. */
+    DHT((byte)0xC4, false),
+
+    /** Start-of-Frame (0) segment identifier. */
+    SOF0((byte)0xC0, true),
+
+    /** Start-of-Frame (1) segment identifier. */
+    SOF1((byte)0xC1, true),
+
+    /** Start-of-Frame (2) segment identifier. */
+    SOF2((byte)0xC2, true),
+
+    /** Start-of-Frame (3) segment identifier. */
+    SOF3((byte)0xC3, true),
+
+//    /** Start-of-Frame (4) segment identifier. */
+//    SOF4((byte)0xC4, true),
+
+    /** Start-of-Frame (5) segment identifier. */
+    SOF5((byte)0xC5, true),
+
+    /** Start-of-Frame (6) segment identifier. */
+    SOF6((byte)0xC6, true),
+
+    /** Start-of-Frame (7) segment identifier. */
+    SOF7((byte)0xC7, true),
+
+    /** Start-of-Frame (8) segment identifier. */
+    SOF8((byte)0xC8, true),
+
+    /** Start-of-Frame (9) segment identifier. */
+    SOF9((byte)0xC9, true),
+
+    /** Start-of-Frame (10) segment identifier. */
+    SOF10((byte)0xCA, true),
+
+    /** Start-of-Frame (11) segment identifier. */
+    SOF11((byte)0xCB, true),
+
+//    /** Start-of-Frame (12) segment identifier. */
+//    SOF12((byte)0xCC, true),
+
+    /** Start-of-Frame (13) segment identifier. */
+    SOF13((byte)0xCD, true),
+
+    /** Start-of-Frame (14) segment identifier. */
+    SOF14((byte)0xCE, true),
+
+    /** Start-of-Frame (15) segment identifier. */
+    SOF15((byte)0xCF, true),
+
+    /** JPEG comment segment identifier. */
+    COM((byte)0xFE, true);
+
+    public static final Collection<JpegSegmentType> canContainMetadataTypes;
+
+    static {
+        List<JpegSegmentType> segmentTypes = new ArrayList<JpegSegmentType>();
+        for (JpegSegmentType segmentType : JpegSegmentType.class.getEnumConstants()) {
+            if (segmentType.canContainMetadata) {
+                segmentTypes.add(segmentType);
+            }
+        }
+        canContainMetadataTypes = segmentTypes;
+    }
+
+    public final byte byteValue;
+    public final boolean canContainMetadata;
+
+    JpegSegmentType(byte byteValue, boolean canContainMetadata)
+    {
+        this.byteValue = byteValue;
+        this.canContainMetadata = canContainMetadata;
+    }
+
+    @Nullable
+    public static JpegSegmentType fromByte(byte segmentTypeByte)
+    {
+        for (JpegSegmentType segmentType : JpegSegmentType.class.getEnumConstants()) {
+            if (segmentType.byteValue == segmentTypeByte)
+                return segmentType;
+        }
+        return null;
+    }
+}
Index: trunk/src/com/drew/imaging/jpeg/package.html
===================================================================
--- trunk/src/com/drew/imaging/jpeg/package.html	(revision 8132)
+++ trunk/src/com/drew/imaging/jpeg/package.html	(revision 8132)
@@ -0,0 +1,33 @@
+<!--
+  ~ Copyright 2002-2015 Drew Noakes
+  ~
+  ~    Licensed under the Apache License, Version 2.0 (the "License");
+  ~    you may not use this file except in compliance with the License.
+  ~    You may obtain a copy of the License at
+  ~
+  ~        http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~    Unless required by applicable law or agreed to in writing, software
+  ~    distributed under the License is distributed on an "AS IS" BASIS,
+  ~    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~    See the License for the specific language governing permissions and
+  ~    limitations under the License.
+  ~
+  ~ More information about this project is available at:
+  ~
+  ~    https://drewnoakes.com/code/exif/
+  ~    https://github.com/drewnoakes/metadata-extractor
+  -->
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+</head>
+<body bgcolor="white">
+
+Contains classes for working with JPEG files.
+
+<!-- Put @see and @since tags down here. -->
+
+</body>
+</html>
