You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/01/09 17:31:12 UTC
[commons-io] branch master updated: Refactor common code, Javadoc,
reuse constants,
use 120 max line length. Javadoc: Sentences end in a period.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new 4b92e65 Refactor common code, Javadoc, reuse constants, use 120 max line length. Javadoc: Sentences end in a period.
4b92e65 is described below
commit 4b92e65963105eedf469ace591ae0b84aa1c3afc
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jan 9 12:22:49 2021 -0500
Refactor common code, Javadoc, reuse constants, use 120 max line length.
Javadoc: Sentences end in a period.
---
.../apache/commons/io/filefilter/IOFileFilter.java | 20 +++++-----
.../io/input/buffer/CircularBufferInputStream.java | 46 ++++++++++++----------
.../io/input/buffer/PeekableInputStream.java | 41 +++++++------------
3 files changed, 50 insertions(+), 57 deletions(-)
diff --git a/src/main/java/org/apache/commons/io/filefilter/IOFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/IOFileFilter.java
index 90df711..6c29841 100644
--- a/src/main/java/org/apache/commons/io/filefilter/IOFileFilter.java
+++ b/src/main/java/org/apache/commons/io/filefilter/IOFileFilter.java
@@ -43,8 +43,8 @@ public interface IOFileFilter extends FileFilter, FilenameFilter, PathFilter {
* 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);
@@ -55,9 +55,9 @@ public interface IOFileFilter extends FileFilter, FilenameFilter, PathFilter {
* 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);
@@ -65,8 +65,8 @@ public interface IOFileFilter extends FileFilter, FilenameFilter, PathFilter {
/**
* 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 @@ public interface IOFileFilter extends FileFilter, FilenameFilter, PathFilter {
* 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 @@ public interface IOFileFilter extends FileFilter, FilenameFilter, PathFilter {
/**
* 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 @@ public interface IOFileFilter extends FileFilter, FilenameFilter, PathFilter {
* 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) {
diff --git a/src/main/java/org/apache/commons/io/input/buffer/CircularBufferInputStream.java b/src/main/java/org/apache/commons/io/input/buffer/CircularBufferInputStream.java
index f797f3d..383a453 100644
--- a/src/main/java/org/apache/commons/io/input/buffer/CircularBufferInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/buffer/CircularBufferInputStream.java
@@ -16,31 +16,37 @@
*/
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 inputStream The input stream, which is being buffered.
+ * @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 class CircularBufferInputStream extends InputStream {
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 class CircularBufferInputStream extends 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 @@ public class CircularBufferInputStream extends InputStream {
@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 class CircularBufferInputStream extends InputStream {
@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 class CircularBufferInputStream extends InputStream {
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 class CircularBufferInputStream extends InputStream {
@Override
public void close() throws IOException {
in.close();
- eofSeen = true;
+ eof = true;
buffer.clear();
}
}
diff --git a/src/main/java/org/apache/commons/io/input/buffer/PeekableInputStream.java b/src/main/java/org/apache/commons/io/input/buffer/PeekableInputStream.java
index 0cffdc2..df15e70 100644
--- a/src/main/java/org/apache/commons/io/input/buffer/PeekableInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/buffer/PeekableInputStream.java
@@ -20,29 +20,24 @@ import java.io.IOException;
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 inputStream The input stream, which is being buffered.
+ * @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 class PeekableInputStream extends CircularBufferInputStream {
}
/**
- * 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,10 +69,10 @@ public class PeekableInputStream extends CircularBufferInputStream {
* @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");
+ + " bytes exceeds buffer size of " + bufferSize + " bytes");
}
if (buffer.getCurrentNumberOfBytes() < sourceBuffer.length) {
fillBuffer();