From b219892bde51a798106541133a31d7d770f9ea5e Mon Sep 17 00:00:00 2001 From: Harald Kuhr Date: Sun, 20 Sep 2009 14:39:13 +0200 Subject: [PATCH] More code clean up. --- .../com/twelvemonkeys/io/enc/Base64Encoder.java | 2 +- .../twelvemonkeys/io/enc/DecodeException.java | 8 ++++---- .../com/twelvemonkeys/io/enc/DecoderStream.java | 16 +++++++++++----- .../com/twelvemonkeys/io/enc/package-info.java | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) mode change 100755 => 100644 twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/DecodeException.java mode change 100755 => 100644 twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/package-info.java diff --git a/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/Base64Encoder.java b/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/Base64Encoder.java index 6c916fee..54af6eb9 100644 --- a/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/Base64Encoder.java +++ b/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/Base64Encoder.java @@ -60,7 +60,7 @@ public class Base64Encoder implements Encoder { // - or have flush/end method(s) in the Encoder // to ensure proper end of stream handling - int length = pLength; + int length; int offset = pOffset; // TODO: Temp impl, will only work for single writes diff --git a/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/DecodeException.java b/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/DecodeException.java old mode 100755 new mode 100644 index 7f49b9f6..45ab9455 --- a/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/DecodeException.java +++ b/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/DecodeException.java @@ -31,7 +31,7 @@ package com.twelvemonkeys.io.enc; import java.io.IOException; /** - * Thrown by {@code Decoder}s when encoded data is not decodable. + * Thrown by {@code Decoder}s when encoded data can not be decocded. *

* * @author Harald Kuhr @@ -39,16 +39,16 @@ import java.io.IOException; */ public class DecodeException extends IOException { - public DecodeException(String pMessage) { + public DecodeException(final String pMessage) { super(pMessage); } - public DecodeException(String pMessage, Throwable pCause) { + public DecodeException(final String pMessage, final Throwable pCause) { super(pMessage); initCause(pCause); } - public DecodeException(Throwable pCause) { + public DecodeException(final Throwable pCause) { this(pCause.getMessage(), pCause); } } \ No newline at end of file diff --git a/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/DecoderStream.java b/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/DecoderStream.java index f371a9be..69920fd7 100644 --- a/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/DecoderStream.java +++ b/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/DecoderStream.java @@ -82,11 +82,11 @@ public final class DecoderStream extends FilterInputStream { return mBuffer[mBufferPos++] & 0xff; } - public int read(byte pBytes[]) throws IOException { + public int read(final byte pBytes[]) throws IOException { return read(pBytes, 0, pBytes.length); } - public int read(byte pBytes[], int pOffset, int pLength) throws IOException { + public int read(final byte pBytes[], final int pOffset, final int pLength) throws IOException { if (pBytes == null) { throw new NullPointerException(); } @@ -134,7 +134,7 @@ public final class DecoderStream extends FilterInputStream { return count; } - public long skip(long pLength) throws IOException { + public long skip(final long pLength) throws IOException { // End of file? if (mBufferLimit - mBufferPos < 0) { return 0; @@ -142,6 +142,7 @@ public final class DecoderStream extends FilterInputStream { // Skip until we have skipped pLength bytes, or have reached EOF long total = 0; + while (total < pLength) { int avail = mBufferLimit - mBufferPos; @@ -170,14 +171,19 @@ public final class DecoderStream extends FilterInputStream { * @return the number of bytes decoded, or {@code -1} if the end of the * file is reached * - * @throws IOException if an IO error occurs + * @throws IOException if an I/O error occurs */ protected int fill() throws IOException { int read = mDecoder.decode(in, mBuffer); // TODO: Enforce this in test case, leave here to aid debugging if (read > mBuffer.length) { - throw new AssertionError(String.format("Decode beyond buffer (%d): %d", mBuffer.length, read)); + throw new AssertionError( + String.format( + "Decode beyond buffer (%d): %d (using %s decoder)", + mBuffer.length, read, mDecoder.getClass().getName() + ) + ); } mBufferPos = 0; diff --git a/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/package-info.java b/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/package-info.java old mode 100755 new mode 100644 index d69ccb65..72d47b16 --- a/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/package-info.java +++ b/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/package-info.java @@ -1,6 +1,6 @@ /** * Contains customized stream classes, that can read or write compressed data on the fly, - * along with encoders and decoders for popular stream formats, such as ZIP (deflate), LZW, PackBits etc.. + * along with encoders and decoders for popular stream formats, such as Base64, ZIP (deflate), LZW, PackBits etc.. * * @see com.twelvemonkeys.io.enc.DecoderStream * @see com.twelvemonkeys.io.enc.EncoderStream