Package org.apache.commons.imaging.formats.jpeg.exif

# Class ExifRewriter

java.lang.Object
org.apache.commons.imaging.common.BinaryFileParser
org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter

public class ExifRewriter extends BinaryFileParser
Interface for Exif write/update/remove functionality for Jpeg/JFIF images.

See the source of the ExifMetadataUpdateExample class for example usage.

See Also:
  - org.apache.commons.imaging.examples.WriteExifMetadataExample

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ExifRewriter()`
  Constructs a new instance with the default, big-endian, byte order.
  `ExifRewriter(ByteOrder byteOrder)`
  Constructs a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `removeExifMetadata(byte[] src, OutputStream os)`
  Reads a JPEG image, removes all EXIF metadata (by removing the APP1 segment), and writes the result to a stream.
  `void`
  `removeExifMetadata(File src, OutputStream os)`
  Reads a JPEG image, removes all EXIF metadata (by removing the APP1 segment), and writes the result to a stream.
  `void`
  `removeExifMetadata(InputStream src, OutputStream os)`
  Reads a JPEG image, removes all EXIF metadata (by removing the APP1 segment), and writes the result to a stream.
  `void`
  `removeExifMetadata(ByteSource byteSource, OutputStream os)`
  Reads a JPEG image, removes all EXIF metadata (by removing the APP1 segment), and writes the result to a stream.
  `void`
  `updateExifMetadataLossless(byte[] src, OutputStream os, TiffOutputSet outputSet)`
  Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.
  `void`
  `updateExifMetadataLossless(File src, OutputStream os, TiffOutputSet outputSet)`
  Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.
  `void`
  `updateExifMetadataLossless(InputStream src, OutputStream os, TiffOutputSet outputSet)`
  Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.
  `void`
  `updateExifMetadataLossless(ByteSource byteSource, OutputStream os, TiffOutputSet outputSet)`
  Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.
  `void`
  `updateExifMetadataLossy(byte[] src, OutputStream os, TiffOutputSet outputSet)`
  Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.
  `void`
  `updateExifMetadataLossy(File src, OutputStream os, TiffOutputSet outputSet)`
  Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.
  `void`
  `updateExifMetadataLossy(InputStream src, OutputStream os, TiffOutputSet outputSet)`
  Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.
  `void`
  `updateExifMetadataLossy(ByteSource byteSource, OutputStream os, TiffOutputSet outputSet)`
  Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.

  ### Methods inherited from class org.apache.commons.imaging.common.BinaryFileParser

  `debugNumber, debugNumber, getByteOrder, setByteOrder`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ExifRewriter

    public ExifRewriter()
    Constructs a new instance with the default, big-endian, byte order.

    Whether a file contains an image based on its file extension.

  - ### ExifRewriter

    public ExifRewriter(ByteOrder byteOrder)
    Constructs a new instance.
    Parameters:
      `byteOrder` - byte order of EXIF segment.

- ## Method Details

  - ### removeExifMetadata

    public void removeExifMetadata(byte[] src, OutputStream os) throws ImagingException, IOException, ImagingException
    Reads a JPEG image, removes all EXIF metadata (by removing the APP1 segment), and writes the result to a stream.
    Parameters:
      `src` - Byte array containing JPEG image data.
      `os` - OutputStream to write the image to.
    Throws:
      `ImagingException` - if it fails to read the JFIF segments
      `IOException` - if it fails to read the image data
      `ImagingException` - if it fails to write the updated data

  - ### removeExifMetadata

    public void removeExifMetadata(ByteSource byteSource, OutputStream os) throws ImagingException, IOException, ImagingException
    Reads a JPEG image, removes all EXIF metadata (by removing the APP1 segment), and writes the result to a stream.
    Parameters:
      `byteSource` - ByteSource containing JPEG image data.
      `os` - OutputStream to write the image to.
    Throws:
      `ImagingException` - if it fails to read the JFIF segments
      `IOException` - if it fails to read the image data
      `ImagingException` - if it fails to write the updated data

  - ### removeExifMetadata

    public void removeExifMetadata(File src, OutputStream os) throws ImagingException, IOException, ImagingException
    Reads a JPEG image, removes all EXIF metadata (by removing the APP1 segment), and writes the result to a stream.

    Parameters:
      `src` - Image file.
      `os` - OutputStream to write the image to.
    Throws:
      `ImagingException` - if it fails to read the JFIF segments
      `IOException` - if it fails to read the image data
      `ImagingException` - if it fails to write the updated data
    See Also:
      - `File`
      - `OutputStream`
      - `File`
      - `OutputStream`

  - ### removeExifMetadata

    public void removeExifMetadata(InputStream src, OutputStream os) throws ImagingException, IOException, ImagingException
    Reads a JPEG image, removes all EXIF metadata (by removing the APP1 segment), and writes the result to a stream.
    Parameters:
      `src` - InputStream containing JPEG image data.
      `os` - OutputStream to write the image to.
    Throws:
      `ImagingException` - if it fails to read the JFIF segments
      `IOException` - if it fails to read the image data
      `ImagingException` - if it fails to write the updated data

  - ### updateExifMetadataLossless

    public void updateExifMetadataLossless(byte[] src, OutputStream os, TiffOutputSet outputSet) throws ImagingException, IOException, ImagingException
    Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.

    Note that this uses the "Lossless" approach - in order to preserve data embedded in the EXIF segment that it can't parse (such as Maker Notes), this algorithm avoids overwriting any part of the original segment that it couldn't parse. This can cause the EXIF segment to grow with each update, which is a serious issue, since all EXIF data must fit in a single APP1 segment of the JPEG image.

    Parameters:
      `src` - Byte array containing JPEG image data.
      `os` - OutputStream to write the image to.
      `outputSet` - TiffOutputSet containing the EXIF data to write.
    Throws:
      `ImagingException` - if it fails to read the JFIF segments
      `IOException` - if it fails to read the image data
      `ImagingException` - if it fails to write the updated data

  - ### updateExifMetadataLossless

    public void updateExifMetadataLossless(ByteSource byteSource, OutputStream os, TiffOutputSet outputSet) throws ImagingException, IOException, ImagingException
    Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.

    Note that this uses the "Lossless" approach - in order to preserve data embedded in the EXIF segment that it can't parse (such as Maker Notes), this algorithm avoids overwriting any part of the original segment that it couldn't parse. This can cause the EXIF segment to grow with each update, which is a serious issue, since all EXIF data must fit in a single APP1 segment of the JPEG image.

    Parameters:
      `byteSource` - ByteSource containing JPEG image data.
      `os` - OutputStream to write the image to.
      `outputSet` - TiffOutputSet containing the EXIF data to write.
    Throws:
      `ImagingException` - if it fails to read the JFIF segments
      `IOException` - if it fails to read the image data
      `ImagingException` - if it fails to write the updated data

  - ### updateExifMetadataLossless

    public void updateExifMetadataLossless(File src, OutputStream os, TiffOutputSet outputSet) throws ImagingException, IOException, ImagingException
    Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.

    Note that this uses the "Lossless" approach - in order to preserve data embedded in the EXIF segment that it can't parse (such as Maker Notes), this algorithm avoids overwriting any part of the original segment that it couldn't parse. This can cause the EXIF segment to grow with each update, which is a serious issue, since all EXIF data must fit in a single APP1 segment of the JPEG image.

    Parameters:
      `src` - Image file.
      `os` - OutputStream to write the image to.
      `outputSet` - TiffOutputSet containing the EXIF data to write.
    Throws:
      `ImagingException` - if it fails to read the JFIF segments
      `IOException` - if it fails to read the image data
      `ImagingException` - if it fails to write the updated data

  - ### updateExifMetadataLossless

    public void updateExifMetadataLossless(InputStream src, OutputStream os, TiffOutputSet outputSet) throws ImagingException, IOException, ImagingException
    Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.

    Note that this uses the "Lossless" approach - in order to preserve data embedded in the EXIF segment that it can't parse (such as Maker Notes), this algorithm avoids overwriting any part of the original segment that it couldn't parse. This can cause the EXIF segment to grow with each update, which is a serious issue, since all EXIF data must fit in a single APP1 segment of the JPEG image.

    Parameters:
      `src` - InputStream containing JPEG image data.
      `os` - OutputStream to write the image to.
      `outputSet` - TiffOutputSet containing the EXIF data to write.
    Throws:
      `ImagingException` - if it fails to read the JFIF segments
      `IOException` - if it fails to read the image data
      `ImagingException` - if it fails to write the updated data

  - ### updateExifMetadataLossy

    public void updateExifMetadataLossy(byte[] src, OutputStream os, TiffOutputSet outputSet) throws ImagingException, IOException, ImagingException
    Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.

    Note that this uses the "Lossy" approach - the algorithm overwrites the entire EXIF segment, ignoring the possibility that it may be discarding data it couldn't parse (such as Maker Notes).

    Parameters:
      `src` - Byte array containing JPEG image data.
      `os` - OutputStream to write the image to.
      `outputSet` - TiffOutputSet containing the EXIF data to write.
    Throws:
      `ImagingException` - if it fails to read the JFIF segments
      `IOException` - if it fails to read the image data
      `ImagingException` - if it fails to write the updated data

  - ### updateExifMetadataLossy

    public void updateExifMetadataLossy(ByteSource byteSource, OutputStream os, TiffOutputSet outputSet) throws ImagingException, IOException, ImagingException
    Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.

    Note that this uses the "Lossy" approach - the algorithm overwrites the entire EXIF segment, ignoring the possibility that it may be discarding data it couldn't parse (such as Maker Notes).

    Parameters:
      `byteSource` - ByteSource containing JPEG image data.
      `os` - OutputStream to write the image to.
      `outputSet` - TiffOutputSet containing the EXIF data to write.
    Throws:
      `ImagingException` - if it fails to read the JFIF segments
      `IOException` - if it fails to read the image data
      `ImagingException` - if it fails to write the updated data

  - ### updateExifMetadataLossy

    public void updateExifMetadataLossy(File src, OutputStream os, TiffOutputSet outputSet) throws ImagingException, IOException, ImagingException
    Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.

    Note that this uses the "Lossy" approach - the algorithm overwrites the entire EXIF segment, ignoring the possibility that it may be discarding data it couldn't parse (such as Maker Notes).

    Parameters:
      `src` - Image file.
      `os` - OutputStream to write the image to.
      `outputSet` - TiffOutputSet containing the EXIF data to write.
    Throws:
      `ImagingException` - if it fails to read the JFIF segments
      `IOException` - if it fails to read the image data
      `ImagingException` - if it fails to write the updated data

  - ### updateExifMetadataLossy

    public void updateExifMetadataLossy(InputStream src, OutputStream os, TiffOutputSet outputSet) throws ImagingException, IOException, ImagingException
    Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.

    Note that this uses the "Lossy" approach - the algorithm overwrites the entire EXIF segment, ignoring the possibility that it may be discarding data it couldn't parse (such as Maker Notes).

    Parameters:
      `src` - InputStream containing JPEG image data.
      `os` - OutputStream to write the image to.
      `outputSet` - TiffOutputSet containing the EXIF data to write.
    Throws:
      `ImagingException` - if it fails to read the JFIF segments
      `IOException` - if it fails to read the image data
      `ImagingException` - if it fails to write the updated data