Refactor common code, Javadoc, reuse constants, use 120 max line length.
Javadoc: Sentences end in a period.
MODIFY
src/main/java/org/apache/commons/io/filefilter/IOFileFilter.java
src/main/java/org/apache/commons/io/filefilter/IOFileFilter.java
* Defined in {@link java.io.FileFilter}.
* </p>
*
- * @param file the File to check
- * @return true if this file matches the test
+ * @param file the File to check.
+ * @return true if this file matches the test.
*/
@Override
boolean accept(File file);
* Defined in {@link java.io.FilenameFilter}.
* </p>
*
- * @param dir the directory File to check
- * @param name the file name within the directory to check
- * @return true if this file matches the test
+ * @param dir the directory File to check.
+ * @param name the file name within the directory to check.
+ * @return true if this file matches the test.
*/
@Override
boolean accept(File dir, String name);
/**
* Checks to see if the Path should be accepted by this filter.
*
- * @param path the Path to check
- * @return true if this path matches the test
+ * @param path the Path to check.
+ * @return true if this path matches the test.
* @since 2.9.0
*/
@Override
@@ -78,7 +78,7 @@ default FileVisitResult accept(final Path path, final BasicFileAttributes attrib
* Creates a new "and" filter with this filter.
*
* @param fileFilter the filter to "and".
- * @return a new filter
+ * @return a new filter.
* @since 2.9.0
*/
default IOFileFilter and(final IOFileFilter fileFilter) {
@@ -88,7 +88,7 @@ default IOFileFilter and(final IOFileFilter fileFilter) {
/**
* Creates a new "not" filter with this filter.
*
- * @return a new filter
+ * @return a new filter.
* @since 2.9.0
*/
default IOFileFilter negate() {
@@ -99,7 +99,7 @@ default IOFileFilter negate() {
* Creates a new "or" filter with this filter.
*
* @param fileFilter the filter to "or".
- * @return a new filter
+ * @return a new filter.
* @since 2.9.0
*/
default IOFileFilter or(final IOFileFilter fileFilter) {

MODIFY
src/main/java/org/apache/commons/io/input/buffer/CircularBufferInputStream.java
src/main/java/org/apache/commons/io/input/buffer/CircularBufferInputStream.java
*/
package org.apache.commons.io.input.buffer;
+import static org.apache.commons.io.IOUtils.EOF;
+
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import org.apache.commons.io.IOUtils;
-
/**
- * Implementation of a buffered input stream, which is internally based on the
- * {@link CircularByteBuffer}. Unlike the {@link java.io.BufferedInputStream}, this one
- * doesn't need to reallocate byte arrays internally.
+ * Implements a buffered input stream, which is internally based on a {@link CircularByteBuffer}. Unlike the
+ * {@link java.io.BufferedInputStream}, this one doesn't need to reallocate byte arrays internally.
*/
public class CircularBufferInputStream extends InputStream {
+
+ /** What we are streaming, used to fill the internal buffer. */
protected final InputStream in;
+
+ /** Internal buffer. */
protected final CircularByteBuffer buffer;
+
+ /** Internal buffer size. */
protected final int bufferSize;
- private boolean eofSeen;
+
+ /** Whether we've see the input stream EOF. */
+ private boolean eof;
/**
- * Creates a new instance, which filters the given input stream, and
- * uses the given buffer size.
+ * Creates a new instance, which filters the given input stream, and uses the given buffer size.
*
* @param inputStream The input stream, which is being buffered.
- * @param bufferSize The size of the {@link CircularByteBuffer}, which is
- * used internally.
+ * @param bufferSize The size of the {@link CircularByteBuffer}, which is used internally.
*/
public CircularBufferInputStream(final InputStream inputStream, final int bufferSize) {
if (bufferSize <= 0) {
@@ -49,12 +55,12 @@ public CircularBufferInputStream(final InputStream inputStream, final int buffer
this.in = Objects.requireNonNull(inputStream, "inputStream");
this.buffer = new CircularByteBuffer(bufferSize);
this.bufferSize = bufferSize;
- this.eofSeen = false;
+ this.eof = false;
}
/**
- * Creates a new instance, which filters the given input stream, and
- * uses a reasonable default buffer size ({@link IOUtils#DEFAULT_BUFFER_SIZE}).
+ * Creates a new instance, which filters the given input stream, and uses a reasonable default buffer size
+ * ({@link IOUtils#DEFAULT_BUFFER_SIZE}).
*
* @param inputStream The input stream, which is being buffered.
*/
@@ -68,15 +74,15 @@ public CircularBufferInputStream(final InputStream inputStream) {
* @throws IOException in case of an error while reading from the input stream.
*/
protected void fillBuffer() throws IOException {
- if (eofSeen) {
+ if (eof) {
return;
}
int space = buffer.getSpace();
final byte[] buf = new byte[space];
while (space > 0) {
final int res = in.read(buf, 0, space);
- if (res == -1) {
- eofSeen = true;
+ if (res == EOF) {
+ eof = true;
return;
} else if (res > 0) {
buffer.add(buf, 0, res);
@@ -102,7 +108,7 @@ protected boolean haveBytes(final int count) throws IOException {
@Override
public int read() throws IOException {
if (!haveBytes(1)) {
- return -1;
+ return EOF;
}
return buffer.read() & 0xFF; // return unsigned byte
}
@@ -114,7 +120,7 @@ public int read(final byte[] buffer) throws IOException {
@Override
public int read(final byte[] targetBuffer, final int offset, final int length) throws IOException {
- Objects.requireNonNull(targetBuffer, "Buffer");
+ Objects.requireNonNull(targetBuffer, "targetBuffer");
if (offset < 0) {
throw new IllegalArgumentException("Offset must not be negative");
}
@@ -122,7 +128,7 @@ public int read(final byte[] targetBuffer, final int offset, final int length) t
throw new IllegalArgumentException("Length must not be negative");
}
if (!haveBytes(length)) {
- return -1;
+ return EOF;
}
final int result = Math.min(length, buffer.getCurrentNumberOfBytes());
for (int i = 0; i < result; i++) {
@@ -134,7 +140,7 @@ public int read(final byte[] targetBuffer, final int offset, final int length) t
@Override
public void close() throws IOException {
in.close();
- eofSeen = true;
+ eof = true;
buffer.clear();
}
}

MODIFY
src/main/java/org/apache/commons/io/input/buffer/PeekableInputStream.java
src/main/java/org/apache/commons/io/input/buffer/PeekableInputStream.java
import java.io.InputStream;
import java.util.Objects;
-
/**
- * Implementation of a buffered input stream, which allows to peek into
- * the buffers first bytes. This comes in handy when manually implementing
- * scanners, lexers, parsers, or the like.
+ * Implements a buffered input stream, which allows to peek into the buffers first bytes. This comes in handy when
+ * manually implementing scanners, lexers, parsers, and the like.
*/
public class PeekableInputStream extends CircularBufferInputStream {
/**
- * Creates a new instance, which filters the given input stream, and
- * uses the given buffer size.
+ * Creates a new instance, which filters the given input stream, and uses the given buffer size.
*
* @param inputStream The input stream, which is being buffered.
- * @param bufferSize The size of the {@link CircularByteBuffer}, which is
- * used internally.
+ * @param bufferSize The size of the {@link CircularByteBuffer}, which is used internally.
*/
public PeekableInputStream(final InputStream inputStream, final int bufferSize) {
super(inputStream, bufferSize);
}
/**
- * Creates a new instance, which filters the given input stream, and
- * uses a reasonable default buffer size (8192).
+ * Creates a new instance, which filters the given input stream, and uses a reasonable default buffer size (8192).
*
* @param inputStream The input stream, which is being buffered.
*/
@@ -51,29 +46,21 @@ public PeekableInputStream(final InputStream inputStream) {
}
/**
- * Returns, whether the next bytes in the buffer are as given by
- * {@code sourceBuffer}. This is equivalent to {@link #peek(byte[], int, int)}
- * with {@code offset} == 0, and {@code length} == {@code sourceBuffer.length}
+ * Returns whether the next bytes in the buffer are as given by {@code sourceBuffer}. This is equivalent to
+ * {@link #peek(byte[], int, int)} with {@code offset} == 0, and {@code length} == {@code sourceBuffer.length}
*
* @param sourceBuffer the buffer to compare against
* @return true if the next bytes are as given
* @throws IOException Refilling the buffer failed.
*/
public boolean peek(final byte[] sourceBuffer) throws IOException {
- Objects.requireNonNull(sourceBuffer, "Buffer");
- if (sourceBuffer.length > bufferSize) {
- throw new IllegalArgumentException("Peek request size of " + sourceBuffer.length
- + " bytes exceeds buffer size of " + bufferSize + " bytes");
- }
- if (buffer.getCurrentNumberOfBytes() < sourceBuffer.length) {
- fillBuffer();
- }
- return buffer.peek(sourceBuffer, 0, sourceBuffer.length);
+ Objects.requireNonNull(sourceBuffer, "sourceBuffer");
+ return peek(sourceBuffer, 0, sourceBuffer.length);
}
/**
- * Returns, whether the next bytes in the buffer are as given by
- * {@code sourceBuffer}, {code offset}, and {@code length}.
+ * Returns whether the next bytes in the buffer are as given by {@code sourceBuffer}, {code offset}, and
+ * {@code length}.
*
* @param sourceBuffer the buffer to compare against
* @param offset the start offset
@@ -82,7 +69,7 @@ public boolean peek(final byte[] sourceBuffer) throws IOException {
* @throws IOException if there is a problem calling fillBuffer()
*/
public boolean peek(final byte[] sourceBuffer, final int offset, final int length) throws IOException {
- Objects.requireNonNull(sourceBuffer, "Buffer");
+ Objects.requireNonNull(sourceBuffer, "sourceBuffer");
if (sourceBuffer.length > bufferSize) {
throw new IllegalArgumentException("Peek request size of " + sourceBuffer.length
+ " bytes exceeds buffer size of " + bufferSize + " bytes");

Refactor common code, Javadoc, reuse constants, use 120 max line length.
Javadoc: Sentences end in a period.