mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-03 11:35:29 -04:00
More code clean up.
This commit is contained in:
parent
6da17cd7d1
commit
b219892bde
@ -60,7 +60,7 @@ public class Base64Encoder implements Encoder {
|
|||||||
// - or have flush/end method(s) in the Encoder
|
// - or have flush/end method(s) in the Encoder
|
||||||
// to ensure proper end of stream handling
|
// to ensure proper end of stream handling
|
||||||
|
|
||||||
int length = pLength;
|
int length;
|
||||||
int offset = pOffset;
|
int offset = pOffset;
|
||||||
|
|
||||||
// TODO: Temp impl, will only work for single writes
|
// TODO: Temp impl, will only work for single writes
|
||||||
|
8
twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/DecodeException.java
Executable file → Normal file
8
twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/DecodeException.java
Executable file → Normal file
@ -31,7 +31,7 @@ package com.twelvemonkeys.io.enc;
|
|||||||
import java.io.IOException;
|
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/>
|
* <p/>
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
* @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 class DecodeException extends IOException {
|
||||||
|
|
||||||
public DecodeException(String pMessage) {
|
public DecodeException(final String pMessage) {
|
||||||
super(pMessage);
|
super(pMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DecodeException(String pMessage, Throwable pCause) {
|
public DecodeException(final String pMessage, final Throwable pCause) {
|
||||||
super(pMessage);
|
super(pMessage);
|
||||||
initCause(pCause);
|
initCause(pCause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DecodeException(Throwable pCause) {
|
public DecodeException(final Throwable pCause) {
|
||||||
this(pCause.getMessage(), pCause);
|
this(pCause.getMessage(), pCause);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -82,11 +82,11 @@ public final class DecoderStream extends FilterInputStream {
|
|||||||
return mBuffer[mBufferPos++] & 0xff;
|
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);
|
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) {
|
if (pBytes == null) {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ public final class DecoderStream extends FilterInputStream {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long skip(long pLength) throws IOException {
|
public long skip(final long pLength) throws IOException {
|
||||||
// End of file?
|
// End of file?
|
||||||
if (mBufferLimit - mBufferPos < 0) {
|
if (mBufferLimit - mBufferPos < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -142,6 +142,7 @@ public final class DecoderStream extends FilterInputStream {
|
|||||||
|
|
||||||
// Skip until we have skipped pLength bytes, or have reached EOF
|
// Skip until we have skipped pLength bytes, or have reached EOF
|
||||||
long total = 0;
|
long total = 0;
|
||||||
|
|
||||||
while (total < pLength) {
|
while (total < pLength) {
|
||||||
int avail = mBufferLimit - mBufferPos;
|
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
|
* @return the number of bytes decoded, or {@code -1} if the end of the
|
||||||
* file is reached
|
* file is reached
|
||||||
*
|
*
|
||||||
* @throws IOException if an IO error occurs
|
* @throws IOException if an I/O error occurs
|
||||||
*/
|
*/
|
||||||
protected int fill() throws IOException {
|
protected int fill() throws IOException {
|
||||||
int read = mDecoder.decode(in, mBuffer);
|
int read = mDecoder.decode(in, mBuffer);
|
||||||
|
|
||||||
// TODO: Enforce this in test case, leave here to aid debugging
|
// TODO: Enforce this in test case, leave here to aid debugging
|
||||||
if (read > mBuffer.length) {
|
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;
|
mBufferPos = 0;
|
||||||
|
2
twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/package-info.java
Executable file → Normal file
2
twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/package-info.java
Executable file → Normal file
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Contains customized stream classes, that can read or write compressed data on the fly,
|
* 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.DecoderStream
|
||||||
* @see com.twelvemonkeys.io.enc.EncoderStream
|
* @see com.twelvemonkeys.io.enc.EncoderStream
|
||||||
|
Loading…
x
Reference in New Issue
Block a user