mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-10-04 11:26:44 -04:00
Various code clean-up. No functional changes.
This commit is contained in:
@@ -46,8 +46,8 @@ import java.util.zip.Deflater;
|
||||
*/
|
||||
final class DeflateEncoder implements Encoder {
|
||||
|
||||
private final Deflater mDeflater;
|
||||
private final byte[] mBuffer = new byte[1024];
|
||||
private final Deflater deflater;
|
||||
private final byte[] buffer = new byte[1024];
|
||||
|
||||
public DeflateEncoder() {
|
||||
// this(new Deflater());
|
||||
@@ -59,32 +59,32 @@ final class DeflateEncoder implements Encoder {
|
||||
throw new IllegalArgumentException("deflater == null");
|
||||
}
|
||||
|
||||
mDeflater = pDeflater;
|
||||
deflater = pDeflater;
|
||||
}
|
||||
|
||||
public void encode(final OutputStream pStream, final byte[] pBuffer, final int pOffset, final int pLength)
|
||||
throws IOException
|
||||
{
|
||||
System.out.println("DeflateEncoder.encode");
|
||||
mDeflater.setInput(pBuffer, pOffset, pLength);
|
||||
deflater.setInput(pBuffer, pOffset, pLength);
|
||||
flushInputToStream(pStream);
|
||||
}
|
||||
|
||||
private void flushInputToStream(final OutputStream pStream) throws IOException {
|
||||
System.out.println("DeflateEncoder.flushInputToStream");
|
||||
|
||||
if (mDeflater.needsInput()) {
|
||||
if (deflater.needsInput()) {
|
||||
System.out.println("Foo");
|
||||
}
|
||||
|
||||
while (!mDeflater.needsInput()) {
|
||||
int deflated = mDeflater.deflate(mBuffer, 0, mBuffer.length);
|
||||
pStream.write(mBuffer, 0, deflated);
|
||||
while (!deflater.needsInput()) {
|
||||
int deflated = deflater.deflate(buffer, 0, buffer.length);
|
||||
pStream.write(buffer, 0, deflated);
|
||||
System.out.println("flushed " + deflated);
|
||||
}
|
||||
}
|
||||
|
||||
// public void flush() {
|
||||
// mDeflater.finish();
|
||||
// deflater.finish();
|
||||
// }
|
||||
}
|
||||
|
@@ -49,9 +49,9 @@ import java.util.zip.Inflater;
|
||||
*/
|
||||
final class InflateDecoder implements Decoder {
|
||||
|
||||
private final Inflater mInflater;
|
||||
private final Inflater inflater;
|
||||
|
||||
private final byte[] mBuffer;
|
||||
private final byte[] buffer;
|
||||
|
||||
/**
|
||||
* Creates an {@code InflateDecoder}
|
||||
@@ -71,20 +71,20 @@ final class InflateDecoder implements Decoder {
|
||||
throw new IllegalArgumentException("inflater == null");
|
||||
}
|
||||
|
||||
mInflater = pInflater;
|
||||
mBuffer = new byte[1024];
|
||||
inflater = pInflater;
|
||||
buffer = new byte[1024];
|
||||
}
|
||||
|
||||
public int decode(final InputStream pStream, final byte[] pBuffer) throws IOException {
|
||||
try {
|
||||
int decoded;
|
||||
|
||||
while ((decoded = mInflater.inflate(pBuffer, 0, pBuffer.length)) == 0) {
|
||||
if (mInflater.finished() || mInflater.needsDictionary()) {
|
||||
while ((decoded = inflater.inflate(pBuffer, 0, pBuffer.length)) == 0) {
|
||||
if (inflater.finished() || inflater.needsDictionary()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (mInflater.needsInput()) {
|
||||
if (inflater.needsInput()) {
|
||||
fill(pStream);
|
||||
}
|
||||
}
|
||||
@@ -98,12 +98,12 @@ final class InflateDecoder implements Decoder {
|
||||
}
|
||||
|
||||
private void fill(final InputStream pStream) throws IOException {
|
||||
int available = pStream.read(mBuffer, 0, mBuffer.length);
|
||||
int available = pStream.read(buffer, 0, buffer.length);
|
||||
|
||||
if (available == -1) {
|
||||
throw new EOFException("Unexpected end of ZLIB stream");
|
||||
}
|
||||
|
||||
mInflater.setInput(mBuffer, 0, available);
|
||||
inflater.setInput(buffer, 0, available);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user