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 EF085E895 for ; Fri, 1 Feb 2013 20:03:29 +0000 (UTC) Received: (qmail 14825 invoked by uid 500); 1 Feb 2013 20:03:29 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 14685 invoked by uid 500); 1 Feb 2013 20:03:29 -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 14678 invoked by uid 99); 1 Feb 2013 20:03:29 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Feb 2013 20:03:29 +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; Fri, 01 Feb 2013 20:03:26 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D85892388847; Fri, 1 Feb 2013 20:03:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1441610 - in /commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging: common/BinaryInputStream.java common/BinaryOutputStream.java formats/jpeg/iptc/IptcParser.java Date: Fri, 01 Feb 2013 20:03:05 -0000 To: commits@commons.apache.org From: damjan@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130201200305.D85892388847@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: damjan Date: Fri Feb 1 20:03:05 2013 New Revision: 1441610 URL: http://svn.apache.org/viewvc?rev=1441610&view=rev Log: Cleanups Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryOutputStream.java commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParser.java Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java?rev=1441610&r1=1441609&r2=1441610&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryInputStream.java Fri Feb 1 20:03:05 2013 @@ -24,6 +24,9 @@ import java.io.RandomAccessFile; import org.apache.commons.imaging.ImageReadException; public class BinaryInputStream extends InputStream { + private final InputStream is; + // default byte order for Java, many file formats. + private ByteOrder byteOrder = ByteOrder.NETWORK; protected boolean debug = false; public final void setDebug(final boolean b) { @@ -34,8 +37,6 @@ public class BinaryInputStream extends I return debug; } - private final InputStream is; - public BinaryInputStream(final byte bytes[], final ByteOrder byteOrder) { this.byteOrder = byteOrder; this.is = new ByteArrayInputStream(bytes); @@ -50,9 +51,6 @@ public class BinaryInputStream extends I this.is = is; } - // default byte order for Java, many file formats. - private ByteOrder byteOrder = ByteOrder.NETWORK; - protected void setByteOrder(final ByteOrder byteOrder) { this.byteOrder = byteOrder; } @@ -401,7 +399,7 @@ public class BinaryInputStream extends I throws ImageReadException, IOException { final int byte0 = is.read(); final int byte1 = is.read(); - if (byte0 < 0 || byte1 < 0) { + if ((byte0 | byte1) < 0) { throw new ImageReadException(exception); } @@ -418,7 +416,7 @@ public class BinaryInputStream extends I final int byte1 = is.read(); final int byte2 = is.read(); final int byte3 = is.read(); - if (byte0 < 0 || byte1 < 0 || byte2 < 0 || byte3 < 0) { + if ((byte0 | byte1 | byte2 | byte3) < 0) { throw new ImageReadException(exception); } Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryOutputStream.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryOutputStream.java?rev=1441610&r1=1441609&r2=1441610&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryOutputStream.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/common/BinaryOutputStream.java Fri Feb 1 20:03:05 2013 @@ -20,6 +20,9 @@ import java.io.IOException; import java.io.OutputStream; public class BinaryOutputStream extends OutputStream { + private final OutputStream os; + // default byte order for Java, many file formats. + private ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; protected boolean debug = false; private int count = 0; @@ -31,8 +34,6 @@ public class BinaryOutputStream extends return debug; } - private final OutputStream os; - public BinaryOutputStream(final OutputStream os, final ByteOrder byteOrder) { this.byteOrder = byteOrder; this.os = os; @@ -42,9 +43,6 @@ public class BinaryOutputStream extends this.os = os; } - // default byte order for Java, many file formats. - private ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; - protected void setByteOrder(final ByteOrder byteOrder) { this.byteOrder = byteOrder; } @@ -64,18 +62,6 @@ public class BinaryOutputStream extends } public final void write4Bytes(final int value) throws IOException { - writeNBytes(value, 4); - } - - public final void write3Bytes(final int value) throws IOException { - writeNBytes(value, 3); - } - - public final void write2Bytes(final int value) throws IOException { - writeNBytes(value, 2); - } - - public final void write4ByteInteger(final int value) throws IOException { if (byteOrder == ByteOrder.MOTOROLA) { write(0xff & (value >> 24)); write(0xff & (value >> 16)); @@ -87,43 +73,35 @@ public class BinaryOutputStream extends write(0xff & (value >> 16)); write(0xff & (value >> 24)); } + count += 4; } - public final void write2ByteInteger(final int value) throws IOException { + public final void write3Bytes(final int value) throws IOException { if (byteOrder == ByteOrder.MOTOROLA) { + write(0xff & (value >> 16)); write(0xff & (value >> 8)); write(0xff & value); } else { write(0xff & value); write(0xff & (value >> 8)); + write(0xff & (value >> 16)); } + count += 3; } - public final void writeByteArray(final byte bytes[]) throws IOException { - os.write(bytes, 0, bytes.length); - count += bytes.length; - } - - private byte[] convertValueToByteArray(final int value, final int n) { - final byte result[] = new byte[n]; - + public final void write2Bytes(final int value) throws IOException { if (byteOrder == ByteOrder.MOTOROLA) { - for (int i = 0; i < n; i++) { - final int b = 0xff & (value >> (8 * (n - i - 1))); - result[i] = (byte) b; - } + write(0xff & (value >> 8)); + write(0xff & value); } else { - for (int i = 0; i < n; i++) { - final int b = 0xff & (value >> (8 * i)); - result[i] = (byte) b; - } + write(0xff & value); + write(0xff & (value >> 8)); } - - return result; + count += 2; } - private final void writeNBytes(final int value, final int n) throws IOException { - write(convertValueToByteArray(value, n)); + public final void writeByteArray(final byte bytes[]) throws IOException { + os.write(bytes, 0, bytes.length); + count += bytes.length; } - } 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=1441610&r1=1441609&r2=1441610&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 Fri Feb 1 20:03:05 2013 @@ -381,7 +381,7 @@ public class IptcParser extends BinaryFi if (block.blockType < 0 || block.blockType > 0xffff) { throw new ImageWriteException("Invalid IPTC block type."); } - bos.write2ByteInteger(block.blockType); + bos.write2Bytes(block.blockType); if (block.blockNameBytes.length > 255) { throw new ImageWriteException("IPTC block name is too long: " @@ -397,7 +397,7 @@ public class IptcParser extends BinaryFi throw new ImageWriteException("IPTC block data is too long: " + block.blockData.length); } - bos.write4ByteInteger(block.blockData.length); + bos.write4Bytes(block.blockData.length); bos.write(block.blockData); if (block.blockData.length % 2 == 1) { bos.write(0); // pad to even size