More code clean up.

This commit is contained in:
Harald Kuhr 2009-09-20 14:39:13 +02:00
parent 6da17cd7d1
commit b219892bde
4 changed files with 17 additions and 11 deletions

View File

@ -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

View File

@ -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.
* <p/>
*
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
@ -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);
}
}

View File

@ -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;

View File

@ -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