You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by da...@apache.org on 2013/02/01 21:03:05 UTC
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
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