diff --git a/src/com/fsck/k9/mail/filter/FixedLengthInputStream.java b/src/com/fsck/k9/mail/filter/FixedLengthInputStream.java index 00e84a7cc..48bf955a2 100644 --- a/src/com/fsck/k9/mail/filter/FixedLengthInputStream.java +++ b/src/com/fsck/k9/mail/filter/FixedLengthInputStream.java @@ -10,9 +10,9 @@ import java.io.InputStream; * past where the protocol handler intended the client to read. */ public class FixedLengthInputStream extends InputStream { - private InputStream mIn; - private int mLength; - private int mCount; + private final InputStream mIn; + private final int mLength; + private int mCount = 0; public FixedLengthInputStream(InputStream in, int length) { this.mIn = in; @@ -26,30 +26,28 @@ public class FixedLengthInputStream extends InputStream { @Override public int read() throws IOException { - if (mCount < mLength) { - int d = mIn.read(); - if (d != -1) { - mCount++; - } - return d; - } else { + if (mCount >= mLength) { return -1; } + + int d = mIn.read(); + if (d != -1) { + mCount++; + } + return d; } @Override public int read(byte[] b, int offset, int length) throws IOException { - if (mCount < mLength) { - int d = mIn.read(b, offset, Math.min(mLength - mCount, length)); - if (d == -1) { - return -1; - } else { - mCount += d; - return d; - } - } else { + if (mCount >= mLength) { return -1; } + + int d = mIn.read(b, offset, Math.min(mLength - mCount, length)); + if (d != -1) { + mCount += d; + } + return d; } @Override