Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A4B579DE7 for ; Sat, 26 May 2012 21:20:05 +0000 (UTC) Received: (qmail 57574 invoked by uid 500); 26 May 2012 21:20:04 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 57473 invoked by uid 500); 26 May 2012 21:20:04 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 57391 invoked by uid 99); 26 May 2012 21:20:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 May 2012 21:20:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 May 2012 21:19:59 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BE3E02388B71 for ; Sat, 26 May 2012 21:19:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1342971 [5/20] - in /commons/proper/imaging/trunk/src: main/java/org/apache/commons/imaging/formats/bmp/ main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/ main/java/org/apache/commons/imaging/formats/bmp/writers/ main/java/org... Date: Sat, 26 May 2012 21:19:22 -0000 To: commits@commons.apache.org From: damjan@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120526211939.BE3E02388B71@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java Sat May 26 21:19:03 2012 @@ -44,59 +44,57 @@ import org.apache.commons.imaging.util.D *

*

* See the source of the ExifMetadataUpdateExample class for example usage. - * - * @see org.apache.commons.imaging.examples.WriteExifMetadataExample + * + * @see org.apache.commons.imaging.examples.WriteExifMetadataExample */ -public class ExifRewriter extends BinaryFileParser implements JpegConstants -{ +public class ExifRewriter extends BinaryFileParser implements JpegConstants { /** - * Constructor. to guess whether a file contains an image based on its file extension. + * Constructor. to guess whether a file contains an image based on its file + * extension. */ - public ExifRewriter() - { + public ExifRewriter() { setByteOrder(BYTE_ORDER_NETWORK); } /** * Constructor. *

- * @param byteOrder byte order of EXIF segment. Optional. See BinaryConstants class. - * + * + * @param byteOrder + * byte order of EXIF segment. Optional. See BinaryConstants + * class. + * * @see org.apache.commons.imaging.common.BinaryConstants */ - public ExifRewriter(int byteOrder) - { + public ExifRewriter(int byteOrder) { setByteOrder(byteOrder); } - private static class JFIFPieces - { + private static class JFIFPieces { public final List pieces; public final List exifPieces; - public JFIFPieces(final List pieces, final List exifPieces) - { + public JFIFPieces(final List pieces, + final List exifPieces) { this.pieces = pieces; this.exifPieces = exifPieces; } } - private abstract static class JFIFPiece - { + private abstract static class JFIFPiece { protected abstract void write(OutputStream os) throws IOException; } - private static class JFIFPieceSegment extends JFIFPiece - { + private static class JFIFPieceSegment extends JFIFPiece { public final int marker; public final byte markerBytes[]; public final byte markerLengthBytes[]; public final byte segmentData[]; public JFIFPieceSegment(final int marker, final byte[] markerBytes, - final byte[] markerLengthBytes, final byte[] segmentData) - { + final byte[] markerLengthBytes, final byte[] segmentData) { this.marker = marker; this.markerBytes = markerBytes; this.markerLengthBytes = markerLengthBytes; @@ -104,40 +102,34 @@ public class ExifRewriter extends Binary } @Override - protected void write(OutputStream os) throws IOException - { + protected void write(OutputStream os) throws IOException { os.write(markerBytes); os.write(markerLengthBytes); os.write(segmentData); } } - private static class JFIFPieceSegmentExif extends JFIFPieceSegment - { + private static class JFIFPieceSegmentExif extends JFIFPieceSegment { public JFIFPieceSegmentExif(final int marker, final byte[] markerBytes, - final byte[] markerLengthBytes, final byte[] segmentData) - { + final byte[] markerLengthBytes, final byte[] segmentData) { super(marker, markerBytes, markerLengthBytes, segmentData); } } - private static class JFIFPieceImageData extends JFIFPiece - { + private static class JFIFPieceImageData extends JFIFPiece { public final byte markerBytes[]; public final byte imageData[]; public JFIFPieceImageData(final byte[] markerBytes, - final byte[] imageData) - { + final byte[] imageData) { super(); this.markerBytes = markerBytes; this.imageData = imageData; } @Override - protected void write(OutputStream os) throws IOException - { + protected void write(OutputStream os) throws IOException { os.write(markerBytes); os.write(imageData); } @@ -145,22 +137,19 @@ public class ExifRewriter extends Binary private JFIFPieces analyzeJFIF(ByteSource byteSource) throws ImageReadException, IOException - // , ImageWriteException + // , ImageWriteException { final List pieces = new ArrayList(); final List exifPieces = new ArrayList(); - JpegUtils.Visitor visitor = new JpegUtils.Visitor() - { + JpegUtils.Visitor visitor = new JpegUtils.Visitor() { // return false to exit before reading image data. - public boolean beginSOS() - { + public boolean beginSOS() { return true; } public void visitSOS(int marker, byte markerBytes[], - byte imageData[]) - { + byte imageData[]) { pieces.add(new JFIFPieceImageData(markerBytes, imageData)); } @@ -168,27 +157,23 @@ public class ExifRewriter extends Binary public boolean visitSegment(int marker, byte markerBytes[], int markerLength, byte markerLengthBytes[], byte segmentData[]) throws - // ImageWriteException, - ImageReadException, IOException - { - if (marker != JPEG_APP1_Marker) - { + // ImageWriteException, + ImageReadException, IOException { + if (marker != JPEG_APP1_Marker) { pieces.add(new JFIFPieceSegment(marker, markerBytes, markerLengthBytes, segmentData)); - } - else if (!byteArrayHasPrefix(segmentData, EXIF_IDENTIFIER_CODE)) - { + } else if (!byteArrayHasPrefix(segmentData, + EXIF_IDENTIFIER_CODE)) { pieces.add(new JFIFPieceSegment(marker, markerBytes, markerLengthBytes, segmentData)); } - // else if (exifSegmentArray[0] != null) - // { - // // TODO: add support for multiple segments - // throw new ImageReadException( - // "More than one APP1 EXIF segment."); - // } - else - { + // else if (exifSegmentArray[0] != null) + // { + // // TODO: add support for multiple segments + // throw new ImageReadException( + // "More than one APP1 EXIF segment."); + // } + else { JFIFPiece piece = new JFIFPieceSegmentExif(marker, markerBytes, markerLengthBytes, segmentData); pieces.add(piece); @@ -200,174 +185,201 @@ public class ExifRewriter extends Binary new JpegUtils().traverseJFIF(byteSource, visitor); - // GenericSegment exifSegment = exifSegmentArray[0]; - // if (exifSegments.size() < 1) - // { - // // TODO: add support for adding, not just replacing. - // throw new ImageReadException("No APP1 EXIF segment found."); - // } + // GenericSegment exifSegment = exifSegmentArray[0]; + // if (exifSegments.size() < 1) + // { + // // TODO: add support for adding, not just replacing. + // throw new ImageReadException("No APP1 EXIF segment found."); + // } return new JFIFPieces(pieces, exifPieces); } /** - * Reads a Jpeg image, removes all EXIF metadata (by removing the APP1 segment), - * and writes the result to a stream. + * Reads a Jpeg image, removes all EXIF metadata (by removing the APP1 + * segment), and writes the result to a stream. *

- * @param src Image file. - * @param os OutputStream to write the image to. - * + * + * @param src + * Image file. + * @param os + * OutputStream to write the image to. + * * @see java.io.File * @see java.io.OutputStream * @see java.io.File * @see java.io.OutputStream */ public void removeExifMetadata(File src, OutputStream os) - throws ImageReadException, IOException, ImageWriteException - { + throws ImageReadException, IOException, ImageWriteException { ByteSource byteSource = new ByteSourceFile(src); removeExifMetadata(byteSource, os); } /** - * Reads a Jpeg image, removes all EXIF metadata (by removing the APP1 segment), - * and writes the result to a stream. + * Reads a Jpeg image, removes all EXIF metadata (by removing the APP1 + * segment), and writes the result to a stream. *

- * @param src Byte array containing Jpeg image data. - * @param os OutputStream to write the image to. + * + * @param src + * Byte array containing Jpeg image data. + * @param os + * OutputStream to write the image to. */ public void removeExifMetadata(byte src[], OutputStream os) - throws ImageReadException, IOException, ImageWriteException - { + throws ImageReadException, IOException, ImageWriteException { ByteSource byteSource = new ByteSourceArray(src); removeExifMetadata(byteSource, os); } /** - * Reads a Jpeg image, removes all EXIF metadata (by removing the APP1 segment), - * and writes the result to a stream. + * Reads a Jpeg image, removes all EXIF metadata (by removing the APP1 + * segment), and writes the result to a stream. *

- * @param src InputStream containing Jpeg image data. - * @param os OutputStream to write the image to. + * + * @param src + * InputStream containing Jpeg image data. + * @param os + * OutputStream to write the image to. */ public void removeExifMetadata(InputStream src, OutputStream os) - throws ImageReadException, IOException, ImageWriteException - { + throws ImageReadException, IOException, ImageWriteException { ByteSource byteSource = new ByteSourceInputStream(src, null); removeExifMetadata(byteSource, os); } /** - * Reads a Jpeg image, removes all EXIF metadata (by removing the APP1 segment), - * and writes the result to a stream. + * Reads a Jpeg image, removes all EXIF metadata (by removing the APP1 + * segment), and writes the result to a stream. *

- * @param byteSource ByteSource containing Jpeg image data. - * @param os OutputStream to write the image to. + * + * @param byteSource + * ByteSource containing Jpeg image data. + * @param os + * OutputStream to write the image to. */ public void removeExifMetadata(ByteSource byteSource, OutputStream os) - throws ImageReadException, IOException, ImageWriteException - { + throws ImageReadException, IOException, ImageWriteException { JFIFPieces jfifPieces = analyzeJFIF(byteSource); List pieces = jfifPieces.pieces; - // Debug.debug("pieces", pieces); + // Debug.debug("pieces", pieces); - // pieces.removeAll(jfifPieces.exifSegments); + // pieces.removeAll(jfifPieces.exifSegments); - // Debug.debug("pieces", pieces); + // Debug.debug("pieces", pieces); writeSegmentsReplacingExif(os, pieces, null); } /** - * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a stream. + * 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. - *

- * @param src Image file. - * @param os OutputStream to write the image to. - * @param outputSet TiffOutputSet containing the EXIF data to write. + * 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. + *

+ * + * @param src + * Image file. + * @param os + * OutputStream to write the image to. + * @param outputSet + * TiffOutputSet containing the EXIF data to write. */ public void updateExifMetadataLossless(File src, OutputStream os, TiffOutputSet outputSet) throws ImageReadException, IOException, - ImageWriteException - { + ImageWriteException { ByteSource byteSource = new ByteSourceFile(src); updateExifMetadataLossless(byteSource, os, outputSet); } /** - * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a stream. + * 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. - *

- * @param src Byte array containing Jpeg image data. - * @param os OutputStream to write the image to. - * @param outputSet TiffOutputSet containing the EXIF data to write. + * 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. + *

+ * + * @param src + * Byte array containing Jpeg image data. + * @param os + * OutputStream to write the image to. + * @param outputSet + * TiffOutputSet containing the EXIF data to write. */ public void updateExifMetadataLossless(byte src[], OutputStream os, TiffOutputSet outputSet) throws ImageReadException, IOException, - ImageWriteException - { + ImageWriteException { ByteSource byteSource = new ByteSourceArray(src); updateExifMetadataLossless(byteSource, os, outputSet); } /** - * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a stream. + * 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. - *

- * @param src InputStream containing Jpeg image data. - * @param os OutputStream to write the image to. - * @param outputSet TiffOutputSet containing the EXIF data to write. + * 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. + *

+ * + * @param src + * InputStream containing Jpeg image data. + * @param os + * OutputStream to write the image to. + * @param outputSet + * TiffOutputSet containing the EXIF data to write. */ public void updateExifMetadataLossless(InputStream src, OutputStream os, TiffOutputSet outputSet) throws ImageReadException, IOException, - ImageWriteException - { + ImageWriteException { ByteSource byteSource = new ByteSourceInputStream(src, null); updateExifMetadataLossless(byteSource, os, outputSet); } /** - * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a stream. + * 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. - *

- * @param byteSource ByteSource containing Jpeg image data. - * @param os OutputStream to write the image to. - * @param outputSet TiffOutputSet containing the EXIF data to write. + * 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. + *

+ * + * @param byteSource + * ByteSource containing Jpeg image data. + * @param os + * OutputStream to write the image to. + * @param outputSet + * TiffOutputSet containing the EXIF data to write. */ public void updateExifMetadataLossless(ByteSource byteSource, OutputStream os, TiffOutputSet outputSet) - throws ImageReadException, IOException, ImageWriteException - { - // List outputDirectories = outputSet.getDirectories(); + throws ImageReadException, IOException, ImageWriteException { + // List outputDirectories = outputSet.getDirectories(); JFIFPieces jfifPieces = analyzeJFIF(byteSource); List pieces = jfifPieces.pieces; TiffImageWriterBase writer; // Just use first APP1 segment for now. // Multiple APP1 segments are rare and poorly supported. - if (jfifPieces.exifPieces.size() > 0) - { + if (jfifPieces.exifPieces.size() > 0) { JFIFPieceSegment exifPiece = null; exifPiece = (JFIFPieceSegment) jfifPieces.exifPieces.get(0); @@ -376,8 +388,7 @@ public class ExifRewriter extends Binary writer = new TiffImageWriterLossless(outputSet.byteOrder, exifBytes); - } - else + } else writer = new TiffImageWriterLossy(outputSet.byteOrder); boolean includeEXIFPrefix = true; @@ -387,73 +398,93 @@ public class ExifRewriter extends Binary } /** - * 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). + * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a + * stream. *

- * @param src Byte array containing Jpeg image data. - * @param os OutputStream to write the image to. - * @param outputSet TiffOutputSet containing the EXIF data to write. + * 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). + *

+ * + * @param src + * Byte array containing Jpeg image data. + * @param os + * OutputStream to write the image to. + * @param outputSet + * TiffOutputSet containing the EXIF data to write. */ public void updateExifMetadataLossy(byte src[], OutputStream os, TiffOutputSet outputSet) throws ImageReadException, IOException, - ImageWriteException - { + ImageWriteException { ByteSource byteSource = new ByteSourceArray(src); updateExifMetadataLossy(byteSource, os, outputSet); } /** - * 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). + * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a + * stream. *

- * @param src InputStream containing Jpeg image data. - * @param os OutputStream to write the image to. - * @param outputSet TiffOutputSet containing the EXIF data to write. + * 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). + *

+ * + * @param src + * InputStream containing Jpeg image data. + * @param os + * OutputStream to write the image to. + * @param outputSet + * TiffOutputSet containing the EXIF data to write. */ public void updateExifMetadataLossy(InputStream src, OutputStream os, TiffOutputSet outputSet) throws ImageReadException, IOException, - ImageWriteException - { + ImageWriteException { ByteSource byteSource = new ByteSourceInputStream(src, null); updateExifMetadataLossy(byteSource, os, outputSet); } /** - * 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). + * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a + * stream. *

- * @param src Image file. - * @param os OutputStream to write the image to. - * @param outputSet TiffOutputSet containing the EXIF data to write. + * 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). + *

+ * + * @param src + * Image file. + * @param os + * OutputStream to write the image to. + * @param outputSet + * TiffOutputSet containing the EXIF data to write. */ public void updateExifMetadataLossy(File src, OutputStream os, TiffOutputSet outputSet) throws ImageReadException, IOException, - ImageWriteException - { + ImageWriteException { ByteSource byteSource = new ByteSourceFile(src); updateExifMetadataLossy(byteSource, os, outputSet); } /** - * 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). + * Reads a Jpeg image, replaces the EXIF metadata and writes the result to a + * stream. *

- * @param byteSource ByteSource containing Jpeg image data. - * @param os OutputStream to write the image to. - * @param outputSet TiffOutputSet containing the EXIF data to write. + * 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). + *

+ * + * @param byteSource + * ByteSource containing Jpeg image data. + * @param os + * OutputStream to write the image to. + * @param outputSet + * TiffOutputSet containing the EXIF data to write. */ public void updateExifMetadataLossy(ByteSource byteSource, OutputStream os, TiffOutputSet outputSet) throws ImageReadException, IOException, - ImageWriteException - { + ImageWriteException { JFIFPieces jfifPieces = analyzeJFIF(byteSource); List pieces = jfifPieces.pieces; @@ -466,26 +497,23 @@ public class ExifRewriter extends Binary writeSegmentsReplacingExif(os, pieces, newBytes); } - private void writeSegmentsReplacingExif(OutputStream os, List segments, - byte newBytes[]) throws ImageWriteException, IOException - { + private void writeSegmentsReplacingExif(OutputStream os, + List segments, byte newBytes[]) + throws ImageWriteException, IOException { int byteOrder = getByteOrder(); - try - { + try { SOI.writeTo(os); boolean hasExif = false; - for (int i = 0; i < segments.size(); i++) - { + for (int i = 0; i < segments.size(); i++) { JFIFPiece piece = segments.get(i); if (piece instanceof JFIFPieceSegmentExif) hasExif = true; } - if (!hasExif && newBytes != null) - { + if (!hasExif && newBytes != null) { byte markerBytes[] = convertShortToByteArray(JPEG_APP1_Marker, byteOrder); if (newBytes.length > 0xffff) @@ -506,11 +534,9 @@ public class ExifRewriter extends Binary boolean APP1Written = false; - for (int i = 0; i < segments.size(); i++) - { + for (int i = 0; i < segments.size(); i++) { JFIFPiece piece = segments.get(i); - if (piece instanceof JFIFPieceSegmentExif) - { + if (piece instanceof JFIFPieceSegmentExif) { // only replace first APP1 segment; skips others. if (APP1Written) continue; @@ -531,42 +557,31 @@ public class ExifRewriter extends Binary os.write(markerBytes); os.write(markerLengthBytes); os.write(newBytes); - } - else - { + } else { piece.write(os); } } - } - finally - { - try - { + } finally { + try { os.close(); - } - catch (Exception e) - { + } catch (Exception e) { Debug.debug(e); } } } - public static class ExifOverflowException extends ImageWriteException - { - public ExifOverflowException(String s) - { + public static class ExifOverflowException extends ImageWriteException { + public ExifOverflowException(String s) { super(s); } } private byte[] writeExifSegment(TiffImageWriterBase writer, TiffOutputSet outputSet, boolean includeEXIFPrefix) - throws IOException, ImageWriteException - { + throws IOException, ImageWriteException { ByteArrayOutputStream os = new ByteArrayOutputStream(); - if (includeEXIFPrefix) - { + if (includeEXIFPrefix) { EXIF_IDENTIFIER_CODE.writeTo(os); os.write(0); os.write(0); @@ -577,4 +592,4 @@ public class ExifRewriter extends Binary return os.toByteArray(); } -} \ No newline at end of file +} Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcBlock.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcBlock.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcBlock.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcBlock.java Sat May 26 21:19:03 2012 @@ -19,21 +19,18 @@ package org.apache.commons.imaging.forma /* * Represents an IPTC block, a set of key-value pairs of Photoshop IPTC data. */ -public class IptcBlock -{ +public class IptcBlock { public final int blockType; public final byte[] blockNameBytes; public final byte[] blockData; - public IptcBlock(int blockType, byte[] blockNameBytes, byte[] blockData) - { + public IptcBlock(int blockType, byte[] blockNameBytes, byte[] blockData) { this.blockData = blockData; this.blockNameBytes = blockNameBytes; this.blockType = blockType; } - public boolean isIPTCBlock() - { + public boolean isIPTCBlock() { return blockType == IptcParser.IMAGE_RESOURCE_BLOCK_IPTC_DATA; } -} \ No newline at end of file +} Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcConstants.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcConstants.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcConstants.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcConstants.java Sat May 26 21:19:03 2012 @@ -18,8 +18,7 @@ package org.apache.commons.imaging.forma import org.apache.commons.imaging.formats.jpeg.JpegConstants; -public interface IptcConstants extends JpegConstants -{ +public interface IptcConstants extends JpegConstants { public static final int IPTC_NON_EXTENDED_RECORD_MAXIMUM_SIZE = 32767; public static final int IMAGE_RESOURCE_BLOCK_PHOTOSHOP2_INFO = 0x03e8; Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java Sat May 26 21:19:03 2012 @@ -34,18 +34,16 @@ import org.apache.commons.imaging.common import org.apache.commons.imaging.util.Debug; import org.apache.commons.imaging.util.ParamMap; -public class IptcParser extends BinaryFileParser implements IptcConstants -{ +public class IptcParser extends BinaryFileParser implements IptcConstants { private static final int APP13_BYTE_ORDER = BYTE_ORDER_NETWORK; - public IptcParser() - { + public IptcParser() { setByteOrder(BYTE_ORDER_NETWORK); } - public boolean isPhotoshopJpegSegment(byte segmentData[]) - { - if (!BinaryFileParser.byteArrayHasPrefix(segmentData, PHOTOSHOP_IDENTIFICATION_STRING)) + public boolean isPhotoshopJpegSegment(byte segmentData[]) { + if (!BinaryFileParser.byteArrayHasPrefix(segmentData, + PHOTOSHOP_IDENTIFICATION_STRING)) return false; int index = PHOTOSHOP_IDENTIFICATION_STRING.size(); @@ -62,42 +60,41 @@ public class IptcParser extends BinaryFi * In practice, App13 segments are only used for Photoshop/IPTC metadata. * However, we should not treat App13 signatures without Photoshop's * signature as Photoshop/IPTC segments. - * + * * A Photoshop/IPTC App13 segment begins with the Photoshop Identification * string. - * + * * There follows 0-N blocks (Photoshop calls them "Image Resource Blocks"). - * + * * Each block has the following structure: - * + * * 1. 4-byte type. This is always "8BIM" for blocks in a Photoshop App13 * segment. 2. 2-byte id. IPTC data is stored in blocks with id 0x0404, aka. * IPTC_NAA_RECORD_IMAGE_RESOURCE_ID 3. Block name as a Pascal String. This * is padded to have an even length. 4. 4-byte size (in bytes). 5. Block * data. This is also padded to have an even length. - * + * * The block data consists of a 0-N records. A record has the following * structure: - * + * * 1. 2-byte prefix. The value is always 0x1C02 2. 1-byte record type. The * record types are documented by the IPTC. See IptcConstants. 3. 2-byte * record size (in bytes). 4. Record data, "record size" bytes long. - * + * * Record data (unlike block data) is NOT padded to have an even length. - * - * Record data, for IPTC record, should always be ISO-8859-1. - * But according to SANSELAN-33, this isn't always the case. - * + * + * Record data, for IPTC record, should always be ISO-8859-1. But according + * to SANSELAN-33, this isn't always the case. + * * The exception is the first record in the block, which must always be a * record version record, whose value is a two-byte number; the value is * 0x02. - * + * * Some IPTC blocks are missing this first "record version" record, so we * don't require it. */ public PhotoshopApp13Data parsePhotoshopSegment(byte bytes[], Map params) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { boolean strict = ParamMap.getParamBoolean(params, ImagingConstants.PARAM_KEY_STRICT, false); boolean verbose = ParamMap.getParamBoolean(params, @@ -108,14 +105,12 @@ public class IptcParser extends BinaryFi public PhotoshopApp13Data parsePhotoshopSegment(byte bytes[], boolean verbose, boolean strict) throws ImageReadException, - IOException - { + IOException { List records = new ArrayList(); List allBlocks = parseAllBlocks(bytes, verbose, strict); - for (int i = 0; i < allBlocks.size(); i++) - { + for (int i = 0; i < allBlocks.size(); i++) { IptcBlock block = allBlocks.get(i); // Ignore everything but IPTC data. @@ -129,21 +124,19 @@ public class IptcParser extends BinaryFi } protected List parseIPTCBlock(byte bytes[], boolean verbose) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { List elements = new ArrayList(); int index = 0; // Integer recordVersion = null; - while (index + 1 < bytes.length) - { + while (index + 1 < bytes.length) { int tagMarker = 0xff & bytes[index++]; if (verbose) - Debug.debug("tagMarker", tagMarker + " (0x" - + Integer.toHexString(tagMarker) + ")"); + Debug.debug("tagMarker", + tagMarker + " (0x" + Integer.toHexString(tagMarker) + + ")"); - if (tagMarker != IPTC_RECORD_TAG_MARKER) - { + if (tagMarker != IPTC_RECORD_TAG_MARKER) { if (verbose) System.out .println("Unexpected record tag marker in IPTC data."); @@ -152,8 +145,10 @@ public class IptcParser extends BinaryFi int recordNumber = 0xff & bytes[index++]; if (verbose) - Debug.debug("recordNumber", recordNumber + " (0x" - + Integer.toHexString(recordNumber) + ")"); + Debug.debug( + "recordNumber", + recordNumber + " (0x" + + Integer.toHexString(recordNumber) + ")"); // int recordPrefix = convertByteArrayToShort("recordPrefix", index, // bytes); @@ -175,8 +170,9 @@ public class IptcParser extends BinaryFi int recordType = 0xff & bytes[index]; if (verbose) - Debug.debug("recordType", recordType + " (0x" - + Integer.toHexString(recordType) + ")"); + Debug.debug("recordType", + recordType + " (0x" + Integer.toHexString(recordType) + + ")"); index++; int recordSize = convertByteArrayToShort("recordSize", index, bytes); @@ -197,12 +193,11 @@ public class IptcParser extends BinaryFi // Debug.debug("recordSize", recordSize + " (0x" // + Integer.toHexString(recordSize) + ")"); - + if (recordNumber != IPTC_APPLICATION_2_RECORD_NUMBER) continue; - if (recordType == 0) - { + if (recordType == 0) { if (verbose) System.out.println("ignore record version record! " + elements.size()); @@ -255,9 +250,8 @@ public class IptcParser extends BinaryFi return elements; } - protected List parseAllBlocks(byte bytes[], boolean verbose, boolean strict) - throws ImageReadException, IOException - { + protected List parseAllBlocks(byte bytes[], boolean verbose, + boolean strict) throws ImageReadException, IOException { List blocks = new ArrayList(); BinaryInputStream bis = new BinaryInputStream(bytes, APP13_BYTE_ORDER); @@ -273,8 +267,7 @@ public class IptcParser extends BinaryFi // int index = PHOTOSHOP_IDENTIFICATION_STRING.length; - while (true) - { + while (true) { byte[] imageResourceBlockSignature = bis .readByteArray(CONST_8BIM.size(), "App13 Segment missing identification string", @@ -288,8 +281,9 @@ public class IptcParser extends BinaryFi int blockType = bis .read2ByteInteger("Image Resource Block missing type"); if (verbose) - Debug.debug("blockType", blockType + " (0x" - + Integer.toHexString(blockType) + ")"); + Debug.debug("blockType", + blockType + " (0x" + Integer.toHexString(blockType) + + ")"); int blockNameLength = bis .read1ByteInteger("Image Resource Block missing name length"); @@ -297,34 +291,33 @@ public class IptcParser extends BinaryFi Debug.debug("blockNameLength", blockNameLength + " (0x" + Integer.toHexString(blockNameLength) + ")"); byte[] blockNameBytes; - if (blockNameLength == 0) - { + if (blockNameLength == 0) { bis.read1ByteInteger("Image Resource Block has invalid name"); blockNameBytes = new byte[0]; - } else - { + } else { blockNameBytes = bis.readByteArray(blockNameLength, "Invalid Image Resource Block name", verbose, strict); if (null == blockNameBytes) break; if (blockNameLength % 2 == 0) - bis - .read1ByteInteger("Image Resource Block missing padding byte"); + bis.read1ByteInteger("Image Resource Block missing padding byte"); } int blockSize = bis .read4ByteInteger("Image Resource Block missing size"); if (verbose) - Debug.debug("blockSize", blockSize + " (0x" - + Integer.toHexString(blockSize) + ")"); + Debug.debug("blockSize", + blockSize + " (0x" + Integer.toHexString(blockSize) + + ")"); /* - * doesn't catch cases where blocksize is invalid but is still less than bytes.length - * but will at least prevent OutOfMemory errors + * doesn't catch cases where blocksize is invalid but is still less + * than bytes.length but will at least prevent OutOfMemory errors */ - if(blockSize > bytes.length) { - throw new ImageReadException("Invalid Block Size : "+blockSize+ " > "+bytes.length); + if (blockSize > bytes.length) { + throw new ImageReadException("Invalid Block Size : " + + blockSize + " > " + bytes.length); } byte[] blockData = bis.readByteArray(blockSize, @@ -335,8 +328,7 @@ public class IptcParser extends BinaryFi blocks.add(new IptcBlock(blockType, blockNameBytes, blockData)); if ((blockSize % 2) != 0) - bis - .read1ByteInteger("Image Resource Block missing padding byte"); + bis.read1ByteInteger("Image Resource Block missing padding byte"); } return blocks; @@ -345,16 +337,14 @@ public class IptcParser extends BinaryFi // private void writeIPTCRecord(BinaryOutputStream bos, ) public byte[] writePhotoshopApp13Segment(PhotoshopApp13Data data) - throws IOException, ImageWriteException - { + throws IOException, ImageWriteException { ByteArrayOutputStream os = new ByteArrayOutputStream(); BinaryOutputStream bos = new BinaryOutputStream(os); PHOTOSHOP_IDENTIFICATION_STRING.writeTo(bos); List blocks = data.getRawBlocks(); - for (int i = 0; i < blocks.size(); i++) - { + for (int i = 0; i < blocks.size(); i++) { IptcBlock block = blocks.get(i); CONST_8BIM.writeTo(bos); @@ -385,9 +375,8 @@ public class IptcParser extends BinaryFi return os.toByteArray(); } - public byte[] writeIPTCBlock(List elements) throws ImageWriteException, - IOException - { + public byte[] writeIPTCBlock(List elements) + throws ImageWriteException, IOException { byte blockData[]; { ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -398,7 +387,7 @@ public class IptcParser extends BinaryFi bos.write(IPTC_RECORD_TAG_MARKER); bos.write(IPTC_APPLICATION_2_RECORD_NUMBER); bos.write(IptcTypes.RECORD_VERSION.type); // record version record - // type. + // type. bos.write2Bytes(2); // record version record size bos.write2Bytes(2); // record version value @@ -407,8 +396,7 @@ public class IptcParser extends BinaryFi // sort the list. Records must be in numerical order. Comparator comparator = new Comparator() { - public int compare(IptcRecord e1, IptcRecord e2) - { + public int compare(IptcRecord e1, IptcRecord e2) { return e2.iptcType.getType() - e1.iptcType.getType(); } }; @@ -416,8 +404,7 @@ public class IptcParser extends BinaryFi // TODO: make sure order right // write the list. - for (int i = 0; i < elements.size(); i++) - { + for (int i = 0; i < elements.size(); i++) { IptcRecord element = elements.get(i); if (element.iptcType == IptcTypes.RECORD_VERSION) @@ -425,7 +412,8 @@ public class IptcParser extends BinaryFi bos.write(IPTC_RECORD_TAG_MARKER); bos.write(IPTC_APPLICATION_2_RECORD_NUMBER); - if (element.iptcType.getType() < 0 || element.iptcType.getType() > 0xff) + if (element.iptcType.getType() < 0 + || element.iptcType.getType() > 0xff) throw new ImageWriteException("Invalid record type: " + element.iptcType.getType()); bos.write(element.iptcType.getType()); Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcRecord.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcRecord.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcRecord.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcRecord.java Sat May 26 21:19:03 2012 @@ -22,21 +22,18 @@ import java.util.Comparator; /* * Represents an IPTC record, a single key-value pair of Photoshop IPTC data. */ -public class IptcRecord -{ +public class IptcRecord { public final IptcType iptcType; private final byte[] bytes; public final String value; - public IptcRecord(IptcType iptcType, byte[] bytes, String value) - { + public IptcRecord(IptcType iptcType, byte[] bytes, String value) { this.iptcType = iptcType; this.bytes = bytes; this.value = value; } - - public IptcRecord(IptcType iptcType, String value) - { + + public IptcRecord(IptcType iptcType, String value) { this.iptcType = iptcType; byte[] bytes; try { @@ -47,26 +44,23 @@ public class IptcRecord this.bytes = bytes; this.value = value; } - + public byte[] getRawBytes() { return bytes.clone(); } - public String getValue() - { + public String getValue() { return value; } - public String getIptcTypeName() - { + public String getIptcTypeName() { return iptcType.getName(); } public static final Comparator COMPARATOR = new Comparator() { - public int compare(IptcRecord e1, IptcRecord e2) - { + public int compare(IptcRecord e1, IptcRecord e2) { return e1.iptcType.getType() - e2.iptcType.getType(); } }; -} \ No newline at end of file +} Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcType.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcType.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcType.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcType.java Sat May 26 21:19:03 2012 @@ -16,10 +16,10 @@ */ package org.apache.commons.imaging.formats.jpeg.iptc; - -public interface IptcType -{ +public interface IptcType { public int getType(); + public String getName(); + public String toString(); -} \ No newline at end of file +} Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcTypeLookup.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcTypeLookup.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcTypeLookup.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcTypeLookup.java Sat May 26 21:19:03 2012 @@ -19,22 +19,18 @@ package org.apache.commons.imaging.forma import java.util.HashMap; import java.util.Map; -public abstract class IptcTypeLookup implements IptcConstants -{ +public abstract class IptcTypeLookup implements IptcConstants { private static final Map IPTC_TYPE_MAP = new HashMap(); - static - { - for (IptcType iptcType : IptcTypes.values()) - { + static { + for (IptcType iptcType : IptcTypes.values()) { IPTC_TYPE_MAP.put(iptcType.getType(), iptcType); } } - public static final IptcType getIptcType(int type) - { + public static final IptcType getIptcType(int type) { if (!IPTC_TYPE_MAP.containsKey(type)) return IptcTypes.getUnknown(type); return IPTC_TYPE_MAP.get(type); } -} \ No newline at end of file +} Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcTypes.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcTypes.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcTypes.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcTypes.java Sat May 26 21:19:03 2012 @@ -135,8 +135,7 @@ public enum IptcTypes implements IptcTyp public final int type; public final String name; - IptcTypes(int type, String name) - { + IptcTypes(int type, String name) { this.type = type; this.name = name; } @@ -150,8 +149,7 @@ public enum IptcTypes implements IptcTyp } @Override - public String toString() - { + public String toString() { return name + " (" + type + ")"; } Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/JpegIptcRewriter.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/JpegIptcRewriter.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/JpegIptcRewriter.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/JpegIptcRewriter.java Sat May 26 21:19:03 2012 @@ -37,26 +37,24 @@ import org.apache.commons.imaging.format /** * Interface for Exif write/update/remove functionality for Jpeg/JFIF images. */ -public class JpegIptcRewriter extends JpegRewriter implements IptcConstants -{ +public class JpegIptcRewriter extends JpegRewriter implements IptcConstants { /** * Reads a Jpeg image, removes all IPTC data from the App13 segment but * leaves the other data in that segment (if present) unchanged and writes * the result to a stream. *

- * + * * @param src * Image file. * @param os * OutputStream to write the image to. - * + * * @see java.io.File * @see java.io.OutputStream */ public void removeIPTC(File src, OutputStream os) - throws ImageReadException, IOException, ImageWriteException - { + throws ImageReadException, IOException, ImageWriteException { ByteSource byteSource = new ByteSourceFile(src); removeIPTC(byteSource, os); } @@ -66,15 +64,14 @@ public class JpegIptcRewriter extends Jp * leaves the other data in that segment (if present) unchanged and writes * the result to a stream. *

- * + * * @param src * Byte array containing Jpeg image data. * @param os * OutputStream to write the image to. */ public void removeIPTC(byte src[], OutputStream os) - throws ImageReadException, IOException, ImageWriteException - { + throws ImageReadException, IOException, ImageWriteException { ByteSource byteSource = new ByteSourceArray(src); removeIPTC(byteSource, os); } @@ -84,15 +81,14 @@ public class JpegIptcRewriter extends Jp * leaves the other data in that segment (if present) unchanged and writes * the result to a stream. *

- * + * * @param src * InputStream containing Jpeg image data. * @param os * OutputStream to write the image to. */ public void removeIPTC(InputStream src, OutputStream os) - throws ImageReadException, IOException, ImageWriteException - { + throws ImageReadException, IOException, ImageWriteException { ByteSource byteSource = new ByteSourceInputStream(src, null); removeIPTC(byteSource, os); } @@ -102,15 +98,14 @@ public class JpegIptcRewriter extends Jp * leaves the other data in that segment (if present) unchanged and writes * the result to a stream. *

- * + * * @param byteSource * ByteSource containing Jpeg image data. * @param os * OutputStream to write the image to. */ public void removeIPTC(ByteSource byteSource, OutputStream os) - throws ImageReadException, IOException, ImageWriteException - { + throws ImageReadException, IOException, ImageWriteException { JFIFPieces jfifPieces = analyzeJFIF(byteSource); List oldPieces = jfifPieces.pieces; List photoshopApp13Segments = findPhotoshopApp13Segments(oldPieces); @@ -119,8 +114,7 @@ public class JpegIptcRewriter extends Jp throw new ImageReadException( "Image contains more than one Photoshop App13 segment."); List newPieces = removePhotoshopApp13Segments(oldPieces); - if (photoshopApp13Segments.size() == 1) - { + if (photoshopApp13Segments.size() == 1) { JFIFPieceSegment oldSegment = (JFIFPieceSegment) photoshopApp13Segments .get(0); Map params = new HashMap(); @@ -143,7 +137,7 @@ public class JpegIptcRewriter extends Jp * Reads a Jpeg image, replaces the IPTC data in the App13 segment but * leaves the other data in that segment (if present) unchanged and writes * the result to a stream. - * + * * @param src * Byte array containing Jpeg image data. * @param os @@ -153,8 +147,7 @@ public class JpegIptcRewriter extends Jp */ public void writeIPTC(byte src[], OutputStream os, PhotoshopApp13Data newData) throws ImageReadException, IOException, - ImageWriteException - { + ImageWriteException { ByteSource byteSource = new ByteSourceArray(src); writeIPTC(byteSource, os, newData); } @@ -163,7 +156,7 @@ public class JpegIptcRewriter extends Jp * Reads a Jpeg image, replaces the IPTC data in the App13 segment but * leaves the other data in that segment (if present) unchanged and writes * the result to a stream. - * + * * @param src * InputStream containing Jpeg image data. * @param os @@ -173,8 +166,7 @@ public class JpegIptcRewriter extends Jp */ public void writeIPTC(InputStream src, OutputStream os, PhotoshopApp13Data newData) throws ImageReadException, IOException, - ImageWriteException - { + ImageWriteException { ByteSource byteSource = new ByteSourceInputStream(src, null); writeIPTC(byteSource, os, newData); } @@ -183,7 +175,7 @@ public class JpegIptcRewriter extends Jp * Reads a Jpeg image, replaces the IPTC data in the App13 segment but * leaves the other data in that segment (if present) unchanged and writes * the result to a stream. - * + * * @param src * Image file. * @param os @@ -192,8 +184,7 @@ public class JpegIptcRewriter extends Jp * structure containing IPTC data. */ public void writeIPTC(File src, OutputStream os, PhotoshopApp13Data newData) - throws ImageReadException, IOException, ImageWriteException - { + throws ImageReadException, IOException, ImageWriteException { ByteSource byteSource = new ByteSourceFile(src); writeIPTC(byteSource, os, newData); } @@ -202,7 +193,7 @@ public class JpegIptcRewriter extends Jp * Reads a Jpeg image, replaces the IPTC data in the App13 segment but * leaves the other data in that segment (if present) unchanged and writes * the result to a stream. - * + * * @param byteSource * ByteSource containing Jpeg image data. * @param os @@ -212,8 +203,7 @@ public class JpegIptcRewriter extends Jp */ public void writeIPTC(ByteSource byteSource, OutputStream os, PhotoshopApp13Data newData) throws ImageReadException, IOException, - ImageWriteException - { + ImageWriteException { JFIFPieces jfifPieces = analyzeJFIF(byteSource); List oldPieces = jfifPieces.pieces; List photoshopApp13Segments = findPhotoshopApp13Segments(oldPieces); @@ -242,11 +232,11 @@ public class JpegIptcRewriter extends Jp JFIFPieceSegment newSegment = new JFIFPieceSegment( JPEG_APP13_Marker, segmentBytes); - newPieces = insertAfterLastAppSegments(newPieces, Arrays - .asList(new JFIFPieceSegment[] { newSegment, })); + newPieces = insertAfterLastAppSegments(newPieces, + Arrays.asList(new JFIFPieceSegment[] { newSegment, })); } writeSegments(os, newPieces); } -} \ No newline at end of file +} Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/PhotoshopApp13Data.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/PhotoshopApp13Data.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/PhotoshopApp13Data.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/PhotoshopApp13Data.java Sat May 26 21:19:03 2012 @@ -20,32 +20,27 @@ package org.apache.commons.imaging.forma import java.util.ArrayList; import java.util.List; -public class PhotoshopApp13Data implements IptcConstants -{ +public class PhotoshopApp13Data implements IptcConstants { private final List records; private final List rawBlocks; - public PhotoshopApp13Data(List records, List rawBlocks) - { + public PhotoshopApp13Data(List records, + List rawBlocks) { this.rawBlocks = rawBlocks; this.records = records; } - public List getRecords() - { + public List getRecords() { return new ArrayList(records); } - public List getRawBlocks() - { + public List getRawBlocks() { return new ArrayList(rawBlocks); } - public List getNonIptcBlocks() - { + public List getNonIptcBlocks() { List result = new ArrayList(); - for (int i = 0; i < rawBlocks.size(); i++) - { + for (int i = 0; i < rawBlocks.size(); i++) { IptcBlock block = rawBlocks.get(i); if (!block.isIPTCBlock()) result.add(block); Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App13Segment.java Sat May 26 21:19:03 2012 @@ -26,23 +26,20 @@ import org.apache.commons.imaging.format import org.apache.commons.imaging.formats.jpeg.iptc.IptcParser; import org.apache.commons.imaging.formats.jpeg.iptc.PhotoshopApp13Data; -public class App13Segment extends AppnSegment -{ +public class App13Segment extends AppnSegment { protected final JpegImageParser parser; // public final List elements = new ArrayList(); // public final boolean isIPTCJpegSegment; public App13Segment(JpegImageParser parser, int marker, byte segmentData[]) - throws IOException - { + throws IOException { this(parser, marker, segmentData.length, new ByteArrayInputStream( segmentData)); } public App13Segment(JpegImageParser parser, int marker, int marker_length, - InputStream is) throws IOException - { + InputStream is) throws IOException { super(marker, marker_length, is); this.parser = parser; @@ -61,14 +58,12 @@ public class App13Segment extends AppnSe // } } - public boolean isPhotoshopJpegSegment() - { + public boolean isPhotoshopJpegSegment() { return new IptcParser().isPhotoshopJpegSegment(bytes); } public PhotoshopApp13Data parsePhotoshopSegment(Map params) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { /* * In practice, App13 segments are only used for Photoshop/IPTC * metadata. However, we should not treat App13 signatures without @@ -79,4 +74,4 @@ public class App13Segment extends AppnSe return new IptcParser().parsePhotoshopSegment(bytes, params); } -} \ No newline at end of file +} Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App2Segment.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App2Segment.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App2Segment.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/App2Segment.java Sat May 26 21:19:03 2012 @@ -24,24 +24,21 @@ import org.apache.commons.imaging.ImageR import org.apache.commons.imaging.common.BinaryFileParser; import org.apache.commons.imaging.formats.jpeg.JpegImageParser; -public class App2Segment extends AppnSegment implements Comparable -{ +public class App2Segment extends AppnSegment implements Comparable { public final byte icc_bytes[]; public final int cur_marker, num_markers; public App2Segment(int marker, byte segmentData[]) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { this(marker, segmentData.length, new ByteArrayInputStream(segmentData)); } public App2Segment(int marker, int marker_length, InputStream is2) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { super(marker, marker_length, is2); - if (BinaryFileParser.byteArrayHasPrefix(bytes, JpegImageParser.icc_profile_label)) - { + if (BinaryFileParser.byteArrayHasPrefix(bytes, + JpegImageParser.icc_profile_label)) { InputStream is = new ByteArrayInputStream(bytes); readAndVerifyBytes(is, JpegImageParser.icc_profile_label, @@ -55,39 +52,36 @@ public class App2Segment extends AppnSeg icc_bytes = readByteArray("App2 Data", marker_length, is, "Invalid App2 Segment: insufficient data"); - } - else - { - // debugByteArray("Unknown APP2 Segment Type", bytes); + } else { + // debugByteArray("Unknown APP2 Segment Type", bytes); cur_marker = -1; num_markers = -1; icc_bytes = null; } } - + @Override public boolean equals(Object obj) { if (obj instanceof App2Segment) { - App2Segment other = (App2Segment)obj; + App2Segment other = (App2Segment) obj; return cur_marker == other.cur_marker; } return false; } - + @Override public int hashCode() { return cur_marker; } - public int compareTo(App2Segment other) - { + public int compareTo(App2Segment other) { return cur_marker - other.cur_marker; } - // public String getDescription() - // { - // return "APPN (APP" - // + (marker - JpegImageParser.JPEG_APP0) - // + ") (" + getDescription() + ")"; - // } -} \ No newline at end of file + // public String getDescription() + // { + // return "APPN (APP" + // + (marker - JpegImageParser.JPEG_APP0) + // + ") (" + getDescription() + ")"; + // } +} Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/AppnSegment.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/AppnSegment.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/AppnSegment.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/AppnSegment.java Sat May 26 21:19:03 2012 @@ -21,18 +21,15 @@ import java.io.InputStream; import org.apache.commons.imaging.formats.jpeg.JpegImageParser; -public class AppnSegment extends GenericSegment -{ +public class AppnSegment extends GenericSegment { public AppnSegment(int marker, int marker_length, InputStream is) - throws IOException - { + throws IOException { super(marker, marker_length, is); } @Override - public String getDescription() - { + public String getDescription() { return "APPN (APP" + (marker - JpegImageParser.JPEG_APP0_Marker) + ") (" + getSegmentType() + ")"; } -} \ No newline at end of file +} Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/ComSegment.java Sat May 26 21:19:03 2012 @@ -21,33 +21,29 @@ import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; -public class ComSegment extends Segment -{ +public class ComSegment extends Segment { public final byte[] comment; - public ComSegment(int marker, byte segmentData[]) - throws IOException - { + public ComSegment(int marker, byte segmentData[]) throws IOException { this(marker, segmentData.length, new ByteArrayInputStream(segmentData)); } public ComSegment(int marker, int marker_length, InputStream is) - throws IOException - { + throws IOException { super(marker, marker_length); if (getDebug()) System.out.println("ComSegment marker_length: " + marker_length); - comment = readByteArray("Comment", marker_length, is, "Error reading JPEG comment"); + comment = readByteArray("Comment", marker_length, is, + "Error reading JPEG comment"); if (getDebug()) System.out.println(""); } @Override - public String getDescription() - { + public String getDescription() { String commentString = ""; try { commentString = new String(comment, "UTF-8"); Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DhtSegment.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DhtSegment.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DhtSegment.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DhtSegment.java Sat May 26 21:19:03 2012 @@ -21,12 +21,10 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; -public class DhtSegment extends Segment -{ +public class DhtSegment extends Segment { public final List huffmanTables = new ArrayList(); - public static class HuffmanTable - { + public static class HuffmanTable { // some arrays are better off one-based // to avoid subtractions by one later when indexing them public final int tableClass; @@ -42,46 +40,41 @@ public class DhtSegment extends Segment public final int[] valPtr = new int[1 + 16]; // 1-based public HuffmanTable(int tableClass, int destinationIdentifier, - int[] bits, int[] huffVal) - { + int[] bits, int[] huffVal) { this.tableClass = tableClass; this.destinationIdentifier = destinationIdentifier; this.bits = bits; this.huffVal = huffVal; - // "generate_size_table", section C.2, figure C.1, page 51 of ITU-T T.81: + // "generate_size_table", section C.2, figure C.1, page 51 of ITU-T + // T.81: int k = 0; int i = 1; int j = 1; int lastK = -1; - while (true) - { - if (j > bits[i]) - { + while (true) { + if (j > bits[i]) { i++; j = 1; - if (i > 16) - { + if (i > 16) { huffSize[k] = 0; lastK = k; break; } - } - else - { + } else { huffSize[k] = i; k++; j++; } } - // "generate_code_table", section C.2, figure C.2, page 52 of ITU-T T.81: + // "generate_code_table", section C.2, figure C.2, page 52 of ITU-T + // T.81: k = 0; int code = 0; int si = huffSize[0]; huffCode = new int[lastK]; - while (true) - { + while (true) { huffCode[k] = code; code++; k++; @@ -90,8 +83,7 @@ public class DhtSegment extends Segment continue; if (huffSize[k] == 0) break; - do - { + do { code <<= 1; si++; } while (huffSize[k] != si); @@ -100,15 +92,13 @@ public class DhtSegment extends Segment // "Decoder_tables", section F.2.2.3, figure F.15, page 108 of T.81: i = 0; j = 0; - while (true) - { + while (true) { i++; if (i > 16) break; if (bits[i] == 0) maxCode[i] = -1; - else - { + else { valPtr[i] = j; minCode[i] = huffCode[j]; j += bits[i] - 1; @@ -120,37 +110,29 @@ public class DhtSegment extends Segment } } - - public DhtSegment(int marker, byte[] segmentData) - throws IOException - { + public DhtSegment(int marker, byte[] segmentData) throws IOException { this(marker, segmentData.length, new ByteArrayInputStream(segmentData)); } public DhtSegment(int marker, int length, InputStream is) - throws IOException - { + throws IOException { super(marker, length); - while (length > 0) - { - int tableClassAndDestinationId = - 0xff & readByte("TableClassAndDestinationId", - is, "Not a Valid JPEG File"); + while (length > 0) { + int tableClassAndDestinationId = 0xff & readByte( + "TableClassAndDestinationId", is, "Not a Valid JPEG File"); length--; int tableClass = (tableClassAndDestinationId >> 4) & 0xf; int destinationIdentifier = tableClassAndDestinationId & 0xf; int[] bits = new int[1 + 16]; int bitsSum = 0; - for (int i = 1; i < bits.length; i++) - { + for (int i = 1; i < bits.length; i++) { bits[i] = 0xff & readByte("Li", is, "Not a Valid JPEG File"); length--; bitsSum += bits[i]; } int[] huffVal = new int[bitsSum]; - for (int i = 0; i < bitsSum; i++) - { + for (int i = 0; i < bitsSum; i++) { huffVal[i] = 0xff & readByte("Vij", is, "Not a Valid JPEG File"); length--; } @@ -161,8 +143,7 @@ public class DhtSegment extends Segment } @Override - public String getDescription() - { + public String getDescription() { return "DHT (" + getSegmentType() + ")"; } } Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DqtSegment.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DqtSegment.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DqtSegment.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/DqtSegment.java Sat May 26 21:19:03 2012 @@ -23,19 +23,16 @@ import java.util.List; import org.apache.commons.imaging.ImageReadException; -public class DqtSegment extends Segment -{ +public class DqtSegment extends Segment { public final List quantizationTables = new ArrayList(); - public static class QuantizationTable - { + public static class QuantizationTable { public final int precision; public final int destinationIdentifier; public final int[] elements; public QuantizationTable(int precision, int destinationIdentifier, - int[] elements) - { + int[] elements) { this.precision = precision; this.destinationIdentifier = destinationIdentifier; this.elements = elements; @@ -43,18 +40,15 @@ public class DqtSegment extends Segment } public DqtSegment(int marker, byte[] segmentData) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { this(marker, segmentData.length, new ByteArrayInputStream(segmentData)); } public DqtSegment(int marker, int length, InputStream is) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { super(marker, length); - while (length > 0) - { + while (length > 0) { int precisionAndDestination = readByte( "QuantizationTablePrecisionAndDestination", is, "Not a Valid JPEG File"); @@ -63,35 +57,29 @@ public class DqtSegment extends Segment int destinationIdentifier = precisionAndDestination & 0xf; int[] elements = new int[64]; - for (int i = 0; i < 64; i++) - { - if (precision == 0) - { + for (int i = 0; i < 64; i++) { + if (precision == 0) { elements[i] = 0xff & readByte("QuantizationTableElement", is, "Not a Valid JPEG File"); length--; - } - else if (precision == 1) - { - elements[i] = read2Bytes("QuantizationTableElement", - is, "Not a Valid JPEG File"); + } else if (precision == 1) { + elements[i] = read2Bytes("QuantizationTableElement", is, + "Not a Valid JPEG File"); length -= 2; - } - else - { - throw new ImageReadException("Quantization table precision '" + - precision + "' is invalid"); + } else { + throw new ImageReadException( + "Quantization table precision '" + precision + + "' is invalid"); } } - quantizationTables.add(new QuantizationTable( - precision, destinationIdentifier, elements)); + quantizationTables.add(new QuantizationTable(precision, + destinationIdentifier, elements)); } } @Override - public String getDescription() - { + public String getDescription() { return "DQT (" + getSegmentType() + ")"; } } Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/GenericSegment.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/GenericSegment.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/GenericSegment.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/GenericSegment.java Sat May 26 21:19:03 2012 @@ -20,42 +20,36 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; -public abstract class GenericSegment extends Segment -{ +public abstract class GenericSegment extends Segment { public final byte bytes[]; public GenericSegment(int marker, int marker_length, InputStream is) - throws IOException - { + throws IOException { super(marker, marker_length); bytes = readByteArray("Segment Data", marker_length, is, "Invalid Segment: insufficient data"); } - public GenericSegment(int marker, byte bytes[]) - { + public GenericSegment(int marker, byte bytes[]) { super(marker, bytes.length); this.bytes = bytes; } @Override - public void dump(PrintWriter pw) - { + public void dump(PrintWriter pw) { dump(pw, 0); } - public void dump(PrintWriter pw, int start) - { - for (int i = 0; (i < 50) && ((i + start) < bytes.length); i++) - { + public void dump(PrintWriter pw, int start) { + for (int i = 0; (i < 50) && ((i + start) < bytes.length); i++) { debugNumber(pw, "\t" + (i + start), bytes[i + start]); } } - // public String getDescription() - // { - // return "Unknown"; - // } -} \ No newline at end of file + // public String getDescription() + // { + // return "Unknown"; + // } +} Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/JfifSegment.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/JfifSegment.java?rev=1342971&r1=1342970&r2=1342971&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/JfifSegment.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/segments/JfifSegment.java Sat May 26 21:19:03 2012 @@ -23,8 +23,7 @@ import java.io.InputStream; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.formats.jpeg.JpegConstants; -public class JfifSegment extends Segment implements JpegConstants -{ +public class JfifSegment extends Segment implements JpegConstants { public final int jfifMajorVersion; public final int jfifMinorVersion; public final int densityUnits; @@ -36,20 +35,17 @@ public class JfifSegment extends Segment public final int thumbnailSize; @Override - public String getDescription() - { + public String getDescription() { return "JFIF (" + getSegmentType() + ")"; } public JfifSegment(int marker, byte segmentData[]) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { this(marker, segmentData.length, new ByteArrayInputStream(segmentData)); } public JfifSegment(int marker, int marker_length, InputStream is) - throws ImageReadException, IOException - { + throws ImageReadException, IOException { super(marker, marker_length); byte signature[] = readBytes(is, JFIF0_SIGNATURE.size()); @@ -69,8 +65,7 @@ public class JfifSegment extends Segment xThumbnail = readByte("x_thumbnail", is, "Not a Valid JPEG File"); yThumbnail = readByte("y_thumbnail", is, "Not a Valid JPEG File"); thumbnailSize = xThumbnail * yThumbnail; - if (thumbnailSize > 0) - { + if (thumbnailSize > 0) { skipBytes(is, thumbnailSize, "Not a Valid JPEG File: missing thumbnail"); @@ -80,4 +75,4 @@ public class JfifSegment extends Segment System.out.println(""); } -} \ No newline at end of file +}