Apply current code style

This commit is contained in:
cketti 2016-04-16 20:52:14 +02:00
parent af7e0ac4cb
commit 1cd4d87068

View file

@ -1,19 +1,21 @@
package com.fsck.k9.mail.filter;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
/**
* A filtering InputStream that allows single byte "peeks" without consuming the byte. The
* client of this stream can call peek() to see the next available byte in the stream
* and a subsequent read will still return the peeked byte.
*/
public class PeekableInputStream extends FilterInputStream {
private boolean mPeeked;
private int mPeekedByte;
private boolean peeked;
private int peekedByte;
public PeekableInputStream(InputStream in) {
super(in);
@ -21,30 +23,30 @@ public class PeekableInputStream extends FilterInputStream {
@Override
public int read() throws IOException {
if (!mPeeked) {
if (!peeked) {
return in.read();
} else {
mPeeked = false;
return mPeekedByte;
peeked = false;
return peekedByte;
}
}
public int peek() throws IOException {
if (!mPeeked) {
mPeekedByte = in.read();
mPeeked = true;
if (!peeked) {
peekedByte = in.read();
peeked = true;
}
return mPeekedByte;
return peekedByte;
}
@Override
public int read(byte[] b, int offset, int length) throws IOException {
if (!mPeeked) {
return in.read(b, offset, length);
public int read(byte[] buffer, int offset, int length) throws IOException {
if (!peeked) {
return in.read(buffer, offset, length);
} else {
b[offset] = (byte)mPeekedByte;
mPeeked = false;
int r = in.read(b, offset + 1, length - 1);
buffer[offset] = (byte) peekedByte;
peeked = false;
int r = in.read(buffer, offset + 1, length - 1);
if (r == -1) {
return 1;
} else {
@ -54,13 +56,13 @@ public class PeekableInputStream extends FilterInputStream {
}
@Override
public int read(byte[] b) throws IOException {
return read(b, 0, b.length);
public int read(byte[] buffer) throws IOException {
return read(buffer, 0, buffer.length);
}
@Override
public String toString() {
return String.format(Locale.US, "PeekableInputStream(in=%s, peeked=%b, peekedByte=%d)",
in.toString(), mPeeked, mPeekedByte);
in.toString(), peeked, peekedByte);
}
}