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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classExifRewriter.JFIFPieceprivate static classExifRewriter.JFIFPieceImageDataprivate static classExifRewriter.JFIFPiecesprivate static classExifRewriter.JFIFPieceSegmentprivate static classExifRewriter.JFIFPieceSegmentExif
-
Constructor Summary
Constructors Constructor Description ExifRewriter()Constructs a new instance with the default, big-endian, byte order.ExifRewriter(java.nio.ByteOrder byteOrder)Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private ExifRewriter.JFIFPiecesanalyzeJfif(ByteSource byteSource)voidremoveExifMetadata(byte[] src, java.io.OutputStream os)Reads a JPEG image, removes all EXIF metadata (by removing the APP1 segment), and writes the result to a stream.voidremoveExifMetadata(java.io.File src, java.io.OutputStream os)Reads a JPEG image, removes all EXIF metadata (by removing the APP1 segment), and writes the result to a stream.voidremoveExifMetadata(java.io.InputStream src, java.io.OutputStream os)Reads a JPEG image, removes all EXIF metadata (by removing the APP1 segment), and writes the result to a stream.voidremoveExifMetadata(ByteSource byteSource, java.io.OutputStream os)Reads a JPEG image, removes all EXIF metadata (by removing the APP1 segment), and writes the result to a stream.voidupdateExifMetadataLossless(byte[] src, java.io.OutputStream os, TiffOutputSet outputSet)Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.voidupdateExifMetadataLossless(java.io.File src, java.io.OutputStream os, TiffOutputSet outputSet)Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.voidupdateExifMetadataLossless(java.io.InputStream src, java.io.OutputStream os, TiffOutputSet outputSet)Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.voidupdateExifMetadataLossless(ByteSource byteSource, java.io.OutputStream os, TiffOutputSet outputSet)Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.voidupdateExifMetadataLossy(byte[] src, java.io.OutputStream os, TiffOutputSet outputSet)Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.voidupdateExifMetadataLossy(java.io.File src, java.io.OutputStream os, TiffOutputSet outputSet)Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.voidupdateExifMetadataLossy(java.io.InputStream src, java.io.OutputStream os, TiffOutputSet outputSet)Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.voidupdateExifMetadataLossy(ByteSource byteSource, java.io.OutputStream os, TiffOutputSet outputSet)Reads a JPEG image, replaces the EXIF metadata and writes the result to a stream.private byte[]writeExifSegment(AbstractTiffImageWriter writer, TiffOutputSet outputSet, boolean includeEXIFPrefix)private voidwriteSegmentsReplacingExif(java.io.OutputStream outputStream, java.util.List<ExifRewriter.JFIFPiece> segments, byte[] newBytes)-
Methods inherited from class org.apache.commons.imaging.common.BinaryFileParser
debugNumber, debugNumber, getByteOrder, setByteOrder
-
-
-
-
Constructor Detail
-
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(java.nio.ByteOrder byteOrder)
Constructs a new instance.- Parameters:
byteOrder- byte order of EXIF segment.
-
-
Method Detail
-
analyzeJfif
private ExifRewriter.JFIFPieces analyzeJfif(ByteSource byteSource) throws ImagingException, java.io.IOException
- Throws:
ImagingExceptionjava.io.IOException
-
removeExifMetadata
public void removeExifMetadata(byte[] src, java.io.OutputStream os) throws ImagingException, java.io.IOException, ImagingExceptionReads 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 segmentsjava.io.IOException- if it fails to read the image dataImagingException- if it fails to write the updated data
-
removeExifMetadata
public void removeExifMetadata(ByteSource byteSource, java.io.OutputStream os) throws ImagingException, java.io.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 segmentsjava.io.IOException- if it fails to read the image dataImagingException- if it fails to write the updated data
-
removeExifMetadata
public void removeExifMetadata(java.io.File src, java.io.OutputStream os) throws ImagingException, java.io.IOException, ImagingExceptionReads 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 segmentsjava.io.IOException- if it fails to read the image dataImagingException- if it fails to write the updated data- See Also:
File,OutputStream,File,OutputStream
-
removeExifMetadata
public void removeExifMetadata(java.io.InputStream src, java.io.OutputStream os) throws ImagingException, java.io.IOException, ImagingExceptionReads 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 segmentsjava.io.IOException- if it fails to read the image dataImagingException- if it fails to write the updated data
-
updateExifMetadataLossless
public void updateExifMetadataLossless(byte[] src, java.io.OutputStream os, TiffOutputSet outputSet) throws ImagingException, java.io.IOException, ImagingExceptionReads 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 segmentsjava.io.IOException- if it fails to read the image dataImagingException- if it fails to write the updated data
-
updateExifMetadataLossless
public void updateExifMetadataLossless(ByteSource byteSource, java.io.OutputStream os, TiffOutputSet outputSet) throws ImagingException, java.io.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 segmentsjava.io.IOException- if it fails to read the image dataImagingException- if it fails to write the updated data
-
updateExifMetadataLossless
public void updateExifMetadataLossless(java.io.File src, java.io.OutputStream os, TiffOutputSet outputSet) throws ImagingException, java.io.IOException, ImagingExceptionReads 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 segmentsjava.io.IOException- if it fails to read the image dataImagingException- if it fails to write the updated data
-
updateExifMetadataLossless
public void updateExifMetadataLossless(java.io.InputStream src, java.io.OutputStream os, TiffOutputSet outputSet) throws ImagingException, java.io.IOException, ImagingExceptionReads 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 segmentsjava.io.IOException- if it fails to read the image dataImagingException- if it fails to write the updated data
-
updateExifMetadataLossy
public void updateExifMetadataLossy(byte[] src, java.io.OutputStream os, TiffOutputSet outputSet) throws ImagingException, java.io.IOException, ImagingExceptionReads 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 segmentsjava.io.IOException- if it fails to read the image dataImagingException- if it fails to write the updated data
-
updateExifMetadataLossy
public void updateExifMetadataLossy(ByteSource byteSource, java.io.OutputStream os, TiffOutputSet outputSet) throws ImagingException, java.io.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 segmentsjava.io.IOException- if it fails to read the image dataImagingException- if it fails to write the updated data
-
updateExifMetadataLossy
public void updateExifMetadataLossy(java.io.File src, java.io.OutputStream os, TiffOutputSet outputSet) throws ImagingException, java.io.IOException, ImagingExceptionReads 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 segmentsjava.io.IOException- if it fails to read the image dataImagingException- if it fails to write the updated data
-
updateExifMetadataLossy
public void updateExifMetadataLossy(java.io.InputStream src, java.io.OutputStream os, TiffOutputSet outputSet) throws ImagingException, java.io.IOException, ImagingExceptionReads 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 segmentsjava.io.IOException- if it fails to read the image dataImagingException- if it fails to write the updated data
-
writeExifSegment
private byte[] writeExifSegment(AbstractTiffImageWriter writer, TiffOutputSet outputSet, boolean includeEXIFPrefix) throws java.io.IOException, ImagingException
- Throws:
java.io.IOExceptionImagingException
-
writeSegmentsReplacingExif
private void writeSegmentsReplacingExif(java.io.OutputStream outputStream, java.util.List<ExifRewriter.JFIFPiece> segments, byte[] newBytes) throws ImagingException, java.io.IOException- Throws:
ImagingExceptionjava.io.IOException
-
-