Skip to content

Commit 7adb122

Browse files
author
Gary Gregory
committed
Rename new class
1 parent 3ec3315 commit 7adb122

14 files changed

Lines changed: 181 additions & 227 deletions

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ public static boolean isFileNewer(final File file, final ChronoLocalDateTime<?>
16411641
public static boolean isFileNewer(final File file, final ChronoZonedDateTime<?> chronoZonedDateTime) {
16421642
Objects.requireNonNull(file, "file");
16431643
Objects.requireNonNull(chronoZonedDateTime, "chronoZonedDateTime");
1644-
return UncheckedIO.get(() -> PathUtils.isNewer(file.toPath(), chronoZonedDateTime));
1644+
return Uncheck.get(() -> PathUtils.isNewer(file.toPath(), chronoZonedDateTime));
16451645
}
16461646

16471647
/**
@@ -1670,7 +1670,7 @@ public static boolean isFileNewer(final File file, final Date date) {
16701670
*/
16711671
public static boolean isFileNewer(final File file, final File reference) {
16721672
requireExists(reference, "reference");
1673-
return UncheckedIO.get(() -> PathUtils.isNewer(file.toPath(), reference.toPath()));
1673+
return Uncheck.get(() -> PathUtils.isNewer(file.toPath(), reference.toPath()));
16741674
}
16751675

16761676
/**
@@ -1699,7 +1699,7 @@ public static boolean isFileNewer(final File file, final FileTime fileTime) thro
16991699
*/
17001700
public static boolean isFileNewer(final File file, final Instant instant) {
17011701
Objects.requireNonNull(instant, "instant");
1702-
return UncheckedIO.get(() -> PathUtils.isNewer(file.toPath(), instant));
1702+
return Uncheck.get(() -> PathUtils.isNewer(file.toPath(), instant));
17031703
}
17041704

17051705
/**
@@ -1713,7 +1713,7 @@ public static boolean isFileNewer(final File file, final Instant instant) {
17131713
*/
17141714
public static boolean isFileNewer(final File file, final long timeMillis) {
17151715
Objects.requireNonNull(file, "file");
1716-
return UncheckedIO.get(() -> PathUtils.isNewer(file.toPath(), timeMillis));
1716+
return Uncheck.get(() -> PathUtils.isNewer(file.toPath(), timeMillis));
17171717
}
17181718

17191719
/**
@@ -1874,7 +1874,7 @@ public static boolean isFileOlder(final File file, final Date date) {
18741874
*/
18751875
public static boolean isFileOlder(final File file, final File reference) {
18761876
requireExists(reference, "reference");
1877-
return UncheckedIO.get(() -> PathUtils.isOlder(file.toPath(), reference.toPath()));
1877+
return Uncheck.get(() -> PathUtils.isOlder(file.toPath(), reference.toPath()));
18781878
}
18791879

18801880
/**
@@ -1903,7 +1903,7 @@ public static boolean isFileOlder(final File file, final FileTime fileTime) thro
19031903
*/
19041904
public static boolean isFileOlder(final File file, final Instant instant) {
19051905
Objects.requireNonNull(instant, "instant");
1906-
return UncheckedIO.get(() -> PathUtils.isOlder(file.toPath(), instant));
1906+
return Uncheck.get(() -> PathUtils.isOlder(file.toPath(), instant));
19071907
}
19081908

19091909
/**
@@ -1917,7 +1917,7 @@ public static boolean isFileOlder(final File file, final Instant instant) {
19171917
*/
19181918
public static boolean isFileOlder(final File file, final long timeMillis) {
19191919
Objects.requireNonNull(file, "file");
1920-
return UncheckedIO.get(() -> PathUtils.isOlder(file.toPath(), timeMillis));
1920+
return Uncheck.get(() -> PathUtils.isOlder(file.toPath(), timeMillis));
19211921
}
19221922

19231923
/**
@@ -2006,7 +2006,7 @@ public static Iterator<File> iterateFiles(final File directory, final IOFileFilt
20062006
* @since 1.2
20072007
*/
20082008
public static Iterator<File> iterateFiles(final File directory, final String[] extensions, final boolean recursive) {
2009-
return UncheckedIO.apply(d -> StreamIterator.iterator(streamFiles(d, recursive, extensions)), directory);
2009+
return Uncheck.apply(d -> StreamIterator.iterator(streamFiles(d, recursive, extensions)), directory);
20102010
}
20112011

20122012
/**
@@ -2102,7 +2102,7 @@ public static long lastModifiedUnchecked(final File file) {
21022102
// https://bugs.openjdk.java.net/browse/JDK-8177809
21032103
// File.lastModified() is losing milliseconds (always ends in 000)
21042104
// This bug is in OpenJDK 8 and 9, and fixed in 10.
2105-
return UncheckedIO.apply(FileUtils::lastModified, file);
2105+
return Uncheck.apply(FileUtils::lastModified, file);
21062106
}
21072107

21082108
/**
@@ -2232,7 +2232,7 @@ private static File[] listFiles(final File directory, final FileFilter fileFilte
22322232
* @see org.apache.commons.io.filefilter.NameFileFilter
22332233
*/
22342234
public static Collection<File> listFiles(final File directory, final IOFileFilter fileFilter, final IOFileFilter dirFilter) {
2235-
final AccumulatorPathVisitor visitor = UncheckedIO
2235+
final AccumulatorPathVisitor visitor = Uncheck
22362236
.apply(d -> listAccumulate(d, FileFileFilter.INSTANCE.and(fileFilter), dirFilter, FileVisitOption.FOLLOW_LINKS), directory);
22372237
return visitor.getFileList().stream().map(Path::toFile).collect(Collectors.toList());
22382238
}
@@ -2248,7 +2248,7 @@ public static Collection<File> listFiles(final File directory, final IOFileFilte
22482248
* @return a collection of java.io.File with the matching files
22492249
*/
22502250
public static Collection<File> listFiles(final File directory, final String[] extensions, final boolean recursive) {
2251-
return UncheckedIO.apply(d -> toList(streamFiles(d, recursive, extensions)), directory);
2251+
return Uncheck.apply(d -> toList(streamFiles(d, recursive, extensions)), directory);
22522252
}
22532253

22542254
/**
@@ -2271,7 +2271,7 @@ public static Collection<File> listFiles(final File directory, final String[] ex
22712271
* @since 2.2
22722272
*/
22732273
public static Collection<File> listFilesAndDirs(final File directory, final IOFileFilter fileFilter, final IOFileFilter dirFilter) {
2274-
final AccumulatorPathVisitor visitor = UncheckedIO.apply(d -> listAccumulate(d, fileFilter, dirFilter, FileVisitOption.FOLLOW_LINKS),
2274+
final AccumulatorPathVisitor visitor = Uncheck.apply(d -> listAccumulate(d, fileFilter, dirFilter, FileVisitOption.FOLLOW_LINKS),
22752275
directory);
22762276
final List<Path> list = visitor.getFileList();
22772277
list.addAll(visitor.getDirList());
@@ -2923,7 +2923,7 @@ private static void setLastModified(final File file, final long timeMillis) thro
29232923
*/
29242924
public static long sizeOf(final File file) {
29252925
requireExists(file, "file");
2926-
return UncheckedIO.get(() -> PathUtils.sizeOf(file.toPath()));
2926+
return Uncheck.get(() -> PathUtils.sizeOf(file.toPath()));
29272927
}
29282928

29292929
/**
@@ -2946,7 +2946,7 @@ public static long sizeOf(final File file) {
29462946
*/
29472947
public static BigInteger sizeOfAsBigInteger(final File file) {
29482948
requireExists(file, "file");
2949-
return UncheckedIO.get(() -> PathUtils.sizeOfAsBigInteger(file.toPath()));
2949+
return Uncheck.get(() -> PathUtils.sizeOfAsBigInteger(file.toPath()));
29502950
}
29512951

29522952
/**
@@ -2965,7 +2965,7 @@ public static BigInteger sizeOfAsBigInteger(final File file) {
29652965
*/
29662966
public static long sizeOfDirectory(final File directory) {
29672967
requireDirectoryExists(directory, "directory");
2968-
return UncheckedIO.get(() -> PathUtils.sizeOfDirectory(directory.toPath()));
2968+
return Uncheck.get(() -> PathUtils.sizeOfDirectory(directory.toPath()));
29692969
}
29702970

29712971
/**
@@ -2979,7 +2979,7 @@ public static long sizeOfDirectory(final File directory) {
29792979
*/
29802980
public static BigInteger sizeOfDirectoryAsBigInteger(final File directory) {
29812981
requireDirectoryExists(directory, "directory");
2982-
return UncheckedIO.get(() -> PathUtils.sizeOfDirectoryAsBigInteger(directory.toPath()));
2982+
return Uncheck.get(() -> PathUtils.sizeOfDirectoryAsBigInteger(directory.toPath()));
29832983
}
29842984

29852985
/**

src/main/java/org/apache/commons/io/UncheckedIO.java renamed to src/main/java/org/apache/commons/io/Uncheck.java

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
import org.apache.commons.io.function.IOTriFunction;
3333

3434
/**
35-
* Helps use lambdas that throw {@link IOException} rethrow as {@link UncheckedIOException}.
35+
* Unchecks calls by throwing {@link UncheckedIOException} instead of {@link IOException}.
3636
*
3737
* @since 2.12.0
3838
*/
39-
public class UncheckedIO {
39+
public class Uncheck {
4040

4141
/**
4242
* Accepts an IO consumer with the given arguments.
@@ -95,14 +95,13 @@ public static <T, U, V> void accept(final IOTriConsumer<T, U, V> consumer, final
9595
/**
9696
* Applies an IO function with the given arguments.
9797
*
98-
* @param function the function.
9998
* @param <T> the first function argument type.
10099
* @param <U> the second function argument type.
101100
* @param <R> the return type.
102-
*
103-
* @param t the first function argument
104-
* @param u the second function argument
105-
* @return the function result
101+
* @param function the function.
102+
* @param t the first function argument.
103+
* @param u the second function argument.
104+
* @return the function result.
106105
* @throws UncheckedIOException if an I/O error occurs.
107106
*/
108107
public static <T, U, R> R apply(final IOBiFunction<T, U, R> function, final T t, final U u) {
@@ -119,9 +118,8 @@ public static <T, U, R> R apply(final IOBiFunction<T, U, R> function, final T t,
119118
* @param function the function.
120119
* @param <T> the first function argument type.
121120
* @param <R> the return type.
122-
*
123-
* @param t the first function argument
124-
* @return the function result
121+
* @param t the first function argument.
122+
* @return the function result.
125123
* @throws UncheckedIOException if an I/O error occurs.
126124
*/
127125
public static <T, R> R apply(final IOFunction<T, R> function, final T t) {
@@ -141,12 +139,11 @@ public static <T, R> R apply(final IOFunction<T, R> function, final T t) {
141139
* @param <V> the third function argument type.
142140
* @param <W> the fourth function argument type.
143141
* @param <R> the return type.
144-
*
145-
* @param t the first function argument
146-
* @param u the second function argument
147-
* @param v the third function argument
148-
* @param w the fourth function argument
149-
* @return the function result
142+
* @param t the first function argument.
143+
* @param u the second function argument.
144+
* @param v the third function argument.
145+
* @param w the fourth function argument.
146+
* @return the function result.
150147
* @throws UncheckedIOException if an I/O error occurs.
151148
*/
152149
public static <T, U, V, W, R> R apply(final IOQuadFunction<T, U, V, W, R> function, final T t, final U u, final V v, final W w) {
@@ -160,16 +157,15 @@ public static <T, U, V, W, R> R apply(final IOQuadFunction<T, U, V, W, R> functi
160157
/**
161158
* Applies an IO tri-function with the given arguments.
162159
*
163-
* @param function the function.
164160
* @param <T> the first function argument type.
165161
* @param <U> the second function argument type.
166162
* @param <V> the third function argument type.
167163
* @param <R> the return type.
168-
*
169-
* @param t the first function argument
170-
* @param u the second function argument
171-
* @param v the third function argument
172-
* @return the function result
164+
* @param function the function.
165+
* @param t the first function argument.
166+
* @param u the second function argument.
167+
* @param v the third function argument.
168+
* @return the function result.
173169
* @throws UncheckedIOException if an I/O error occurs.
174170
*/
175171
public static <T, U, V, R> R apply(final IOTriFunction<T, U, V, R> function, final T t, final U u, final V v) {
@@ -211,12 +207,12 @@ public static void run(final IORunnable runnable) {
211207
}
212208

213209
/**
214-
* Tests an IO predicate
210+
* Tests an IO predicate.
215211
*
216-
* @param <T> the type of the input to the predicate
217-
* @param predicate the predicate
218-
* @param t the input to the predicate
219-
* @return {@code true} if the input argument matches the predicate, otherwise {@code false}
212+
* @param <T> the type of the input to the predicate.
213+
* @param predicate the predicate.
214+
* @param t the input to the predicate.
215+
* @return {@code true} if the input argument matches the predicate, otherwise {@code false}.
220216
*/
221217
public static <T> boolean test(final IOPredicate<T> predicate, final T t) {
222218
try {
@@ -242,7 +238,7 @@ private static UncheckedIOException wrap(final IOException e) {
242238
/**
243239
* No instances needed.
244240
*/
245-
private UncheckedIO() {
241+
private Uncheck() {
246242
// no instances needed.
247243
}
248244
}

0 commit comments

Comments
 (0)