Skip to content

Commit 6aaf6f5

Browse files
author
Gary Gregory
committed
Javadoc and refactor to FileTimes.now().
Reuse own APIs.
1 parent c146a94 commit 6aaf6f5

55 files changed

Lines changed: 189 additions & 179 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/org/apache/commons/io/FileSystem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ public int getMaxPathLength() {
288288

289289
/**
290290
* Gets the name separator, '\\' on Windows, '/' on Linux.
291+
*
291292
* @return '\\' on Windows, '/' on Linux.
292293
*
293294
* @since 2.12.0
@@ -372,7 +373,7 @@ public boolean isReservedFileName(final CharSequence candidate) {
372373
/**
373374
* Converts all separators to the Windows separator of backslash.
374375
*
375-
* @param path the path to be changed, null ignored
376+
* @param path the path to be changed, null ignored
376377
* @return the updated path
377378
* @since 2.12.0
378379
*/

src/main/java/org/apache/commons/io/FileSystemUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public static long freeSpaceKb(final String path, final long timeout) throws IOE
212212
* <p>
213213
* Identical to:
214214
* <pre>
215-
* freeSpaceKb(new File(".").getAbsolutePath())
215+
* freeSpaceKb(FileUtils.current().getAbsolutePath())
216216
* </pre>
217217
* @return the amount of free drive space on the drive or volume in kilobytes
218218
* @throws IllegalStateException if an error occurred in initialisation
@@ -231,7 +231,7 @@ public static long freeSpaceKb() throws IOException {
231231
* <p>
232232
* Identical to:
233233
* <pre>
234-
* freeSpaceKb(new File(".").getAbsolutePath())
234+
* freeSpaceKb(FileUtils.current().getAbsolutePath())
235235
* </pre>
236236
* @param timeout The timeout amount in milliseconds or no timeout if the value
237237
* is zero or less
@@ -243,7 +243,7 @@ public static long freeSpaceKb() throws IOException {
243243
*/
244244
@Deprecated
245245
public static long freeSpaceKb(final long timeout) throws IOException {
246-
return freeSpaceKb(new File(".").getAbsolutePath(), timeout);
246+
return freeSpaceKb(FileUtils.current().getAbsolutePath(), timeout);
247247
}
248248

249249
/**

src/main/java/org/apache/commons/io/FileUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import org.apache.commons.io.file.PathFilter;
7070
import org.apache.commons.io.file.PathUtils;
7171
import org.apache.commons.io.file.StandardDeleteOption;
72+
import org.apache.commons.io.file.attribute.FileTimes;
7273
import org.apache.commons.io.filefilter.FileEqualsFileFilter;
7374
import org.apache.commons.io.filefilter.FileFileFilter;
7475
import org.apache.commons.io.filefilter.IOFileFilter;
@@ -3152,7 +3153,7 @@ public static void touch(final File file) throws IOException {
31523153
if (!file.exists()) {
31533154
newOutputStream(file, false).close();
31543155
}
3155-
PathUtils.setLastModifiedTime(file.toPath());
3156+
FileTimes.setLastModifiedTime(file.toPath());
31563157
}
31573158

31583159
/**

src/main/java/org/apache/commons/io/comparator/AbstractFileComparator.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
abstract class AbstractFileComparator implements Comparator<File> {
3131

3232
/**
33-
* Sort an array of files.
33+
* Sorts an array of files.
3434
* <p>
3535
* This method uses {@link Arrays#sort(Object[], Comparator)} and returns the original array.
3636
* </p>
3737
*
38-
* @param files The files to sort, may be null
39-
* @return The sorted array
38+
* @param files The files to sort, may be null.
39+
* @return The sorted array.
4040
* @since 2.0
4141
*/
4242
public File[] sort(final File... files) {
@@ -47,13 +47,13 @@ public File[] sort(final File... files) {
4747
}
4848

4949
/**
50-
* Sort a List of files.
50+
* Sorts a List of files.
5151
* <p>
5252
* This method uses {@link Collections#sort(List, Comparator)} and returns the original list.
5353
* </p>
5454
*
55-
* @param files The files to sort, may be null
56-
* @return The sorted list
55+
* @param files The files to sort, may be null.
56+
* @return The sorted list.
5757
* @since 2.0
5858
*/
5959
public List<File> sort(final List<File> files) {
@@ -66,7 +66,7 @@ public List<File> sort(final List<File> files) {
6666
/**
6767
* String representation of this file comparator.
6868
*
69-
* @return String representation of this file comparator
69+
* @return String representation of this file comparator.
7070
*/
7171
@Override
7272
public String toString() {

src/main/java/org/apache/commons/io/comparator/CompositeFileComparator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,33 @@ public class CompositeFileComparator extends AbstractFileComparator implements S
4545

4646
private static final Comparator<?>[] EMPTY_COMPARATOR_ARRAY = {};
4747
private static final long serialVersionUID = -2224170307287243428L;
48-
private static final Comparator<?>[] NO_COMPARATORS = {};
48+
4949
private final Comparator<File>[] delegates;
5050

5151
/**
52-
* Create a composite comparator for the set of delegate comparators.
52+
* Constructs a composite comparator for the set of delegate comparators.
5353
*
5454
* @param delegates The delegate file comparators
5555
*/
5656
@SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct
5757
public CompositeFileComparator(final Comparator<File>... delegates) {
5858
if (delegates == null) {
59-
this.delegates = (Comparator<File>[]) NO_COMPARATORS;//1
59+
this.delegates = (Comparator<File>[]) EMPTY_COMPARATOR_ARRAY;//1
6060
} else {
6161
this.delegates = (Comparator<File>[]) new Comparator<?>[delegates.length];//2
6262
System.arraycopy(delegates, 0, this.delegates, 0, delegates.length);
6363
}
6464
}
6565

6666
/**
67-
* Create a composite comparator for the set of delegate comparators.
67+
* Constructs a composite comparator for the set of delegate comparators.
6868
*
6969
* @param delegates The delegate file comparators
7070
*/
7171
@SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct
7272
public CompositeFileComparator(final Iterable<Comparator<File>> delegates) {
7373
if (delegates == null) {
74-
this.delegates = (Comparator<File>[]) NO_COMPARATORS; //1
74+
this.delegates = (Comparator<File>[]) EMPTY_COMPARATOR_ARRAY; //1
7575
} else {
7676
final List<Comparator<File>> list = new ArrayList<>();
7777
for (final Comparator<File> comparator : delegates) {
@@ -82,7 +82,7 @@ public CompositeFileComparator(final Iterable<Comparator<File>> delegates) {
8282
}
8383

8484
/**
85-
* Compare the two files using delegate comparators.
85+
* Compares the two files using delegate comparators.
8686
*
8787
* @param file1 The first file to compare
8888
* @param file2 The second file to compare

src/main/java/org/apache/commons/io/comparator/DefaultFileComparator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.Comparator;
2222

2323
/**
24-
* Compare two files using the <b>default</b> {@link File#compareTo(File)} method.
24+
* s two files using the <b>default</b> {@link File#compareTo(File)} method.
2525
* <p>
2626
* This comparator can be used to sort lists or arrays of files
2727
* by using the default file comparison.
@@ -56,7 +56,7 @@ public class DefaultFileComparator extends AbstractFileComparator implements Ser
5656
public static final Comparator<File> DEFAULT_REVERSE = new ReverseFileComparator(DEFAULT_COMPARATOR);
5757

5858
/**
59-
* Compare the two files using the {@link File#compareTo(File)} method.
59+
* Compares the two files using the {@link File#compareTo(File)} method.
6060
*
6161
* @param file1 The first file to compare
6262
* @param file2 The second file to compare

src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@
2626
* This comparator can be used to sort lists or arrays by directories and files.
2727
* </p>
2828
* <p>
29-
* Example of sorting a list of files/directories using the
30-
* {@link #DIRECTORY_COMPARATOR} singleton instance:
29+
* Example of sorting a list of files/directories using the {@link #DIRECTORY_COMPARATOR} singleton instance:
3130
* </p>
31+
*
3232
* <pre>
3333
* List&lt;File&gt; list = ...
3434
* ((AbstractFileComparator) DirectoryFileComparator.DIRECTORY_COMPARATOR).sort(list);
3535
* </pre>
3636
* <p>
37-
* Example of doing a <i>reverse</i> sort of an array of files/directories using the
38-
* {@link #DIRECTORY_REVERSE} singleton instance:
37+
* Example of doing a <i>reverse</i> sort of an array of files/directories using the {@link #DIRECTORY_REVERSE}
38+
* singleton instance:
3939
* </p>
40+
*
4041
* <pre>
4142
* File[] array = ...
4243
* ((AbstractFileComparator) DirectoryFileComparator.DIRECTORY_REVERSE).sort(array);
@@ -59,23 +60,22 @@ public class DirectoryFileComparator extends AbstractFileComparator implements S
5960
public static final Comparator<File> DIRECTORY_REVERSE = new ReverseFileComparator(DIRECTORY_COMPARATOR);
6061

6162
/**
62-
* Compare the two files using the {@link File#isDirectory()} method.
63+
* Compares the two files using the {@link File#isDirectory()} method.
6364
*
64-
* @param file1 The first file to compare
65-
* @param file2 The second file to compare
66-
* @return the result of calling file1's
67-
* {@link File#compareTo(File)} with file2 as the parameter.
65+
* @param file1 The first file to compare.
66+
* @param file2 The second file to compare.
67+
* @return the result of calling file1's {@link File#compareTo(File)} with file2 as the parameter.
6868
*/
6969
@Override
7070
public int compare(final File file1, final File file2) {
7171
return getType(file1) - getType(file2);
7272
}
7373

7474
/**
75-
* Convert type to numeric value.
75+
* Converts type to numeric value.
7676
*
77-
* @param file The file
78-
* @return 1 for directories and 2 for files
77+
* @param file The file.
78+
* @return 1 for directories and 2 for files.
7979
*/
8080
private int getType(final File file) {
8181
return file.isDirectory() ? TYPE_DIRECTORY : TYPE_FILE;

src/main/java/org/apache/commons/io/comparator/ExtensionFileComparator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ public class ExtensionFileComparator extends AbstractFileComparator implements S
8080
private final IOCase caseSensitivity;
8181

8282
/**
83-
* Construct a case sensitive file extension comparator instance.
83+
* Constructs a case sensitive file extension comparator instance.
8484
*/
8585
public ExtensionFileComparator() {
8686
this.caseSensitivity = IOCase.SENSITIVE;
8787
}
8888

8989
/**
90-
* Construct a file extension comparator instance with the specified case-sensitivity.
90+
* Constructs a file extension comparator instance with the specified case-sensitivity.
9191
*
9292
* @param caseSensitivity how to handle case sensitivity, null means case-sensitive
9393
*/
@@ -96,7 +96,7 @@ public ExtensionFileComparator(final IOCase caseSensitivity) {
9696
}
9797

9898
/**
99-
* Compare the extensions of two files the specified case sensitivity.
99+
* Compares the extensions of two files the specified case sensitivity.
100100
*
101101
* @param file1 The first file to compare
102102
* @param file2 The second file to compare

src/main/java/org/apache/commons/io/comparator/NameFileComparator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ public class NameFileComparator extends AbstractFileComparator implements Serial
7676
private final IOCase caseSensitivity;
7777

7878
/**
79-
* Construct a case sensitive file name comparator instance.
79+
* Constructs a case sensitive file name comparator instance.
8080
*/
8181
public NameFileComparator() {
8282
this.caseSensitivity = IOCase.SENSITIVE;
8383
}
8484

8585
/**
86-
* Construct a file name comparator instance with the specified case-sensitivity.
86+
* Constructs a file name comparator instance with the specified case-sensitivity.
8787
*
8888
* @param caseSensitivity how to handle case sensitivity, null means case-sensitive
8989
*/
@@ -92,7 +92,7 @@ public NameFileComparator(final IOCase caseSensitivity) {
9292
}
9393

9494
/**
95-
* Compare the names of two files with the specified case sensitivity.
95+
* Compares the names of two files with the specified case sensitivity.
9696
*
9797
* @param file1 The first file to compare
9898
* @param file2 The second file to compare

src/main/java/org/apache/commons/io/comparator/PathFileComparator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ public class PathFileComparator extends AbstractFileComparator implements Serial
7676
private final IOCase caseSensitivity;
7777

7878
/**
79-
* Construct a case sensitive file path comparator instance.
79+
* Constructs a case sensitive file path comparator instance.
8080
*/
8181
public PathFileComparator() {
8282
this.caseSensitivity = IOCase.SENSITIVE;
8383
}
8484

8585
/**
86-
* Construct a file path comparator instance with the specified case-sensitivity.
86+
* Constructs a file path comparator instance with the specified case-sensitivity.
8787
*
8888
* @param caseSensitivity how to handle case sensitivity, null means case-sensitive
8989
*/
@@ -92,7 +92,7 @@ public PathFileComparator(final IOCase caseSensitivity) {
9292
}
9393

9494
/**
95-
* Compare the paths of two files the specified case sensitivity.
95+
* Compares the paths of two files the specified case sensitivity.
9696
*
9797
* @param file1 The first file to compare
9898
* @param file2 The second file to compare

0 commit comments

Comments
 (0)