Revision: 8435
http://svn.sourceforge.net/foray/?rev=8435&view=rev
Author: victormote
Date: 2006-10-27 09:10:37 -0700 (Fri, 27 Oct 2006)
Log Message:
-----------
Fix multiple bugs introduced in the removal of magic numbers.
Modified Paths:
--------------
trunk/foray/foray-ps/src/java/org/foray/ps/filter/ASCII85Filter.java
Modified: trunk/foray/foray-ps/src/java/org/foray/ps/filter/ASCII85Filter.java
===================================================================
--- trunk/foray/foray-ps/src/java/org/foray/ps/filter/ASCII85Filter.java 2006-10-27 01:24:18 UTC (rev 8434)
+++ trunk/foray/foray-ps/src/java/org/foray/ps/filter/ASCII85Filter.java 2006-10-27 16:10:37 UTC (rev 8435)
@@ -40,15 +40,18 @@
public class ASCII85Filter extends PSFilter {
/** Mask needed during encoding. */
- private static final long MASK_BYTE_1 = WKConstants.MAX_8_BIT_UNSIGNED_INT
+ private static final long MASK_BYTE_1 =
+ ((long) WKConstants.MAX_8_BIT_UNSIGNED_INT)
<< WKConstants.SHIFT_3_BYTES;
/** Mask needed during encoding. */
- private static final long MASK_BYTE_2 = WKConstants.MAX_8_BIT_UNSIGNED_INT
+ private static final long MASK_BYTE_2 =
+ ((long) WKConstants.MAX_8_BIT_UNSIGNED_INT)
<< WKConstants.SHIFT_2_BYTES;
/** Mask needed during encoding. */
- private static final long MASK_BYTE_3 = WKConstants.MAX_8_BIT_UNSIGNED_INT
+ private static final long MASK_BYTE_3 =
+ ((long) WKConstants.MAX_8_BIT_UNSIGNED_INT)
<< WKConstants.SHIFT_1_BYTE;
/** Mask needed during encoding. */
@@ -102,12 +105,17 @@
public byte[] encode(final byte[] data) throws PSFilterException {
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int i;
+ byte[] unencodedBytes;
// first encode the majority of the data
// each 4 byte group becomes a 5 byte group
for (i = 0; i + UNENCODED_BLOCK_SIZE <= data.length;
i += UNENCODED_BLOCK_SIZE) {
- final long val = encodeAsLong(data);
+ unencodedBytes = new byte[UNENCODED_BLOCK_SIZE];
+ for (int j = 0; j < unencodedBytes.length; j++) {
+ unencodedBytes[j] = data[i + j];
+ }
+ final long val = encodeAsLong(unencodedBytes);
final byte[] conv = convertWord(val);
buffer.write(conv, 0, conv.length);
}
@@ -118,16 +126,16 @@
// and write out the first n+1 bytes from the result
if (i < data.length) {
final int n = data.length - i;
- final byte[] lastdata = new byte[UNENCODED_BLOCK_SIZE];
- for (int j = 0; j < lastdata.length; j++) {
+ unencodedBytes = new byte[UNENCODED_BLOCK_SIZE];
+ for (int j = 0; j < unencodedBytes.length; j++) {
if (j < n) {
- lastdata[j] = data[i++];
+ unencodedBytes[j] = data[i++];
} else {
- lastdata[j] = 0;
+ unencodedBytes[j] = 0;
}
}
- final long val = encodeAsLong(lastdata);
+ final long val = encodeAsLong(unencodedBytes);
byte[] conv = convertWord(val);
// special rule for handling zeros at the end
@@ -157,13 +165,13 @@
return -1;
}
int index = 0;
- final long byte1 = (bytes[index] << WKConstants.SHIFT_3_BYTES)
+ final long byte1 = (((long) bytes[index]) << WKConstants.SHIFT_3_BYTES)
& MASK_BYTE_1;
index ++;
- final long byte2 = (bytes[index] << WKConstants.SHIFT_2_BYTES)
+ final long byte2 = (((long) bytes[index]) << WKConstants.SHIFT_2_BYTES)
& MASK_BYTE_2;
index ++;
- final long byte3 = (bytes[index] << WKConstants.SHIFT_1_BYTE)
+ final long byte3 = (((long) bytes[index]) << WKConstants.SHIFT_1_BYTE)
& MASK_BYTE_3;
index ++;
final long byte4 = bytes[index] & MASK_BYTE_4;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|