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/19 19:03:51 UTC
[commons-io] branch master updated: Minor Improvement: (#190)
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 9009ede Minor Improvement: (#190)
9009ede is described below
commit 9009ede38b2d30be7b9cebdaca47649a1ead5528
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Tue Jan 19 20:03:44 2021 +0100
Minor Improvement: (#190)
* Add final
* Remove redundant initializer
* simplify conditions
---
.../org/apache/commons/io/FileCleaningTracker.java | 2 +-
src/main/java/org/apache/commons/io/FileUtils.java | 22 +++++++++++-----------
.../java/org/apache/commons/io/LineIterator.java | 2 +-
.../commons/io/file/DeletingPathVisitor.java | 2 +-
.../java/org/apache/commons/io/file/PathUtils.java | 4 ++--
.../commons/io/input/BoundedInputStream.java | 2 +-
.../org/apache/commons/io/input/BoundedReader.java | 2 +-
.../io/input/BufferedFileChannelInputStream.java | 4 +---
.../io/input/UnixLineEndingInputStream.java | 6 +++---
.../io/input/WindowsLineEndingInputStream.java | 8 ++++----
.../commons/io/monitor/FileAlterationMonitor.java | 4 ++--
.../commons/io/output/CountingOutputStream.java | 2 +-
.../io/output/DeferredFileOutputStream.java | 2 +-
.../commons/io/output/QueueOutputStream.java | 2 +-
.../org/apache/commons/io/IOUtilsTestCase.java | 4 ++--
.../io/input/ObservableInputStreamTest.java | 2 +-
.../org/apache/commons/io/input/TailerTest.java | 10 +++++-----
.../io/input/compatibility/XmlStreamReader.java | 2 +-
18 files changed, 40 insertions(+), 42 deletions(-)
diff --git a/src/main/java/org/apache/commons/io/FileCleaningTracker.java b/src/main/java/org/apache/commons/io/FileCleaningTracker.java
index 8efed7b..62c52e7 100644
--- a/src/main/java/org/apache/commons/io/FileCleaningTracker.java
+++ b/src/main/java/org/apache/commons/io/FileCleaningTracker.java
@@ -60,7 +60,7 @@ public class FileCleaningTracker {
/**
* Whether to terminate the thread when the tracking is complete.
*/
- volatile boolean exitWhenFinished = false;
+ volatile boolean exitWhenFinished;
/**
* The thread that will clean up registered files.
*/
diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java
index 0ad361b..389653f 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -1293,7 +1293,7 @@ public class FileUtils {
* @throws IOException if the given file object is not a directory.
*/
private static void doCopyDirectory(final File srcDir, final File destDir, final FileFilter fileFilter,
- final List<String> exclusionList, boolean preserveDirDate, final CopyOption... copyOptions) throws IOException {
+ final List<String> exclusionList, final boolean preserveDirDate, final CopyOption... copyOptions) throws IOException {
// recurse dirs, copy files.
final File[] srcFiles = listFiles(srcDir, fileFilter);
requireDirectoryIfExists(destDir, "destDir");
@@ -2005,7 +2005,7 @@ public class FileUtils {
* @throws IllegalArgumentException if directory does not exist or is not a directory.
* @throws IOException if an I/O error occurs.
*/
- private static File[] listFiles(final File directory, FileFilter fileFilter) throws IOException {
+ private static File[] listFiles(final File directory, final FileFilter fileFilter) throws IOException {
requireDirectoryExists(directory, "directory");
final File[] files = fileFilter == null ? directory.listFiles() : directory.listFiles(fileFilter);
if (files == null) {
@@ -2501,7 +2501,7 @@ public class FileUtils {
return readLines(file, Charsets.toCharset(charsetName));
}
- private static void requireAbsent(final File file, String name) throws FileExistsException {
+ private static void requireAbsent(final File file, final String name) throws FileExistsException {
if (file.exists()) {
throw new FileExistsException(
String.format("File element in parameter '%s' already exists: '%s'", name, file));
@@ -2533,7 +2533,7 @@ public class FileUtils {
* @throws NullPointerException if the given {@code File} is {@code null}.
* @throws IllegalArgumentException if the file is not writable.
*/
- private static void requireCanWrite(final File file, String name) {
+ private static void requireCanWrite(final File file, final String name) {
Objects.requireNonNull(file, "file");
if (!file.canWrite()) {
throw new IllegalArgumentException("File parameter '" + name + " is not writable: '" + file + "'");
@@ -2549,7 +2549,7 @@ public class FileUtils {
* @throws NullPointerException if the given {@code File} is {@code null}.
* @throws IllegalArgumentException if the given {@code File} does not exist or is not a directory.
*/
- private static File requireDirectory(final File directory, String name) {
+ private static File requireDirectory(final File directory, final String name) {
Objects.requireNonNull(directory, name);
if (!directory.isDirectory()) {
throw new IllegalArgumentException("Parameter '" + name + "' is not a directory: '" + directory + "'");
@@ -2566,7 +2566,7 @@ public class FileUtils {
* @throws NullPointerException if the given {@code File} is {@code null}.
* @throws IllegalArgumentException if the given {@code File} does not exist or is not a directory.
*/
- private static File requireDirectoryExists(final File directory, String name) {
+ private static File requireDirectoryExists(final File directory, final String name) {
requireExists(directory, name);
requireDirectory(directory, name);
return directory;
@@ -2581,7 +2581,7 @@ public class FileUtils {
* @throws NullPointerException if the given {@code File} is {@code null}.
* @throws IllegalArgumentException if the given {@code File} exists but is not a directory.
*/
- private static File requireDirectoryIfExists(final File directory, String name) {
+ private static File requireDirectoryIfExists(final File directory, final String name) {
Objects.requireNonNull(directory, name);
if (directory.exists()) {
requireDirectory(directory, name);
@@ -2615,7 +2615,7 @@ public class FileUtils {
* @throws NullPointerException if the given {@code File} is {@code null}.
* @throws IllegalArgumentException if the given {@code File} does not exist.
*/
- private static File requireExists(final File file, String fileParamName) {
+ private static File requireExists(final File file, final String fileParamName) {
Objects.requireNonNull(file, fileParamName);
if (!file.exists()) {
throw new IllegalArgumentException(
@@ -2633,7 +2633,7 @@ public class FileUtils {
* @throws NullPointerException if the given {@code File} is {@code null}.
* @throws FileNotFoundException if the given {@code File} does not exist.
*/
- private static File requireExistsChecked(final File file, String fileParamName) throws FileNotFoundException {
+ private static File requireExistsChecked(final File file, final String fileParamName) throws FileNotFoundException {
Objects.requireNonNull(file, fileParamName);
if (!file.exists()) {
throw new FileNotFoundException(
@@ -2651,7 +2651,7 @@ public class FileUtils {
* @throws NullPointerException if the given {@code File} is {@code null}.
* @throws IllegalArgumentException if the given {@code File} does not exist or is not a directory.
*/
- private static File requireFile(final File file, String name) {
+ private static File requireFile(final File file, final String name) {
Objects.requireNonNull(file, name);
if (!file.isFile()) {
throw new IllegalArgumentException("Parameter '" + name + "' is not a file: " + file);
@@ -2681,7 +2681,7 @@ public class FileUtils {
* @throws NullPointerException if the given {@code File} is {@code null}.
* @throws IllegalArgumentException if the given {@code File} does exists but is not a directory.
*/
- private static File requireFileIfExists(final File file, String name) {
+ private static File requireFileIfExists(final File file, final String name) {
Objects.requireNonNull(file, name);
return file.exists() ? requireFile(file, name) : file;
}
diff --git a/src/main/java/org/apache/commons/io/LineIterator.java b/src/main/java/org/apache/commons/io/LineIterator.java
index 0aa5bd0..49c3a01 100644
--- a/src/main/java/org/apache/commons/io/LineIterator.java
+++ b/src/main/java/org/apache/commons/io/LineIterator.java
@@ -56,7 +56,7 @@ public class LineIterator implements Iterator<String>, Closeable {
/** The current line. */
private String cachedLine;
/** A flag indicating if the iterator has been fully read. */
- private boolean finished = false;
+ private boolean finished;
/**
* Constructs an iterator of the lines for a {@code Reader}.
diff --git a/src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java b/src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java
index 206aaa9..b91bd14 100644
--- a/src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java
+++ b/src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java
@@ -165,7 +165,7 @@ public class DeletingPathVisitor extends CountingPathVisitor {
try {
// deleteIfExists does not work for this case
Files.delete(file);
- } catch (NoSuchFileException e) {
+ } catch (final NoSuchFileException e) {
// ignore
}
}
diff --git a/src/main/java/org/apache/commons/io/file/PathUtils.java b/src/main/java/org/apache/commons/io/file/PathUtils.java
index 809c708..5cba5b8 100644
--- a/src/main/java/org/apache/commons/io/file/PathUtils.java
+++ b/src/main/java/org/apache/commons/io/file/PathUtils.java
@@ -878,7 +878,7 @@ public final class PathUtils {
try {
fileAttributeView.setReadOnly(readOnly);
return path;
- } catch (IOException e) {
+ } catch (final IOException e) {
// ignore for now, retry with PosixFileAttributeView
causeList.add(e);
}
@@ -896,7 +896,7 @@ public final class PathUtils {
permissions.remove(PosixFilePermission.OTHERS_WRITE);
try {
return Files.setPosixFilePermissions(path, permissions);
- } catch (IOException e) {
+ } catch (final IOException e) {
causeList.add(e);
}
}
diff --git a/src/main/java/org/apache/commons/io/input/BoundedInputStream.java b/src/main/java/org/apache/commons/io/input/BoundedInputStream.java
index 3deaf74..031df87 100644
--- a/src/main/java/org/apache/commons/io/input/BoundedInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/BoundedInputStream.java
@@ -43,7 +43,7 @@ public class BoundedInputStream extends InputStream {
private final long max;
/** the number of bytes already returned */
- private long pos = 0;
+ private long pos;
/** the marked position */
private long mark = EOF;
diff --git a/src/main/java/org/apache/commons/io/input/BoundedReader.java b/src/main/java/org/apache/commons/io/input/BoundedReader.java
index a1b5379..8bb6845 100644
--- a/src/main/java/org/apache/commons/io/input/BoundedReader.java
+++ b/src/main/java/org/apache/commons/io/input/BoundedReader.java
@@ -38,7 +38,7 @@ public class BoundedReader extends Reader {
private final Reader target;
- private int charsRead = 0;
+ private int charsRead;
private int markedAt = INVALID;
diff --git a/src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java b/src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java
index a2c95f6..67ff54a 100644
--- a/src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java
@@ -214,9 +214,7 @@ public final class BufferedFileChannelInputStream extends InputStream {
nRead = fileChannel.read(byteBuffer);
}
byteBuffer.flip();
- if (nRead < 0) {
- return false;
- }
+ return nRead >= 0;
}
return true;
}
diff --git a/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java b/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
index 7ed1839..42d72d4 100644
--- a/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
@@ -30,11 +30,11 @@ import java.io.InputStream;
*/
public class UnixLineEndingInputStream extends InputStream {
- private boolean slashNSeen = false;
+ private boolean slashNSeen;
- private boolean slashRSeen = false;
+ private boolean slashRSeen;
- private boolean eofSeen = false;
+ private boolean eofSeen;
private final InputStream target;
diff --git a/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java b/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java
index 0a8c186..b557026 100644
--- a/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java
@@ -30,13 +30,13 @@ import java.io.InputStream;
*/
public class WindowsLineEndingInputStream extends InputStream {
- private boolean slashRSeen = false;
+ private boolean slashRSeen;
- private boolean slashNSeen = false;
+ private boolean slashNSeen;
- private boolean injectSlashN = false;
+ private boolean injectSlashN;
- private boolean eofSeen = false;
+ private boolean eofSeen;
private final InputStream target;
diff --git a/src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java b/src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java
index 3be7fc6..48fceac 100644
--- a/src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java
+++ b/src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java
@@ -31,9 +31,9 @@ public final class FileAlterationMonitor implements Runnable {
private final long interval;
private final List<FileAlterationObserver> observers = new CopyOnWriteArrayList<>();
- private Thread thread = null;
+ private Thread thread;
private ThreadFactory threadFactory;
- private volatile boolean running = false;
+ private volatile boolean running;
/**
* Constructs a monitor with a default interval of 10 seconds.
diff --git a/src/main/java/org/apache/commons/io/output/CountingOutputStream.java b/src/main/java/org/apache/commons/io/output/CountingOutputStream.java
index 341c98d..f27e7ff 100644
--- a/src/main/java/org/apache/commons/io/output/CountingOutputStream.java
+++ b/src/main/java/org/apache/commons/io/output/CountingOutputStream.java
@@ -29,7 +29,7 @@ import java.io.OutputStream;
public class CountingOutputStream extends ProxyOutputStream {
/** The count of bytes that have passed. */
- private long count = 0;
+ private long count;
/**
* Constructs a new CountingOutputStream.
diff --git a/src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java b/src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java
index 05ae327..8e934f4 100644
--- a/src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java
+++ b/src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java
@@ -69,7 +69,7 @@ public class DeferredFileOutputStream extends ThresholdingOutputStream {
/**
* True when close() has been called successfully.
*/
- private boolean closed = false;
+ private boolean closed;
/**
* Constructs an instance of this class which will trigger an event at the specified threshold, and save data to a
diff --git a/src/main/java/org/apache/commons/io/output/QueueOutputStream.java b/src/main/java/org/apache/commons/io/output/QueueOutputStream.java
index e1af097..b5968d6 100644
--- a/src/main/java/org/apache/commons/io/output/QueueOutputStream.java
+++ b/src/main/java/org/apache/commons/io/output/QueueOutputStream.java
@@ -91,7 +91,7 @@ public class QueueOutputStream extends OutputStream {
public void write(final int b) throws InterruptedIOException {
try {
blockingQueue.put(0xFF & b);
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
Thread.currentThread().interrupt();
final InterruptedIOException interruptedIoException = new InterruptedIOException();
interruptedIoException.initCause(e);
diff --git a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
index 8e8a8c0..ed7375f 100644
--- a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
@@ -99,9 +99,9 @@ public class IOUtilsTestCase {
@TempDir
public File temporaryFolder;
- private char[] carr = null;
+ private char[] carr;
- private byte[] iarr = null;
+ private byte[] iarr;
private File m_testFile;
diff --git a/src/test/java/org/apache/commons/io/input/ObservableInputStreamTest.java b/src/test/java/org/apache/commons/io/input/ObservableInputStreamTest.java
index aa5edea..adde785 100644
--- a/src/test/java/org/apache/commons/io/input/ObservableInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/ObservableInputStreamTest.java
@@ -53,7 +53,7 @@ public class ObservableInputStreamTest {
}
private static class LastBytesKeepingObserver extends Observer {
- private byte[] buffer = null;
+ private byte[] buffer;
private int offset = -1;
private int length = -1;
diff --git a/src/test/java/org/apache/commons/io/input/TailerTest.java b/src/test/java/org/apache/commons/io/input/TailerTest.java
index 14176cd..268d514 100644
--- a/src/test/java/org/apache/commons/io/input/TailerTest.java
+++ b/src/test/java/org/apache/commons/io/input/TailerTest.java
@@ -438,15 +438,15 @@ public class TailerTest {
// Must be synchronized because it is written by one thread and read by another
private final List<String> lines = Collections.synchronizedList(new ArrayList<String>());
- volatile Exception exception = null;
+ volatile Exception exception;
- volatile int notFound = 0;
+ volatile int notFound;
- volatile int rotated = 0;
+ volatile int rotated;
- volatile int initialized = 0;
+ volatile int initialized;
- volatile int reachedEndOfFile = 0;
+ volatile int reachedEndOfFile;
@Override
public void handle(final String line) {
diff --git a/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReader.java b/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReader.java
index 1b01e74..ed3d0ca 100644
--- a/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReader.java
+++ b/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReader.java
@@ -83,7 +83,7 @@ public class XmlStreamReader extends Reader {
private static final String EBCDIC = "CP1047";
- private static String staticDefaultEncoding = null;
+ private static String staticDefaultEncoding;
private Reader reader;