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
commit 6aaf6f581f63e4de59cb1355197dd452a47c0c2e Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Sat Sep 18 10:47:33 2021 -0400 Javadoc and refactor to FileTimes.now(). Reuse own APIs. --- .../java/org/apache/commons/io/FileSystem.java | 3 +- .../org/apache/commons/io/FileSystemUtils.java | 6 +- src/main/java/org/apache/commons/io/FileUtils.java | 3 +- .../io/comparator/AbstractFileComparator.java | 14 ++-- .../io/comparator/CompositeFileComparator.java | 12 +-- .../io/comparator/DefaultFileComparator.java | 4 +- .../io/comparator/DirectoryFileComparator.java | 24 +++--- .../io/comparator/ExtensionFileComparator.java | 6 +- .../commons/io/comparator/NameFileComparator.java | 6 +- .../commons/io/comparator/PathFileComparator.java | 6 +- .../io/comparator/ReverseFileComparator.java | 2 +- .../commons/io/comparator/SizeFileComparator.java | 7 +- .../commons/io/file/AccumulatorPathVisitor.java | 2 +- .../java/org/apache/commons/io/file/PathUtils.java | 85 +++++++++------------- .../commons/io/file/attribute/FileTimes.java | 24 +++++- .../commons/io/filefilter/AgeFileFilter.java | 13 ++-- .../io/filefilter/CanExecuteFileFilter.java | 4 +- .../commons/io/filefilter/CanReadFileFilter.java | 6 +- .../commons/io/filefilter/CanWriteFileFilter.java | 4 +- .../commons/io/filefilter/DirectoryFileFilter.java | 4 +- .../commons/io/filefilter/EmptyFileFilter.java | 6 +- .../commons/io/filefilter/FileFileFilter.java | 4 +- .../commons/io/filefilter/HiddenFileFilter.java | 6 +- .../io/filefilter/MagicNumberFileFilter.java | 6 +- .../commons/io/filefilter/NameFileFilter.java | 4 +- .../commons/io/filefilter/PrefixFileFilter.java | 4 +- .../commons/io/filefilter/RegexFileFilter.java | 4 +- .../commons/io/filefilter/SizeFileFilter.java | 4 +- .../commons/io/filefilter/SuffixFileFilter.java | 4 +- .../io/filefilter/SymbolicLinkFileFilter.java | 4 +- .../commons/io/filefilter/WildcardFileFilter.java | 4 +- .../commons/io/filefilter/WildcardFilter.java | 4 +- .../apache/commons/io/input/BrokenInputStream.java | 6 +- .../org/apache/commons/io/input/BrokenReader.java | 4 +- .../apache/commons/io/input/ClosedInputStream.java | 4 +- .../org/apache/commons/io/input/ClosedReader.java | 4 +- .../commons/io/monitor/FileAlterationObserver.java | 2 +- .../io/output/AbstractByteArrayOutputStream.java | 8 +- .../org/apache/commons/io/output/BrokenWriter.java | 6 +- .../commons/io/output/ClosedOutputStream.java | 2 +- .../org/apache/commons/io/output/ClosedWriter.java | 2 +- .../apache/commons/io/output/NullOutputStream.java | 2 +- .../apache/commons/io/output/NullPrintStream.java | 2 +- .../org/apache/commons/io/output/NullWriter.java | 2 +- .../apache/commons/io/DirectoryWalkerTestCase.java | 4 +- .../commons/io/DirectoryWalkerTestCaseJava4.java | 4 +- .../commons/io/FileUtilsFileNewerTestCase.java | 1 - .../org/apache/commons/io/FileUtilsTestCase.java | 2 +- .../apache/commons/io/LineIteratorTestCase.java | 2 - .../io/comparator/DirectoryFileComparatorTest.java | 3 +- .../io/comparator/SizeFileComparatorTest.java | 3 +- .../commons/io/filefilter/AgeFileFilterTest.java | 3 +- .../io/filefilter/DirectoryFileFilterTest.java | 3 +- .../commons/io/filefilter/NameFileFilterTest.java | 3 +- .../io/output/DeferredFileOutputStreamTest.java | 7 +- 55 files changed, 189 insertions(+), 179 deletions(-) diff --git a/src/main/java/org/apache/commons/io/FileSystem.java b/src/main/java/org/apache/commons/io/FileSystem.java index bdccf82..2e76a79 100644 --- a/src/main/java/org/apache/commons/io/FileSystem.java +++ b/src/main/java/org/apache/commons/io/FileSystem.java @@ -288,6 +288,7 @@ public enum FileSystem { /** * Gets the name separator, '\\' on Windows, '/' on Linux. + * * @return '\\' on Windows, '/' on Linux. * * @since 2.12.0 @@ -372,7 +373,7 @@ public enum FileSystem { /** * Converts all separators to the Windows separator of backslash. * - * @param path the path to be changed, null ignored + * @param path the path to be changed, null ignored * @return the updated path * @since 2.12.0 */ diff --git a/src/main/java/org/apache/commons/io/FileSystemUtils.java b/src/main/java/org/apache/commons/io/FileSystemUtils.java index 9625035..8017ad0 100644 --- a/src/main/java/org/apache/commons/io/FileSystemUtils.java +++ b/src/main/java/org/apache/commons/io/FileSystemUtils.java @@ -212,7 +212,7 @@ public class FileSystemUtils { * <p> * Identical to: * <pre> - * freeSpaceKb(new File(".").getAbsolutePath()) + * freeSpaceKb(FileUtils.current().getAbsolutePath()) * </pre> * @return the amount of free drive space on the drive or volume in kilobytes * @throws IllegalStateException if an error occurred in initialisation @@ -231,7 +231,7 @@ public class FileSystemUtils { * <p> * Identical to: * <pre> - * freeSpaceKb(new File(".").getAbsolutePath()) + * freeSpaceKb(FileUtils.current().getAbsolutePath()) * </pre> * @param timeout The timeout amount in milliseconds or no timeout if the value * is zero or less @@ -243,7 +243,7 @@ public class FileSystemUtils { */ @Deprecated public static long freeSpaceKb(final long timeout) throws IOException { - return freeSpaceKb(new File(".").getAbsolutePath(), timeout); + return freeSpaceKb(FileUtils.current().getAbsolutePath(), timeout); } /** diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java index 79e211f..7cd7e9a 100644 --- a/src/main/java/org/apache/commons/io/FileUtils.java +++ b/src/main/java/org/apache/commons/io/FileUtils.java @@ -69,6 +69,7 @@ import org.apache.commons.io.file.Counters; import org.apache.commons.io.file.PathFilter; import org.apache.commons.io.file.PathUtils; import org.apache.commons.io.file.StandardDeleteOption; +import org.apache.commons.io.file.attribute.FileTimes; import org.apache.commons.io.filefilter.FileEqualsFileFilter; import org.apache.commons.io.filefilter.FileFileFilter; import org.apache.commons.io.filefilter.IOFileFilter; @@ -3152,7 +3153,7 @@ public class FileUtils { if (!file.exists()) { newOutputStream(file, false).close(); } - PathUtils.setLastModifiedTime(file.toPath()); + FileTimes.setLastModifiedTime(file.toPath()); } /** diff --git a/src/main/java/org/apache/commons/io/comparator/AbstractFileComparator.java b/src/main/java/org/apache/commons/io/comparator/AbstractFileComparator.java index 0f12ab3..52cb526 100644 --- a/src/main/java/org/apache/commons/io/comparator/AbstractFileComparator.java +++ b/src/main/java/org/apache/commons/io/comparator/AbstractFileComparator.java @@ -30,13 +30,13 @@ import java.util.List; abstract class AbstractFileComparator implements Comparator<File> { /** - * Sort an array of files. + * Sorts an array of files. * <p> * This method uses {@link Arrays#sort(Object[], Comparator)} and returns the original array. * </p> * - * @param files The files to sort, may be null - * @return The sorted array + * @param files The files to sort, may be null. + * @return The sorted array. * @since 2.0 */ public File[] sort(final File... files) { @@ -47,13 +47,13 @@ abstract class AbstractFileComparator implements Comparator<File> { } /** - * Sort a List of files. + * Sorts a List of files. * <p> * This method uses {@link Collections#sort(List, Comparator)} and returns the original list. * </p> * - * @param files The files to sort, may be null - * @return The sorted list + * @param files The files to sort, may be null. + * @return The sorted list. * @since 2.0 */ public List<File> sort(final List<File> files) { @@ -66,7 +66,7 @@ abstract class AbstractFileComparator implements Comparator<File> { /** * String representation of this file comparator. * - * @return String representation of this file comparator + * @return String representation of this file comparator. */ @Override public String toString() { diff --git a/src/main/java/org/apache/commons/io/comparator/CompositeFileComparator.java b/src/main/java/org/apache/commons/io/comparator/CompositeFileComparator.java index 17b4ff0..a32d7a7 100644 --- a/src/main/java/org/apache/commons/io/comparator/CompositeFileComparator.java +++ b/src/main/java/org/apache/commons/io/comparator/CompositeFileComparator.java @@ -45,18 +45,18 @@ public class CompositeFileComparator extends AbstractFileComparator implements S private static final Comparator<?>[] EMPTY_COMPARATOR_ARRAY = {}; private static final long serialVersionUID = -2224170307287243428L; - private static final Comparator<?>[] NO_COMPARATORS = {}; + private final Comparator<File>[] delegates; /** - * Create a composite comparator for the set of delegate comparators. + * Constructs a composite comparator for the set of delegate comparators. * * @param delegates The delegate file comparators */ @SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct public CompositeFileComparator(final Comparator<File>... delegates) { if (delegates == null) { - this.delegates = (Comparator<File>[]) NO_COMPARATORS;//1 + this.delegates = (Comparator<File>[]) EMPTY_COMPARATOR_ARRAY;//1 } else { this.delegates = (Comparator<File>[]) new Comparator<?>[delegates.length];//2 System.arraycopy(delegates, 0, this.delegates, 0, delegates.length); @@ -64,14 +64,14 @@ public class CompositeFileComparator extends AbstractFileComparator implements S } /** - * Create a composite comparator for the set of delegate comparators. + * Constructs a composite comparator for the set of delegate comparators. * * @param delegates The delegate file comparators */ @SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct public CompositeFileComparator(final Iterable<Comparator<File>> delegates) { if (delegates == null) { - this.delegates = (Comparator<File>[]) NO_COMPARATORS; //1 + this.delegates = (Comparator<File>[]) EMPTY_COMPARATOR_ARRAY; //1 } else { final List<Comparator<File>> list = new ArrayList<>(); for (final Comparator<File> comparator : delegates) { @@ -82,7 +82,7 @@ public class CompositeFileComparator extends AbstractFileComparator implements S } /** - * Compare the two files using delegate comparators. + * Compares the two files using delegate comparators. * * @param file1 The first file to compare * @param file2 The second file to compare diff --git a/src/main/java/org/apache/commons/io/comparator/DefaultFileComparator.java b/src/main/java/org/apache/commons/io/comparator/DefaultFileComparator.java index e85a1f8..88be4e0 100644 --- a/src/main/java/org/apache/commons/io/comparator/DefaultFileComparator.java +++ b/src/main/java/org/apache/commons/io/comparator/DefaultFileComparator.java @@ -21,7 +21,7 @@ import java.io.Serializable; import java.util.Comparator; /** - * Compare two files using the <b>default</b> {@link File#compareTo(File)} method. + * s two files using the <b>default</b> {@link File#compareTo(File)} method. * <p> * This comparator can be used to sort lists or arrays of files * by using the default file comparison. @@ -56,7 +56,7 @@ public class DefaultFileComparator extends AbstractFileComparator implements Ser public static final Comparator<File> DEFAULT_REVERSE = new ReverseFileComparator(DEFAULT_COMPARATOR); /** - * Compare the two files using the {@link File#compareTo(File)} method. + * Compares the two files using the {@link File#compareTo(File)} method. * * @param file1 The first file to compare * @param file2 The second file to compare diff --git a/src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java b/src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java index b72ed86..e563531 100644 --- a/src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java +++ b/src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java @@ -26,17 +26,18 @@ import java.util.Comparator; * This comparator can be used to sort lists or arrays by directories and files. * </p> * <p> - * Example of sorting a list of files/directories using the - * {@link #DIRECTORY_COMPARATOR} singleton instance: + * Example of sorting a list of files/directories using the {@link #DIRECTORY_COMPARATOR} singleton instance: * </p> + * * <pre> * List<File> list = ... * ((AbstractFileComparator) DirectoryFileComparator.DIRECTORY_COMPARATOR).sort(list); * </pre> * <p> - * Example of doing a <i>reverse</i> sort of an array of files/directories using the - * {@link #DIRECTORY_REVERSE} singleton instance: + * Example of doing a <i>reverse</i> sort of an array of files/directories using the {@link #DIRECTORY_REVERSE} + * singleton instance: * </p> + * * <pre> * File[] array = ... * ((AbstractFileComparator) DirectoryFileComparator.DIRECTORY_REVERSE).sort(array); @@ -59,12 +60,11 @@ public class DirectoryFileComparator extends AbstractFileComparator implements S public static final Comparator<File> DIRECTORY_REVERSE = new ReverseFileComparator(DIRECTORY_COMPARATOR); /** - * Compare the two files using the {@link File#isDirectory()} method. + * Compares the two files using the {@link File#isDirectory()} method. * - * @param file1 The first file to compare - * @param file2 The second file to compare - * @return the result of calling file1's - * {@link File#compareTo(File)} with file2 as the parameter. + * @param file1 The first file to compare. + * @param file2 The second file to compare. + * @return the result of calling file1's {@link File#compareTo(File)} with file2 as the parameter. */ @Override public int compare(final File file1, final File file2) { @@ -72,10 +72,10 @@ public class DirectoryFileComparator extends AbstractFileComparator implements S } /** - * Convert type to numeric value. + * Converts type to numeric value. * - * @param file The file - * @return 1 for directories and 2 for files + * @param file The file. + * @return 1 for directories and 2 for files. */ private int getType(final File file) { return file.isDirectory() ? TYPE_DIRECTORY : TYPE_FILE; diff --git a/src/main/java/org/apache/commons/io/comparator/ExtensionFileComparator.java b/src/main/java/org/apache/commons/io/comparator/ExtensionFileComparator.java index 1e3edad..c0a834e 100644 --- a/src/main/java/org/apache/commons/io/comparator/ExtensionFileComparator.java +++ b/src/main/java/org/apache/commons/io/comparator/ExtensionFileComparator.java @@ -80,14 +80,14 @@ public class ExtensionFileComparator extends AbstractFileComparator implements S private final IOCase caseSensitivity; /** - * Construct a case sensitive file extension comparator instance. + * Constructs a case sensitive file extension comparator instance. */ public ExtensionFileComparator() { this.caseSensitivity = IOCase.SENSITIVE; } /** - * Construct a file extension comparator instance with the specified case-sensitivity. + * Constructs a file extension comparator instance with the specified case-sensitivity. * * @param caseSensitivity how to handle case sensitivity, null means case-sensitive */ @@ -96,7 +96,7 @@ public class ExtensionFileComparator extends AbstractFileComparator implements S } /** - * Compare the extensions of two files the specified case sensitivity. + * Compares the extensions of two files the specified case sensitivity. * * @param file1 The first file to compare * @param file2 The second file to compare diff --git a/src/main/java/org/apache/commons/io/comparator/NameFileComparator.java b/src/main/java/org/apache/commons/io/comparator/NameFileComparator.java index 898e227..7fa5603 100644 --- a/src/main/java/org/apache/commons/io/comparator/NameFileComparator.java +++ b/src/main/java/org/apache/commons/io/comparator/NameFileComparator.java @@ -76,14 +76,14 @@ public class NameFileComparator extends AbstractFileComparator implements Serial private final IOCase caseSensitivity; /** - * Construct a case sensitive file name comparator instance. + * Constructs a case sensitive file name comparator instance. */ public NameFileComparator() { this.caseSensitivity = IOCase.SENSITIVE; } /** - * Construct a file name comparator instance with the specified case-sensitivity. + * Constructs a file name comparator instance with the specified case-sensitivity. * * @param caseSensitivity how to handle case sensitivity, null means case-sensitive */ @@ -92,7 +92,7 @@ public class NameFileComparator extends AbstractFileComparator implements Serial } /** - * Compare the names of two files with the specified case sensitivity. + * Compares the names of two files with the specified case sensitivity. * * @param file1 The first file to compare * @param file2 The second file to compare diff --git a/src/main/java/org/apache/commons/io/comparator/PathFileComparator.java b/src/main/java/org/apache/commons/io/comparator/PathFileComparator.java index bb8e13d..f350d58 100644 --- a/src/main/java/org/apache/commons/io/comparator/PathFileComparator.java +++ b/src/main/java/org/apache/commons/io/comparator/PathFileComparator.java @@ -76,14 +76,14 @@ public class PathFileComparator extends AbstractFileComparator implements Serial private final IOCase caseSensitivity; /** - * Construct a case sensitive file path comparator instance. + * Constructs a case sensitive file path comparator instance. */ public PathFileComparator() { this.caseSensitivity = IOCase.SENSITIVE; } /** - * Construct a file path comparator instance with the specified case-sensitivity. + * Constructs a file path comparator instance with the specified case-sensitivity. * * @param caseSensitivity how to handle case sensitivity, null means case-sensitive */ @@ -92,7 +92,7 @@ public class PathFileComparator extends AbstractFileComparator implements Serial } /** - * Compare the paths of two files the specified case sensitivity. + * Compares the paths of two files the specified case sensitivity. * * @param file1 The first file to compare * @param file2 The second file to compare diff --git a/src/main/java/org/apache/commons/io/comparator/ReverseFileComparator.java b/src/main/java/org/apache/commons/io/comparator/ReverseFileComparator.java index d0ddcc2..c5315fe 100644 --- a/src/main/java/org/apache/commons/io/comparator/ReverseFileComparator.java +++ b/src/main/java/org/apache/commons/io/comparator/ReverseFileComparator.java @@ -31,7 +31,7 @@ class ReverseFileComparator extends AbstractFileComparator implements Serializab private final Comparator<File> delegate; /** - * Construct an instance with the specified delegate {@link Comparator}. + * Constructs an instance with the specified delegate {@link Comparator}. * * @param delegate The comparator to delegate to. */ diff --git a/src/main/java/org/apache/commons/io/comparator/SizeFileComparator.java b/src/main/java/org/apache/commons/io/comparator/SizeFileComparator.java index ef15003..0ee5e4a 100644 --- a/src/main/java/org/apache/commons/io/comparator/SizeFileComparator.java +++ b/src/main/java/org/apache/commons/io/comparator/SizeFileComparator.java @@ -74,18 +74,19 @@ public class SizeFileComparator extends AbstractFileComparator implements Serial private final boolean sumDirectoryContents; /** - * Construct a file size comparator instance (directories treated as zero size). + * Constructs a file size comparator instance (directories treated as zero size). */ public SizeFileComparator() { this.sumDirectoryContents = false; } /** - * Construct a file size comparator instance specifying whether the size of + * Constructs a file size comparator instance specifying whether the size of * the directory contents should be aggregated. * <p> * If the {@code sumDirectoryContents} is {@code true} The size of * directories is calculated using {@link FileUtils#sizeOfDirectory(File)}. + * </p> * * @param sumDirectoryContents {@code true} if the sum of the directories' contents * should be calculated, otherwise {@code false} if directories should be treated @@ -96,7 +97,7 @@ public class SizeFileComparator extends AbstractFileComparator implements Serial } /** - * Compare the length of two files. + * Compares the length of two files. * * @param file1 The first file to compare * @param file2 The second file to compare diff --git a/src/main/java/org/apache/commons/io/file/AccumulatorPathVisitor.java b/src/main/java/org/apache/commons/io/file/AccumulatorPathVisitor.java index 3877db5..5da6e70 100644 --- a/src/main/java/org/apache/commons/io/file/AccumulatorPathVisitor.java +++ b/src/main/java/org/apache/commons/io/file/AccumulatorPathVisitor.java @@ -35,7 +35,7 @@ import org.apache.commons.io.file.Counters.PathCounters; * <h2>Example</h2> * * <pre> - * Path dir = Paths.get(""); + * Path dir = PathUtils.current(); * // We are interested in files older than one day * Instant cutoff = Instant.now().minus(Duration.ofDays(1)); * AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new AgeFileFilter(cutoff)); 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 ac42725..7a573ee 100644 --- a/src/main/java/org/apache/commons/io/file/PathUtils.java +++ b/src/main/java/org/apache/commons/io/file/PathUtils.java @@ -79,6 +79,10 @@ import org.apache.commons.io.filefilter.IOFileFilter; */ public final class PathUtils { + private static final OpenOption[] OPEN_OPTIONS_TRUNCATE = new OpenOption[] {StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING}; + + private static final OpenOption[] OPEN_OPTIONS_APPEND = new OpenOption[] {StandardOpenOption.CREATE, StandardOpenOption.APPEND}; + /** * Private worker/holder that computes and tracks relative path names and their equality. We reuse the sorted relative * lists when comparing directories. @@ -222,14 +226,14 @@ public final class PathUtils { } /** - * Compares the specified {@code Path}'s last modified time to the given file time. + * Compares the given {@code Path}'s last modified time to the given file time. * * @param file the {@code Path} to test. * @param fileTime the time reference. * @param options options indicating how to handle symbolic links. * @return See {@link FileTime#compareTo(FileTime)} * @throws IOException if an I/O error occurs. - * @throws NullPointerException if the file is {@code null} + * @throws NullPointerException if the file is {@code null}. */ private static int compareLastModifiedTimeTo(final Path file, final FileTime fileTime, final LinkOption... options) throws IOException { return getLastModifiedTime(file, options).compareTo(fileTime); @@ -343,7 +347,7 @@ public final class PathUtils { * @since 2.9.0 */ public static Path current() { - return Paths.get(""); + return Paths.get("."); } /** @@ -720,7 +724,7 @@ public final class PathUtils { * Reads the access control list from a file attribute view. * * @param sourcePath the path to the file. - * @return a file attribute view of the specified type, or null if the attribute view type is not available. + * @return a file attribute view of the given type, or null if the attribute view type is not available. * @throws IOException if an I/O error occurs. * @since 2.8.0 */ @@ -737,7 +741,6 @@ public final class PathUtils { * Gets a {@link Path} representing the system temporary directory. * * @return the system temporary directory. - * * @since 2.12.0 */ public static Path getTempDirectory() { @@ -745,7 +748,7 @@ public final class PathUtils { } /** - * Tests whether the specified {@code Path} is a directory or not. Implemented as a null-safe delegate to + * Tests whether the given {@code Path} is a directory or not. Implemented as a null-safe delegate to * {@code Files.isDirectory(Path path, LinkOption... options)}. * * @param path the path to the file. @@ -802,14 +805,14 @@ public final class PathUtils { } /** - * Tests if the specified {@code Path} is newer than the specified time reference. + * Tests if the given {@code Path} is newer than the given time reference. * * @param file the {@code Path} to test. * @param czdt the time reference. * @param options options indicating how to handle symbolic links. * @return true if the {@code Path} exists and has been modified after the given time reference. * @throws IOException if an I/O error occurs. - * @throws NullPointerException if the file is {@code null} + * @throws NullPointerException if the file is {@code null}. * @since 2.12.0 */ public static boolean isNewer(final Path file, final ChronoZonedDateTime<?> czdt, final LinkOption... options) throws IOException { @@ -818,14 +821,14 @@ public final class PathUtils { } /** - * Tests if the specified {@code Path} is newer than the specified time reference. + * Tests if the given {@code Path} is newer than the given time reference. * * @param file the {@code Path} to test. * @param fileTime the time reference. * @param options options indicating how to handle symbolic links. * @return true if the {@code Path} exists and has been modified after the given time reference. * @throws IOException if an I/O error occurs. - * @throws NullPointerException if the file is {@code null} + * @throws NullPointerException if the file is {@code null}. * @since 2.12.0 */ public static boolean isNewer(final Path file, final FileTime fileTime, final LinkOption... options) throws IOException { @@ -836,14 +839,14 @@ public final class PathUtils { } /** - * Tests if the specified {@code Path} is newer than the specified time reference. + * Tests if the given {@code Path} is newer than the given time reference. * * @param file the {@code Path} to test. * @param instant the time reference. * @param options options indicating how to handle symbolic links. * @return true if the {@code Path} exists and has been modified after the given time reference. * @throws IOException if an I/O error occurs. - * @throws NullPointerException if the file is {@code null} + * @throws NullPointerException if the file is {@code null}. * @since 2.12.0 */ public static boolean isNewer(final Path file, final Instant instant, final LinkOption... options) throws IOException { @@ -851,14 +854,14 @@ public final class PathUtils { } /** - * Tests if the specified {@code Path} is newer than the specified time reference. + * Tests if the given {@code Path} is newer than the given time reference. * * @param file the {@code Path} to test. * @param timeMillis the time reference measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970) * @param options options indicating how to handle symbolic links. * @return true if the {@code Path} exists and has been modified after the given time reference. * @throws IOException if an I/O error occurs. - * @throws NullPointerException if the file is {@code null} + * @throws NullPointerException if the file is {@code null}. * @since 2.9.0 */ public static boolean isNewer(final Path file, final long timeMillis, final LinkOption... options) throws IOException { @@ -866,7 +869,7 @@ public final class PathUtils { } /** - * Tests if the specified {@code Path} is newer than the reference {@code Path}. + * Tests if the given {@code Path} is newer than the reference {@code Path}. * * @param file the {@code File} to test. * @param reference the {@code File} of which the modification date is used. @@ -880,14 +883,14 @@ public final class PathUtils { } /** - * Tests if the specified {@code Path} is older than the specified time reference. + * Tests if the given {@code Path} is older than the given time reference. * * @param file the {@code Path} to test. * @param fileTime the time reference. * @param options options indicating how to handle symbolic links. * @return true if the {@code Path} exists and has been modified before the given time reference. * @throws IOException if an I/O error occurs. - * @throws NullPointerException if the file is {@code null} + * @throws NullPointerException if the file is {@code null}. * @since 2.12.0 */ public static boolean isOlder(final Path file, final FileTime fileTime, final LinkOption... options) throws IOException { @@ -898,14 +901,14 @@ public final class PathUtils { } /** - * Tests if the specified {@code Path} is older than the specified time reference. + * Tests if the given {@code Path} is older than the given time reference. * * @param file the {@code Path} to test. * @param instant the time reference. * @param options options indicating how to handle symbolic links. - * @return true if the {@code Path} exists and has been modified after the given time reference. + * @return true if the {@code Path} exists and has been modified before the given time reference. * @throws IOException if an I/O error occurs. - * @throws NullPointerException if the file is {@code null} + * @throws NullPointerException if the file is {@code null}. * @since 2.12.0 */ public static boolean isOlder(final Path file, final Instant instant, final LinkOption... options) throws IOException { @@ -913,14 +916,14 @@ public final class PathUtils { } /** - * Tests if the specified {@code Path} is older than the specified time reference. + * Tests if the given {@code Path} is older than the given time reference. * * @param file the {@code Path} to test. * @param timeMillis the time reference measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970) * @param options options indicating how to handle symbolic links. * @return true if the {@code Path} exists and has been modified before the given time reference. * @throws IOException if an I/O error occurs. - * @throws NullPointerException if the file is {@code null} + * @throws NullPointerException if the file is {@code null}. * @since 2.12.0 */ public static boolean isOlder(final Path file, final long timeMillis, final LinkOption... options) throws IOException { @@ -928,7 +931,7 @@ public final class PathUtils { } /** - * Tests if the specified {@code Path} is older than the reference {@code Path}. + * Tests if the given {@code Path} is older than the reference {@code Path}. * * @param file the {@code File} to test. * @param reference the {@code File} of which the modification date is used. @@ -942,7 +945,7 @@ public final class PathUtils { /** - * Tests whether the specified {@code Path} is a regular file or not. Implemented as a null-safe delegate to + * Tests whether the given {@code Path} is a regular file or not. Implemented as a null-safe delegate to * {@code Files.isRegularFile(Path path, LinkOption... options)}. * * @param path the path to the file. @@ -988,11 +991,7 @@ public final class PathUtils { } else { createParentDirectories(path); } - // @formatter:off - return Files.newOutputStream(path, append ? - new OpenOption[] {StandardOpenOption.CREATE, StandardOpenOption.APPEND} : - new OpenOption[] {StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING}); - // @formatter:on + return Files.newOutputStream(path, append ? OPEN_OPTIONS_APPEND : OPEN_OPTIONS_TRUNCATE); } private static boolean notExists(final Path path, final LinkOption... options) { @@ -1124,17 +1123,6 @@ public final class PathUtils { } /** - * Sets the last modified time of the given file path to now. - * - * @param path The file path to set. - * @throws IOException if an I/O error occurs. - * @since 2.12.0 - */ - public static void setLastModifiedTime(final Path path) throws IOException { - Files.setLastModifiedTime(path, FileTime.from(Instant.now())); - } - - /** * Sets the given {@code targetFile}'s last modified time to the value from {@code sourceFile}. * * @param sourceFile The source path to query. @@ -1197,15 +1185,15 @@ public final class PathUtils { } /** - * Returns the size of the specified file or directory. If the provided {@link File} is a regular file, then the file's - * length is returned. If the argument is a directory, then the size of the directory is calculated recursively. + * Returns the size of the given file or directory. If the provided {@link Path} is a regular file, then the file's size + * is returned. If the argument is a directory, then the size of the directory is calculated recursively. * <p> * Note that overflow is not detected, and the return value may be negative if overflow occurs. See * {@link #sizeOfAsBigInteger(Path)} for an alternative method that does not overflow. * </p> * - * @param path the regular file or directory to return the size of (must not be {@code null}). - * @return the length of the file, or recursive size of the directory, provided (in bytes). + * @param path the regular file or directory to return the size of, must not be {@code null}. + * @return the length of the file, or recursive size of the directory, in bytes. * @throws NullPointerException if the file is {@code null}. * @throws IllegalArgumentException if the file does not exist. * @throws IOException if an I/O error occurs. @@ -1217,9 +1205,8 @@ public final class PathUtils { } /** - * Returns the size of the specified file or directory. If the provided {@link Path} is a regular file, then the file's - * length is returned. If the argument is a directory, then the size of the directory is calculated recursively. If a - * directory or subdirectory is security restricted, its size will not be included. + * Returns the size of the given file or directory. If the provided {@link Path} is a regular file, then the file's size + * is returned. If the argument is a directory, then the size of the directory is calculated recursively. * * @param path the regular file or directory to return the size of (must not be {@code null}). * @return the length of the file, or recursive size of the directory, provided (in bytes). @@ -1349,7 +1336,7 @@ public final class PathUtils { * Waits for the file system to propagate a file creation, with a timeout. * <p> * This method repeatedly tests {@link Files#exists(Path,LinkOption...)} until it returns true up to the maximum time - * specified. + * given. * </p> * * @param file the file to check, must not be {@code null}. @@ -1383,7 +1370,7 @@ public final class PathUtils { Thread.currentThread().interrupt(); } } - return Files.exists(file, options); + return exists(file, options); } /** diff --git a/src/main/java/org/apache/commons/io/file/attribute/FileTimes.java b/src/main/java/org/apache/commons/io/file/attribute/FileTimes.java index ed7a141..d7e2cec 100644 --- a/src/main/java/org/apache/commons/io/file/attribute/FileTimes.java +++ b/src/main/java/org/apache/commons/io/file/attribute/FileTimes.java @@ -17,6 +17,9 @@ package org.apache.commons.io.file.attribute; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.attribute.FileTime; import java.time.Instant; @@ -28,7 +31,7 @@ import java.time.Instant; public class FileTimes { /** - * Constant for the {@code 1970-01-01T00:00:00Z} epoch as a time stamp attribute. + * Constant for the {@code 1970-01-01T00:00:00Z} {@link Instant#EPOCH epoch} as a time stamp attribute. * * @see Instant#EPOCH */ @@ -68,6 +71,15 @@ public class FileTimes { } /** + * Returns the current instant FileTime from the system clock. + * + * @return the current instant FileTime from the system clock. + */ + public static FileTime now() { + return FileTime.from(Instant.now()); + } + + /** * Adds milliseconds to a source FileTime. * * @param fileTime The source FileTime. @@ -100,6 +112,16 @@ public class FileTimes { return FileTime.from(fileTime.toInstant().plusSeconds(secondsToAdd)); } + /** + * Sets the last modified time of the given file path to now. + * + * @param path The file path to set. + * @throws IOException if an I/O error occurs. + */ + public static void setLastModifiedTime(final Path path) throws IOException { + Files.setLastModifiedTime(path, now()); + } + private FileTimes() { // No instances. } diff --git a/src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java index 1ff289e..78cd230 100644 --- a/src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java @@ -35,7 +35,7 @@ import org.apache.commons.io.file.PathUtils; * </p> * <h2>Using Classic IO</h2> * <pre> - * Path dir = Paths.get(""); + * Path dir = PathUtils.current(); * // We are interested in files older than one day * Instant cutoff = Instant.now().minus(Duration.ofDays(1)); * String[] files = dir.list(new AgeFileFilter(cutoff)); @@ -46,7 +46,7 @@ import org.apache.commons.io.file.PathUtils; * * <h2>Using NIO</h2> * <pre> - * Path dir = Paths.get(""); + * Path dir = PathUtils.current(); * // We are interested in files older than one day * Instant cutoff = Instant.now().minus(Duration.ofDays(1)); * AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new AgeFileFilter(cutoff)); @@ -128,8 +128,7 @@ public class AgeFileFilter extends AbstractFileFilter implements Serializable { /** * Constructs a new age file filter for files equal to or older than a certain cutoff. * - * @param cutoffInstant The cutoff time threshold measured in milliseconds since the epoch (00:00:00 GMT, January 1, - * 1970). + * @param cutoffInstant The cutoff time threshold since the epoch (00:00:00 GMT, January 1, 1970). * @since 2.12.0 */ public AgeFileFilter(final Instant cutoffInstant) { @@ -139,10 +138,8 @@ public class AgeFileFilter extends AbstractFileFilter implements Serializable { /** * Constructs a new age file filter for files on any one side of a certain cutoff. * - * @param cutoffInstant The cutoff time threshold since the epoch (00:00:00 GMT, January 1, - * 1970). - * @param acceptOlder if true, older files (at or before the cutoff) are accepted, else newer ones (after the - * cutoff). + * @param cutoffInstant The cutoff time threshold since the epoch (00:00:00 GMT, January 1, 1970). + * @param acceptOlder if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff). * @since 2.12.0 */ public AgeFileFilter(final Instant cutoffInstant, final boolean acceptOlder) { diff --git a/src/main/java/org/apache/commons/io/filefilter/CanExecuteFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/CanExecuteFileFilter.java index 97b7d6f..da08688 100644 --- a/src/main/java/org/apache/commons/io/filefilter/CanExecuteFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/CanExecuteFileFilter.java @@ -31,7 +31,7 @@ import java.nio.file.attribute.BasicFileAttributes; * </p> * <h2>Using Classic IO</h2> * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(CanExecuteFileFilter.CAN_EXECUTE); * for (String file : files) { * System.out.println(file); @@ -44,7 +44,7 @@ import java.nio.file.attribute.BasicFileAttributes; * </p> * * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(CanExecuteFileFilter.CANNOT_EXECUTE); * for (int i = 0; i < files.length; i++) { * System.out.println(files[i]); diff --git a/src/main/java/org/apache/commons/io/filefilter/CanReadFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/CanReadFileFilter.java index 93dcb16..8c8e5f8 100644 --- a/src/main/java/org/apache/commons/io/filefilter/CanReadFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/CanReadFileFilter.java @@ -30,7 +30,7 @@ import java.nio.file.attribute.BasicFileAttributes; * </p> * <h2>Using Classic IO</h2> * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(CanReadFileFilter.CAN_READ); * for (String file : files) { * System.out.println(file); @@ -41,7 +41,7 @@ import java.nio.file.attribute.BasicFileAttributes; * Example, showing how to print out a list of the current directory's <i>un-readable</i> files: * * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(CanReadFileFilter.CANNOT_READ); * for (String file : files) { * System.out.println(file); @@ -52,7 +52,7 @@ import java.nio.file.attribute.BasicFileAttributes; * Example, showing how to print out a list of the current directory's <i>read-only</i> files: * * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(CanReadFileFilter.READ_ONLY); * for (String file : files) { * System.out.println(file); diff --git a/src/main/java/org/apache/commons/io/filefilter/CanWriteFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/CanWriteFileFilter.java index 80ba322..d4e2b6b 100644 --- a/src/main/java/org/apache/commons/io/filefilter/CanWriteFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/CanWriteFileFilter.java @@ -30,7 +30,7 @@ import java.nio.file.attribute.BasicFileAttributes; * </p> * <h2>Using Classic IO</h2> * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(CanWriteFileFilter.CAN_WRITE); * for (String file : files) { * System.out.println(file); @@ -41,7 +41,7 @@ import java.nio.file.attribute.BasicFileAttributes; * Example, showing how to print out a list of the current directory's <i>un-writable</i> files: * * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(CanWriteFileFilter.CANNOT_WRITE); * for (String file : files) { * System.out.println(file); diff --git a/src/main/java/org/apache/commons/io/filefilter/DirectoryFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/DirectoryFileFilter.java index 1b37bd9..de3394d 100644 --- a/src/main/java/org/apache/commons/io/filefilter/DirectoryFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/DirectoryFileFilter.java @@ -31,7 +31,7 @@ import java.nio.file.attribute.BasicFileAttributes; * <h2>Using Classic IO</h2> * * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(DirectoryFileFilter.INSTANCE); * for (String file : files) { * System.out.println(file); @@ -41,7 +41,7 @@ import java.nio.file.attribute.BasicFileAttributes; * <h2>Using NIO</h2> * * <pre> - * final Path dir = Paths.get(""); + * final Path dir = PathUtils.current(); * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(DirectoryFileFilter.INSTANCE); * // * // Walk one dir diff --git a/src/main/java/org/apache/commons/io/filefilter/EmptyFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/EmptyFileFilter.java index 1017973..55daa9c 100644 --- a/src/main/java/org/apache/commons/io/filefilter/EmptyFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/EmptyFileFilter.java @@ -37,7 +37,7 @@ import org.apache.commons.io.IOUtils; * </p> * <h2>Using Classic IO</h2> * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(EmptyFileFilter.EMPTY); * for (String file : files) { * System.out.println(file); @@ -49,7 +49,7 @@ import org.apache.commons.io.IOUtils; * </p> * * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(EmptyFileFilter.NOT_EMPTY); * for (String file : files) { * System.out.println(file); @@ -58,7 +58,7 @@ import org.apache.commons.io.IOUtils; * * <h2>Using NIO</h2> * <pre> - * final Path dir = Paths.get(""); + * final Path dir = PathUtils.current(); * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(EmptyFileFilter.EMPTY); * // * // Walk one dir diff --git a/src/main/java/org/apache/commons/io/filefilter/FileFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/FileFileFilter.java index 1878a71..a15dd8d 100644 --- a/src/main/java/org/apache/commons/io/filefilter/FileFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/FileFileFilter.java @@ -31,7 +31,7 @@ import java.nio.file.attribute.BasicFileAttributes; * </p> * <h2>Using Classic IO</h2> * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(FileFileFilter.INSTANCE); * for (String file : files) { * System.out.println(file); @@ -40,7 +40,7 @@ import java.nio.file.attribute.BasicFileAttributes; * * <h2>Using NIO</h2> * <pre> - * final Path dir = Paths.get(""); + * final Path dir = PathUtils.current(); * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(FileFileFilter.INSTANCE); * // * // Walk one dir diff --git a/src/main/java/org/apache/commons/io/filefilter/HiddenFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/HiddenFileFilter.java index d0c7b34..8fa7940 100644 --- a/src/main/java/org/apache/commons/io/filefilter/HiddenFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/HiddenFileFilter.java @@ -32,7 +32,7 @@ import java.nio.file.attribute.BasicFileAttributes; * </p> * <h2>Using Classic IO</h2> * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(HiddenFileFilter.HIDDEN); * for (String file : files) { * System.out.println(file); @@ -45,7 +45,7 @@ import java.nio.file.attribute.BasicFileAttributes; * </p> * * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(HiddenFileFilter.VISIBLE); * for (String file : files) { * System.out.println(file); @@ -54,7 +54,7 @@ import java.nio.file.attribute.BasicFileAttributes; * * <h2>Using NIO</h2> * <pre> - * final Path dir = Paths.get(""); + * final Path dir = PathUtils.current(); * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(HiddenFileFilter.HIDDEN); * // * // Walk one dir diff --git a/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java index c6cbe87..5521662 100644 --- a/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java @@ -40,7 +40,7 @@ import org.apache.commons.io.IOUtils; * </p> * <h2>Using Classic IO</h2> * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * MagicNumberFileFilter javaClassFileFilter = * MagicNumberFileFilter(new byte[] {(byte) 0xCA, (byte) 0xFE, * (byte) 0xBA, (byte) 0xBE}); @@ -57,7 +57,7 @@ import org.apache.commons.io.IOUtils; * </p> * * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * MagicNumberFileFilter tarFileFilter = * MagicNumberFileFilter("ustar", 257); * String[] tarFiles = dir.list(tarFileFilter); @@ -67,7 +67,7 @@ import org.apache.commons.io.IOUtils; * </pre> * <h2>Using NIO</h2> * <pre> - * final Path dir = Paths.get(""); + * final Path dir = PathUtils.current(); * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(MagicNumberFileFilter("ustar", 257)); * // * // Walk one dir diff --git a/src/main/java/org/apache/commons/io/filefilter/NameFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/NameFileFilter.java index 69c6d04..904e713 100644 --- a/src/main/java/org/apache/commons/io/filefilter/NameFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/NameFileFilter.java @@ -34,7 +34,7 @@ import org.apache.commons.io.IOCase; * </p> * <h2>Using Classic IO</h2> * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(new NameFileFilter("Test")); * for (String file : files) { * System.out.println(file); @@ -43,7 +43,7 @@ import org.apache.commons.io.IOCase; * * <h2>Using NIO</h2> * <pre> - * final Path dir = Paths.get(""); + * final Path dir = PathUtils.current(); * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new NameFileFilter("Test")); * // * // Walk one dir diff --git a/src/main/java/org/apache/commons/io/filefilter/PrefixFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/PrefixFileFilter.java index 437ae9e..2d89172 100644 --- a/src/main/java/org/apache/commons/io/filefilter/PrefixFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/PrefixFileFilter.java @@ -33,7 +33,7 @@ import org.apache.commons.io.IOCase; * </p> * <h2>Using Classic IO</h2> * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(new PrefixFileFilter("Test")); * for (String file : files) { * System.out.println(file); @@ -42,7 +42,7 @@ import org.apache.commons.io.IOCase; * * <h2>Using NIO</h2> * <pre> - * final Path dir = Paths.get(""); + * final Path dir = PathUtils.current(); * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new PrefixFileFilter("Test")); * // * // Walk one dir diff --git a/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java index f1a6fda..cee7b4a 100644 --- a/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java @@ -36,7 +36,7 @@ import org.apache.commons.io.IOCase; * e.g. * * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * FileFilter fileFilter = new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$"); * File[] files = dir.listFiles(fileFilter); * for (String file : files) { @@ -47,7 +47,7 @@ import org.apache.commons.io.IOCase; * <h2>Using NIO</h2> * * <pre> - * final Path dir = Paths.get(""); + * final Path dir = PathUtils.current(); * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$")); * // * // Walk one dir diff --git a/src/main/java/org/apache/commons/io/filefilter/SizeFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/SizeFileFilter.java index 0b4e2f1..09adc2e 100644 --- a/src/main/java/org/apache/commons/io/filefilter/SizeFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/SizeFileFilter.java @@ -33,7 +33,7 @@ import java.nio.file.attribute.BasicFileAttributes; * </p> * <h2>Using Classic IO</h2> * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(new SizeFileFilter(1024 * 1024)); * for (String file : files) { * System.out.println(file); @@ -42,7 +42,7 @@ import java.nio.file.attribute.BasicFileAttributes; * * <h2>Using NIO</h2> * <pre> - * final Path dir = Paths.get(""); + * final Path dir = PathUtils.current(); * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new SizeFileFilter(1024 * 1024)); * // * // Walk one dir diff --git a/src/main/java/org/apache/commons/io/filefilter/SuffixFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/SuffixFileFilter.java index f5bc863..76ede69 100644 --- a/src/main/java/org/apache/commons/io/filefilter/SuffixFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/SuffixFileFilter.java @@ -35,7 +35,7 @@ import org.apache.commons.io.IOCase; * </p> * <h2>Using Classic IO</h2> * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(new SuffixFileFilter(".java")); * for (String file : files) { * System.out.println(file); @@ -44,7 +44,7 @@ import org.apache.commons.io.IOCase; * * <h2>Using NIO</h2> * <pre> - * final Path dir = Paths.get(""); + * final Path dir = PathUtils.current(); * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new SuffixFileFilter(".java")); * // * // Walk one dir diff --git a/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java index b1714b7..e3a30bd 100644 --- a/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java @@ -31,7 +31,7 @@ import java.nio.file.attribute.BasicFileAttributes; * </p> * <h2>Using Classic IO</h2> * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * String[] files = dir.list(SymbolicLinkFileFilter.INSTANCE); * for (String file : files) { * System.out.println(file); @@ -40,7 +40,7 @@ import java.nio.file.attribute.BasicFileAttributes; * * <h2>Using NIO</h2> * <pre> - * final Path dir = Paths.get(""); + * final Path dir = PathUtils.current(); * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(SymbolicLinkFileFilter.INSTANCE); * // * // Walk one dir diff --git a/src/main/java/org/apache/commons/io/filefilter/WildcardFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/WildcardFileFilter.java index f38ae70..6ed79ca 100644 --- a/src/main/java/org/apache/commons/io/filefilter/WildcardFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/WildcardFileFilter.java @@ -45,7 +45,7 @@ import org.apache.commons.io.IOCase; * </p> * <h2>Using Classic IO</h2> * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * FileFilter fileFilter = new WildcardFileFilter("*test*.java~*~"); * File[] files = dir.listFiles(fileFilter); * for (String file : files) { @@ -55,7 +55,7 @@ import org.apache.commons.io.IOCase; * * <h2>Using NIO</h2> * <pre> - * final Path dir = Paths.get(""); + * final Path dir = PathUtils.current(); * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new WildcardFileFilter("*test*.java~*~")); * // * // Walk one dir diff --git a/src/main/java/org/apache/commons/io/filefilter/WildcardFilter.java b/src/main/java/org/apache/commons/io/filefilter/WildcardFilter.java index abd8f42..7f70960 100644 --- a/src/main/java/org/apache/commons/io/filefilter/WildcardFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/WildcardFilter.java @@ -45,7 +45,7 @@ import org.apache.commons.io.FilenameUtils; * </p> * <h2>Using Classic IO</h2> * <pre> - * File dir = new File("."); + * File dir = FileUtils.current(); * FileFilter fileFilter = new WildcardFilter("*test*.java~*~"); * File[] files = dir.listFiles(fileFilter); * for (String file : files) { @@ -55,7 +55,7 @@ import org.apache.commons.io.FilenameUtils; * * <h2>Using NIO</h2> * <pre> - * final Path dir = Paths.get(""); + * final Path dir = PathUtils.current(); * final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new WildcardFilter("*test*.java~*~")); * // * // Walk one dir diff --git a/src/main/java/org/apache/commons/io/input/BrokenInputStream.java b/src/main/java/org/apache/commons/io/input/BrokenInputStream.java index 731b032..907e37c 100644 --- a/src/main/java/org/apache/commons/io/input/BrokenInputStream.java +++ b/src/main/java/org/apache/commons/io/input/BrokenInputStream.java @@ -20,11 +20,9 @@ import java.io.IOException; import java.io.InputStream; /** - * Broken input stream. This stream always throws an {@link IOException} from - * all the {@link InputStream} methods where the exception is declared. + * Always throws an {@link IOException} from all the {@link InputStream} methods where the exception is declared. * <p> - * This class is mostly useful for testing error handling in code that uses an - * input stream. + * This class is mostly useful for testing error handling. * </p> * * @since 2.0 diff --git a/src/main/java/org/apache/commons/io/input/BrokenReader.java b/src/main/java/org/apache/commons/io/input/BrokenReader.java index 1603778..931971a 100644 --- a/src/main/java/org/apache/commons/io/input/BrokenReader.java +++ b/src/main/java/org/apache/commons/io/input/BrokenReader.java @@ -20,9 +20,9 @@ import java.io.IOException; import java.io.Reader; /** - * Broken reader. This reader always throws an {@link IOException} from all the {@link Reader} methods where the exception is declared. + * Always throws an {@link IOException} from all the {@link Reader} methods where the exception is declared. * <p> - * This class is mostly useful for testing error handling in code that uses a reader. + * This class is mostly useful for testing error handling. * </p> * * @since 2.7 diff --git a/src/main/java/org/apache/commons/io/input/ClosedInputStream.java b/src/main/java/org/apache/commons/io/input/ClosedInputStream.java index 78951c3..fc372e3 100644 --- a/src/main/java/org/apache/commons/io/input/ClosedInputStream.java +++ b/src/main/java/org/apache/commons/io/input/ClosedInputStream.java @@ -20,8 +20,10 @@ import static org.apache.commons.io.IOUtils.EOF; import java.io.InputStream; +import org.apache.commons.io.IOUtils; + /** - * Closed input stream. This stream returns EOF to all attempts to read something from the stream. + * Always returns {@link IOUtils#EOF} to all attempts to read something from the stream. * <p> * Typically uses of this class include testing for corner cases in methods that accept input streams and acting as a * sentinel value instead of a {@code null} input stream. diff --git a/src/main/java/org/apache/commons/io/input/ClosedReader.java b/src/main/java/org/apache/commons/io/input/ClosedReader.java index 2a0234c..ac5b0df 100644 --- a/src/main/java/org/apache/commons/io/input/ClosedReader.java +++ b/src/main/java/org/apache/commons/io/input/ClosedReader.java @@ -21,8 +21,10 @@ import static org.apache.commons.io.IOUtils.EOF; import java.io.IOException; import java.io.Reader; +import org.apache.commons.io.IOUtils; + /** - * Closed reader. This reader returns EOF to all attempts to read something from it. + * Always returns {@link IOUtils#EOF} to all attempts to read something from it. * <p> * Typically uses of this class include testing for corner cases in methods that accept readers and acting as a sentinel * value instead of a {@code null} reader. diff --git a/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java b/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java index 48b96f9..7eb9a8b 100644 --- a/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java +++ b/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java @@ -46,7 +46,7 @@ import org.apache.commons.io.comparator.NameFileComparator; * <h2>Basic Usage</h2> * Create a {@link FileAlterationObserver} for the directory and register the listeners: * <pre> - * File directory = new File(new File("."), "src"); + * File directory = new File(FileUtils.current(), "src"); * FileAlterationObserver observer = new FileAlterationObserver(directory); * observer.addListener(...); * observer.addListener(...); diff --git a/src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java b/src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java index 4380ade..ade14c2 100644 --- a/src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java +++ b/src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java @@ -82,21 +82,19 @@ public abstract class AbstractByteArrayOutputStream extends OutputStream { */ protected void needNewBuffer(final int newcount) { if (currentBufferIndex < buffers.size() - 1) { - //Recycling old buffer + // Recycling old buffer filledBufferSum += currentBuffer.length; currentBufferIndex++; currentBuffer = buffers.get(currentBufferIndex); } else { - //Creating new buffer + // Creating new buffer final int newBufferSize; if (currentBuffer == null) { newBufferSize = newcount; filledBufferSum = 0; } else { - newBufferSize = Math.max( - currentBuffer.length << 1, - newcount - filledBufferSum); + newBufferSize = Math.max(currentBuffer.length << 1, newcount - filledBufferSum); filledBufferSum += currentBuffer.length; } diff --git a/src/main/java/org/apache/commons/io/output/BrokenWriter.java b/src/main/java/org/apache/commons/io/output/BrokenWriter.java index f7e07a4..f2b659b 100644 --- a/src/main/java/org/apache/commons/io/output/BrokenWriter.java +++ b/src/main/java/org/apache/commons/io/output/BrokenWriter.java @@ -20,11 +20,9 @@ import java.io.IOException; import java.io.Writer; /** - * Broken writer. This writer always throws an {@link IOException} from - * all {@link Writer} methods. + * Always throws an {@link IOException} from all {@link Writer} methods. * <p> - * This class is mostly useful for testing error handling in code that uses a - * writer. + * This class is mostly useful for testing error handling in code that uses a writer. * </p> * * @since 2.0 diff --git a/src/main/java/org/apache/commons/io/output/ClosedOutputStream.java b/src/main/java/org/apache/commons/io/output/ClosedOutputStream.java index a6dcd39..051d145 100644 --- a/src/main/java/org/apache/commons/io/output/ClosedOutputStream.java +++ b/src/main/java/org/apache/commons/io/output/ClosedOutputStream.java @@ -20,7 +20,7 @@ import java.io.IOException; import java.io.OutputStream; /** - * Throws an exception on all attempts to write to the stream. + * Throws an IOException on all attempts to write to the stream. * <p> * Typically uses of this class include testing for corner cases in methods that accept an output stream and acting as a * sentinel value instead of a {@code null} output stream. diff --git a/src/main/java/org/apache/commons/io/output/ClosedWriter.java b/src/main/java/org/apache/commons/io/output/ClosedWriter.java index 5721f57..7220ba1 100644 --- a/src/main/java/org/apache/commons/io/output/ClosedWriter.java +++ b/src/main/java/org/apache/commons/io/output/ClosedWriter.java @@ -20,7 +20,7 @@ import java.io.IOException; import java.io.Writer; /** - * Throws an exception on all attempts to write with {@link #close()} implemented as a noop. + * Throws an IOException on all attempts to write with {@link #close()} implemented as a noop. * <p> * Typically uses of this class include testing for corner cases in methods that accept a writer and acting as a * sentinel value instead of a {@code null} writer. diff --git a/src/main/java/org/apache/commons/io/output/NullOutputStream.java b/src/main/java/org/apache/commons/io/output/NullOutputStream.java index 6678b63..b9cac75 100644 --- a/src/main/java/org/apache/commons/io/output/NullOutputStream.java +++ b/src/main/java/org/apache/commons/io/output/NullOutputStream.java @@ -20,7 +20,7 @@ import java.io.IOException; import java.io.OutputStream; /** - * Writes all data to the famous <b>/dev/null</b>. + * Never writes data. Calls never go beyond this class. * <p> * This output stream has no destination (file/socket etc.) and all bytes written to it are ignored and lost. * </p> diff --git a/src/main/java/org/apache/commons/io/output/NullPrintStream.java b/src/main/java/org/apache/commons/io/output/NullPrintStream.java index d3ac880..c882c75 100644 --- a/src/main/java/org/apache/commons/io/output/NullPrintStream.java +++ b/src/main/java/org/apache/commons/io/output/NullPrintStream.java @@ -20,7 +20,7 @@ package org.apache.commons.io.output; import java.io.PrintStream; /** - * Writes all data to the famous <b>/dev/null</b>. + * Never prints data. Calls never go beyond this class. * <p> * This print stream has no destination (file/socket etc.) and all bytes written to it are ignored and lost. * </p> diff --git a/src/main/java/org/apache/commons/io/output/NullWriter.java b/src/main/java/org/apache/commons/io/output/NullWriter.java index 7f5263a..ccfccc5 100644 --- a/src/main/java/org/apache/commons/io/output/NullWriter.java +++ b/src/main/java/org/apache/commons/io/output/NullWriter.java @@ -19,7 +19,7 @@ package org.apache.commons.io.output; import java.io.Writer; /** - * Writes all data to the famous <b>/dev/null</b>. + * Never writes data. Calls never go beyond this class. * <p> * This {@code Writer} has no destination (file/socket etc.) and all characters written to it are ignored and lost. * </p> diff --git a/src/test/java/org/apache/commons/io/DirectoryWalkerTestCase.java b/src/test/java/org/apache/commons/io/DirectoryWalkerTestCase.java index 7280b48..c23dbec 100644 --- a/src/test/java/org/apache/commons/io/DirectoryWalkerTestCase.java +++ b/src/test/java/org/apache/commons/io/DirectoryWalkerTestCase.java @@ -226,7 +226,7 @@ public class DirectoryWalkerTestCase { } } // Directories - private static final File current = new File("."); + private static final File current = FileUtils.current(); private static final File javaDir = new File("src/main/java"); private static final File orgDir = new File(javaDir, "org"); @@ -498,7 +498,7 @@ public class DirectoryWalkerTestCase { public void testLimitToCurrent() { final List<File> results = new TestFileFinder(null, 0).find(current); assertEquals(1, results.size(), "Result Size"); - assertTrue(results.contains(new File(".")), "Current Dir"); + assertTrue(results.contains(FileUtils.current()), "Current Dir"); } /** diff --git a/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java b/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java index e5159ad..4452b47 100644 --- a/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java +++ b/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java @@ -226,7 +226,7 @@ public class DirectoryWalkerTestCaseJava4 { } } // Directories - private static final File current = new File("."); + private static final File current = FileUtils.current(); private static final File javaDir = new File("src/main/java"); private static final File orgDir = new File(javaDir, "org"); private static final File apacheDir = new File(orgDir, "apache"); @@ -470,7 +470,7 @@ public class DirectoryWalkerTestCaseJava4 { public void testLimitToCurrent() { final List<File> results = new TestFileFinder(null, 0).find(current); assertEquals(1, results.size(), "Result Size"); - assertTrue(results.contains(new File(".")), "Current Dir"); + assertTrue(results.contains(FileUtils.current()), "Current Dir"); } // ------------ Test DirectoryWalker implementation -------------------------- diff --git a/src/test/java/org/apache/commons/io/FileUtilsFileNewerTestCase.java b/src/test/java/org/apache/commons/io/FileUtilsFileNewerTestCase.java index 25bc737..837e9cc 100644 --- a/src/test/java/org/apache/commons/io/FileUtilsFileNewerTestCase.java +++ b/src/test/java/org/apache/commons/io/FileUtilsFileNewerTestCase.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.attribute.FileTime; import java.util.Date; -import java.util.concurrent.TimeUnit; import org.apache.commons.io.file.attribute.FileTimes; import org.apache.commons.io.test.TestUtils; diff --git a/src/test/java/org/apache/commons/io/FileUtilsTestCase.java b/src/test/java/org/apache/commons/io/FileUtilsTestCase.java index 9bef98e..57f000a 100644 --- a/src/test/java/org/apache/commons/io/FileUtilsTestCase.java +++ b/src/test/java/org/apache/commons/io/FileUtilsTestCase.java @@ -579,7 +579,7 @@ public class FileUtilsTestCase { @Test public void testChecksumOnDirectory() throws Exception { - assertThrows(IllegalArgumentException.class, () -> FileUtils.checksum(new File("."), new CRC32())); + assertThrows(IllegalArgumentException.class, () -> FileUtils.checksum(FileUtils.current(), new CRC32())); } @Test diff --git a/src/test/java/org/apache/commons/io/LineIteratorTestCase.java b/src/test/java/org/apache/commons/io/LineIteratorTestCase.java index bad2b33..a0546f3 100644 --- a/src/test/java/org/apache/commons/io/LineIteratorTestCase.java +++ b/src/test/java/org/apache/commons/io/LineIteratorTestCase.java @@ -21,11 +21,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.io.BufferedReader; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.Reader; import java.io.StringReader; diff --git a/src/test/java/org/apache/commons/io/comparator/DirectoryFileComparatorTest.java b/src/test/java/org/apache/commons/io/comparator/DirectoryFileComparatorTest.java index 429fdc3..d4ebcb6 100644 --- a/src/test/java/org/apache/commons/io/comparator/DirectoryFileComparatorTest.java +++ b/src/test/java/org/apache/commons/io/comparator/DirectoryFileComparatorTest.java @@ -18,6 +18,7 @@ package org.apache.commons.io.comparator; import java.io.File; +import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,7 +31,7 @@ public class DirectoryFileComparatorTest extends ComparatorAbstractTestCase { public void setUp() { comparator = (AbstractFileComparator) DirectoryFileComparator.DIRECTORY_COMPARATOR; reverse = DirectoryFileComparator.DIRECTORY_REVERSE; - final File currentDir = new File("."); + final File currentDir = FileUtils.current(); equalFile1 = new File(currentDir, "src"); equalFile2 = new File(currentDir, "src/site/xdoc"); lessFile = new File(currentDir, "src"); diff --git a/src/test/java/org/apache/commons/io/comparator/SizeFileComparatorTest.java b/src/test/java/org/apache/commons/io/comparator/SizeFileComparatorTest.java index 07f75ee..b6d78bc 100644 --- a/src/test/java/org/apache/commons/io/comparator/SizeFileComparatorTest.java +++ b/src/test/java/org/apache/commons/io/comparator/SizeFileComparatorTest.java @@ -25,6 +25,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.test.TestUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -95,7 +96,7 @@ public class SizeFileComparatorTest extends ComparatorAbstractTestCase { */ @Test public void testNonexistantFile() { - final File nonexistantFile = new File(new File("."), "nonexistant.txt"); + final File nonexistantFile = new File(FileUtils.current(), "nonexistant.txt"); assertFalse(nonexistantFile.exists()); assertTrue(comparator.compare(nonexistantFile, moreFile) < 0, "less"); } diff --git a/src/test/java/org/apache/commons/io/filefilter/AgeFileFilterTest.java b/src/test/java/org/apache/commons/io/filefilter/AgeFileFilterTest.java index 571d25b..f660e71 100644 --- a/src/test/java/org/apache/commons/io/filefilter/AgeFileFilterTest.java +++ b/src/test/java/org/apache/commons/io/filefilter/AgeFileFilterTest.java @@ -27,6 +27,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.file.AccumulatorPathVisitor; import org.apache.commons.io.file.CounterAssertions; import org.apache.commons.io.file.Counters; @@ -44,7 +45,7 @@ public class AgeFileFilterTest { */ @Test public void testJavadocExampleUsingIo() { - final File dir = new File("."); + final File dir = FileUtils.current(); // We are interested in files older than one day final long cutoffMillis = System.currentTimeMillis(); final String[] files = dir.list(new AgeFileFilter(cutoffMillis)); diff --git a/src/test/java/org/apache/commons/io/filefilter/DirectoryFileFilterTest.java b/src/test/java/org/apache/commons/io/filefilter/DirectoryFileFilterTest.java index da0c5a8..22958a8 100644 --- a/src/test/java/org/apache/commons/io/filefilter/DirectoryFileFilterTest.java +++ b/src/test/java/org/apache/commons/io/filefilter/DirectoryFileFilterTest.java @@ -28,6 +28,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.file.AccumulatorPathVisitor; import org.apache.commons.io.file.CounterAssertions; import org.apache.commons.io.file.Counters; @@ -45,7 +46,7 @@ public class DirectoryFileFilterTest { */ @Test public void testJavadocExampleUsingIo() { - final File dir = new File("."); + final File dir = FileUtils.current(); final String[] files = dir.list(DirectoryFileFilter.INSTANCE); for (final String file : files) { // System.out.println(files[i]); diff --git a/src/test/java/org/apache/commons/io/filefilter/NameFileFilterTest.java b/src/test/java/org/apache/commons/io/filefilter/NameFileFilterTest.java index 11c6119..09162b1 100644 --- a/src/test/java/org/apache/commons/io/filefilter/NameFileFilterTest.java +++ b/src/test/java/org/apache/commons/io/filefilter/NameFileFilterTest.java @@ -28,6 +28,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.file.AccumulatorPathVisitor; import org.apache.commons.io.file.CounterAssertions; import org.apache.commons.io.file.Counters; @@ -45,7 +46,7 @@ public class NameFileFilterTest { */ @Test public void testJavadocExampleUsingIo() { - final File dir = new File("."); + final File dir = FileUtils.current(); final String[] files = dir.list(new NameFileFilter("NOTICE.txt")); for (final String file : files) { // System.out.println(file); diff --git a/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java b/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java index 785d4e2..eac7165 100644 --- a/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java +++ b/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java @@ -32,6 +32,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.stream.IntStream; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -179,7 +180,7 @@ public class DeferredFileOutputStreamTest { final String prefix = "commons-io-test"; final String suffix = ".out"; - final File tempDir = new File("."); + final File tempDir = FileUtils.current(); final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length - 5, initialBufferSize, prefix, suffix, tempDir); assertNull(dfos.getFile(), "Check file is null-A"); @@ -244,7 +245,7 @@ public class DeferredFileOutputStreamTest { final String prefix = "commons-io-test"; final String suffix = ".out"; - final File tempDir = new File("."); + final File tempDir = FileUtils.current(); final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length + 42, initialBufferSize, prefix, suffix, tempDir); assertNull(dfos.getFile(), "Check file is null-A"); @@ -268,7 +269,7 @@ public class DeferredFileOutputStreamTest { final String prefix = null; final String suffix = ".out"; - final File tempDir = new File("."); + final File tempDir = FileUtils.current(); try { new DeferredFileOutputStream(testBytes.length - 5, prefix, suffix, tempDir).close(); fail("Expected IllegalArgumentException ");