public void removeIptc(final ByteSource byteSource, final OutputStream os, final boolean removeSegment)
            throws ImagingException, IOException, ImagingException {
        final JFIFPieces jfifPieces = analyzeJfif(byteSource);
        final List<JFIFPiece> oldPieces = jfifPieces.pieces;
        final List<JFIFPiece> photoshopApp13Segments = findPhotoshopApp13Segments(oldPieces);

        if (photoshopApp13Segments.size() > 1) {
            throw new ImagingException("Image contains more than one Photoshop App13 segment.");
        }
        final List<JFIFPiece> newPieces = removePhotoshopApp13Segments(oldPieces);
        if (!removeSegment && photoshopApp13Segments.size() == 1) {
            final JFIFPieceSegment oldSegment = (JFIFPieceSegment) photoshopApp13Segments.get(0);
            final JpegImagingParameters params = new JpegImagingParameters();
            final PhotoshopApp13Data oldData = new IptcParser().parsePhotoshopSegment(oldSegment.getSegmentData(), params);
            final List<IptcBlock> newBlocks = oldData.getNonIptcBlocks();
            final List<IptcRecord> newRecords = new ArrayList<>();
            final PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords, newBlocks);
            final byte[] segmentBytes = new IptcParser().writePhotoshopApp13Segment(newData);
            final JFIFPieceSegment newSegment = new JFIFPieceSegment(oldSegment.marker, segmentBytes);
            newPieces.add(oldPieces.indexOf(oldSegment), newSegment);
        }
        writeSegments(os, newPieces);
    }
Reads a JPEG image, removes all IPTC data from the App13 segment but leaves the other data in that segment (if present) unchanged (unless removeSegment
is true) and writes the result to a stream.

@param byteSource    ByteSource containing JPEG image data.
@param os            OutputStream to write the image to.
@param removeSegment Remove the App13 segment.
@throws ImagingException if there are more than one Photoshop App13 segment, or if the Photoshop segment cannot be parsed
@throws IOException      if it fails to read from the origin byte source, or to write to the target byte source
@throws ImagingException if it fails to write the target image
src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/JpegIptcRewriter.java