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 7adb12218adbb643d24546fe630f1d0c77db5cfd Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Sun Jul 24 12:36:57 2022 -0400 Rename new class --- src/main/java/org/apache/commons/io/FileUtils.java | 32 +++--- .../commons/io/{UncheckedIO.java => Uncheck.java} | 52 +++++----- .../org/apache/commons/io/file/FilesUncheck.java | 112 ++++++++++----------- .../java/org/apache/commons/io/file/PathUtils.java | 6 +- .../apache/commons/io/function/IOPredicate.java | 4 +- .../commons/io/input/UncheckedBufferedReader.java | 22 ++-- .../io/input/UncheckedFilterInputStream.java | 16 +-- .../commons/io/input/UncheckedFilterReader.java | 20 ++-- .../commons/io/output/UncheckedAppendableImpl.java | 8 +- .../io/output/UncheckedFilterOutputStream.java | 12 +-- .../commons/io/output/UncheckedFilterWriter.java | 66 +++--------- .../commons/io/UncheckedIOExceptionsTest.java | 2 +- .../org/apache/commons/io/UncheckedIOTest.java | 32 +++--- .../apache/commons/io/file/FilesUncheckTest.java | 24 ++--- 14 files changed, 181 insertions(+), 227 deletions(-) diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java index 58ae0ff7..12767d13 100644 --- a/src/main/java/org/apache/commons/io/FileUtils.java +++ b/src/main/java/org/apache/commons/io/FileUtils.java @@ -1641,7 +1641,7 @@ public class FileUtils { public static boolean isFileNewer(final File file, final ChronoZonedDateTime<?> chronoZonedDateTime) { Objects.requireNonNull(file, "file"); Objects.requireNonNull(chronoZonedDateTime, "chronoZonedDateTime"); - return UncheckedIO.get(() -> PathUtils.isNewer(file.toPath(), chronoZonedDateTime)); + return Uncheck.get(() -> PathUtils.isNewer(file.toPath(), chronoZonedDateTime)); } /** @@ -1670,7 +1670,7 @@ public class FileUtils { */ public static boolean isFileNewer(final File file, final File reference) { requireExists(reference, "reference"); - return UncheckedIO.get(() -> PathUtils.isNewer(file.toPath(), reference.toPath())); + return Uncheck.get(() -> PathUtils.isNewer(file.toPath(), reference.toPath())); } /** @@ -1699,7 +1699,7 @@ public class FileUtils { */ public static boolean isFileNewer(final File file, final Instant instant) { Objects.requireNonNull(instant, "instant"); - return UncheckedIO.get(() -> PathUtils.isNewer(file.toPath(), instant)); + return Uncheck.get(() -> PathUtils.isNewer(file.toPath(), instant)); } /** @@ -1713,7 +1713,7 @@ public class FileUtils { */ public static boolean isFileNewer(final File file, final long timeMillis) { Objects.requireNonNull(file, "file"); - return UncheckedIO.get(() -> PathUtils.isNewer(file.toPath(), timeMillis)); + return Uncheck.get(() -> PathUtils.isNewer(file.toPath(), timeMillis)); } /** @@ -1874,7 +1874,7 @@ public class FileUtils { */ public static boolean isFileOlder(final File file, final File reference) { requireExists(reference, "reference"); - return UncheckedIO.get(() -> PathUtils.isOlder(file.toPath(), reference.toPath())); + return Uncheck.get(() -> PathUtils.isOlder(file.toPath(), reference.toPath())); } /** @@ -1903,7 +1903,7 @@ public class FileUtils { */ public static boolean isFileOlder(final File file, final Instant instant) { Objects.requireNonNull(instant, "instant"); - return UncheckedIO.get(() -> PathUtils.isOlder(file.toPath(), instant)); + return Uncheck.get(() -> PathUtils.isOlder(file.toPath(), instant)); } /** @@ -1917,7 +1917,7 @@ public class FileUtils { */ public static boolean isFileOlder(final File file, final long timeMillis) { Objects.requireNonNull(file, "file"); - return UncheckedIO.get(() -> PathUtils.isOlder(file.toPath(), timeMillis)); + return Uncheck.get(() -> PathUtils.isOlder(file.toPath(), timeMillis)); } /** @@ -2006,7 +2006,7 @@ public class FileUtils { * @since 1.2 */ public static Iterator<File> iterateFiles(final File directory, final String[] extensions, final boolean recursive) { - return UncheckedIO.apply(d -> StreamIterator.iterator(streamFiles(d, recursive, extensions)), directory); + return Uncheck.apply(d -> StreamIterator.iterator(streamFiles(d, recursive, extensions)), directory); } /** @@ -2102,7 +2102,7 @@ public class FileUtils { // https://bugs.openjdk.java.net/browse/JDK-8177809 // File.lastModified() is losing milliseconds (always ends in 000) // This bug is in OpenJDK 8 and 9, and fixed in 10. - return UncheckedIO.apply(FileUtils::lastModified, file); + return Uncheck.apply(FileUtils::lastModified, file); } /** @@ -2232,7 +2232,7 @@ public class FileUtils { * @see org.apache.commons.io.filefilter.NameFileFilter */ public static Collection<File> listFiles(final File directory, final IOFileFilter fileFilter, final IOFileFilter dirFilter) { - final AccumulatorPathVisitor visitor = UncheckedIO + final AccumulatorPathVisitor visitor = Uncheck .apply(d -> listAccumulate(d, FileFileFilter.INSTANCE.and(fileFilter), dirFilter, FileVisitOption.FOLLOW_LINKS), directory); return visitor.getFileList().stream().map(Path::toFile).collect(Collectors.toList()); } @@ -2248,7 +2248,7 @@ public class FileUtils { * @return a collection of java.io.File with the matching files */ public static Collection<File> listFiles(final File directory, final String[] extensions, final boolean recursive) { - return UncheckedIO.apply(d -> toList(streamFiles(d, recursive, extensions)), directory); + return Uncheck.apply(d -> toList(streamFiles(d, recursive, extensions)), directory); } /** @@ -2271,7 +2271,7 @@ public class FileUtils { * @since 2.2 */ public static Collection<File> listFilesAndDirs(final File directory, final IOFileFilter fileFilter, final IOFileFilter dirFilter) { - final AccumulatorPathVisitor visitor = UncheckedIO.apply(d -> listAccumulate(d, fileFilter, dirFilter, FileVisitOption.FOLLOW_LINKS), + final AccumulatorPathVisitor visitor = Uncheck.apply(d -> listAccumulate(d, fileFilter, dirFilter, FileVisitOption.FOLLOW_LINKS), directory); final List<Path> list = visitor.getFileList(); list.addAll(visitor.getDirList()); @@ -2923,7 +2923,7 @@ public class FileUtils { */ public static long sizeOf(final File file) { requireExists(file, "file"); - return UncheckedIO.get(() -> PathUtils.sizeOf(file.toPath())); + return Uncheck.get(() -> PathUtils.sizeOf(file.toPath())); } /** @@ -2946,7 +2946,7 @@ public class FileUtils { */ public static BigInteger sizeOfAsBigInteger(final File file) { requireExists(file, "file"); - return UncheckedIO.get(() -> PathUtils.sizeOfAsBigInteger(file.toPath())); + return Uncheck.get(() -> PathUtils.sizeOfAsBigInteger(file.toPath())); } /** @@ -2965,7 +2965,7 @@ public class FileUtils { */ public static long sizeOfDirectory(final File directory) { requireDirectoryExists(directory, "directory"); - return UncheckedIO.get(() -> PathUtils.sizeOfDirectory(directory.toPath())); + return Uncheck.get(() -> PathUtils.sizeOfDirectory(directory.toPath())); } /** @@ -2979,7 +2979,7 @@ public class FileUtils { */ public static BigInteger sizeOfDirectoryAsBigInteger(final File directory) { requireDirectoryExists(directory, "directory"); - return UncheckedIO.get(() -> PathUtils.sizeOfDirectoryAsBigInteger(directory.toPath())); + return Uncheck.get(() -> PathUtils.sizeOfDirectoryAsBigInteger(directory.toPath())); } /** diff --git a/src/main/java/org/apache/commons/io/UncheckedIO.java b/src/main/java/org/apache/commons/io/Uncheck.java similarity index 88% rename from src/main/java/org/apache/commons/io/UncheckedIO.java rename to src/main/java/org/apache/commons/io/Uncheck.java index 37bc3a32..64b620d6 100644 --- a/src/main/java/org/apache/commons/io/UncheckedIO.java +++ b/src/main/java/org/apache/commons/io/Uncheck.java @@ -32,11 +32,11 @@ import org.apache.commons.io.function.IOTriConsumer; import org.apache.commons.io.function.IOTriFunction; /** - * Helps use lambdas that throw {@link IOException} rethrow as {@link UncheckedIOException}. + * Unchecks calls by throwing {@link UncheckedIOException} instead of {@link IOException}. * * @since 2.12.0 */ -public class UncheckedIO { +public class Uncheck { /** * Accepts an IO consumer with the given arguments. @@ -95,14 +95,13 @@ public class UncheckedIO { /** * Applies an IO function with the given arguments. * - * @param function the function. * @param <T> the first function argument type. * @param <U> the second function argument type. * @param <R> the return type. - * - * @param t the first function argument - * @param u the second function argument - * @return the function result + * @param function the function. + * @param t the first function argument. + * @param u the second function argument. + * @return the function result. * @throws UncheckedIOException if an I/O error occurs. */ public static <T, U, R> R apply(final IOBiFunction<T, U, R> function, final T t, final U u) { @@ -119,9 +118,8 @@ public class UncheckedIO { * @param function the function. * @param <T> the first function argument type. * @param <R> the return type. - * - * @param t the first function argument - * @return the function result + * @param t the first function argument. + * @return the function result. * @throws UncheckedIOException if an I/O error occurs. */ public static <T, R> R apply(final IOFunction<T, R> function, final T t) { @@ -141,12 +139,11 @@ public class UncheckedIO { * @param <V> the third function argument type. * @param <W> the fourth function argument type. * @param <R> the return type. - * - * @param t the first function argument - * @param u the second function argument - * @param v the third function argument - * @param w the fourth function argument - * @return the function result + * @param t the first function argument. + * @param u the second function argument. + * @param v the third function argument. + * @param w the fourth function argument. + * @return the function result. * @throws UncheckedIOException if an I/O error occurs. */ 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 class UncheckedIO { /** * Applies an IO tri-function with the given arguments. * - * @param function the function. * @param <T> the first function argument type. * @param <U> the second function argument type. * @param <V> the third function argument type. * @param <R> the return type. - * - * @param t the first function argument - * @param u the second function argument - * @param v the third function argument - * @return the function result + * @param function the function. + * @param t the first function argument. + * @param u the second function argument. + * @param v the third function argument. + * @return the function result. * @throws UncheckedIOException if an I/O error occurs. */ 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 class UncheckedIO { } /** - * Tests an IO predicate + * Tests an IO predicate. * - * @param <T> the type of the input to the predicate - * @param predicate the predicate - * @param t the input to the predicate - * @return {@code true} if the input argument matches the predicate, otherwise {@code false} + * @param <T> the type of the input to the predicate. + * @param predicate the predicate. + * @param t the input to the predicate. + * @return {@code true} if the input argument matches the predicate, otherwise {@code false}. */ public static <T> boolean test(final IOPredicate<T> predicate, final T t) { try { @@ -242,7 +238,7 @@ public class UncheckedIO { /** * No instances needed. */ - private UncheckedIO() { + private Uncheck() { // no instances needed. } } diff --git a/src/main/java/org/apache/commons/io/file/FilesUncheck.java b/src/main/java/org/apache/commons/io/file/FilesUncheck.java index 06de080b..8a406278 100644 --- a/src/main/java/org/apache/commons/io/file/FilesUncheck.java +++ b/src/main/java/org/apache/commons/io/file/FilesUncheck.java @@ -44,7 +44,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Stream; -import org.apache.commons.io.UncheckedIO; +import org.apache.commons.io.Uncheck; /** * Delegates to {@link Files} to uncheck calls by throwing {@link UncheckedIOException} instead of {@link IOException}. @@ -68,7 +68,7 @@ public class FilesUncheck { * @see Files#copy(InputStream, Path,CopyOption...) */ public static long copy(final InputStream in, final Path target, final CopyOption... options) { - return UncheckedIO.apply(Files::copy, in, target, options); + return Uncheck.apply(Files::copy, in, target, options); } /** @@ -81,7 +81,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static long copy(final Path source, final OutputStream out) { - return UncheckedIO.apply(Files::copy, source, out); + return Uncheck.apply(Files::copy, source, out); } /** @@ -95,7 +95,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Path copy(final Path source, final Path target, final CopyOption... options) { - return UncheckedIO.apply(Files::copy, source, target, options); + return Uncheck.apply(Files::copy, source, target, options); } /** @@ -108,7 +108,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Path createDirectories(final Path dir, final FileAttribute<?>... attrs) { - return UncheckedIO.apply(Files::createDirectories, dir, attrs); + return Uncheck.apply(Files::createDirectories, dir, attrs); } /** @@ -121,7 +121,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Path createDirectory(final Path dir, final FileAttribute<?>... attrs) { - return UncheckedIO.apply(Files::createDirectory, dir, attrs); + return Uncheck.apply(Files::createDirectory, dir, attrs); } /** @@ -134,7 +134,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Path createFile(final Path path, final FileAttribute<?>... attrs) { - return UncheckedIO.apply(Files::createFile, path, attrs); + return Uncheck.apply(Files::createFile, path, attrs); } /** @@ -147,7 +147,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Path createLink(final Path link, final Path existing) { - return UncheckedIO.apply(Files::createLink, link, existing); + return Uncheck.apply(Files::createLink, link, existing); } /** @@ -161,7 +161,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Path createSymbolicLink(final Path link, final Path target, final FileAttribute<?>... attrs) { - return UncheckedIO.apply(Files::createSymbolicLink, link, target, attrs); + return Uncheck.apply(Files::createSymbolicLink, link, target, attrs); } /** @@ -175,7 +175,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Path createTempDirectory(final Path dir, final String prefix, final FileAttribute<?>... attrs) { - return UncheckedIO.apply(Files::createTempDirectory, dir, prefix, attrs); + return Uncheck.apply(Files::createTempDirectory, dir, prefix, attrs); } /** @@ -188,7 +188,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Path createTempDirectory(final String prefix, final FileAttribute<?>... attrs) { - return UncheckedIO.apply(Files::createTempDirectory, prefix, attrs); + return Uncheck.apply(Files::createTempDirectory, prefix, attrs); } /** @@ -203,7 +203,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Path createTempFile(final Path dir, final String prefix, final String suffix, final FileAttribute<?>... attrs) { - return UncheckedIO.apply(Files::createTempFile, dir, prefix, suffix, attrs); + return Uncheck.apply(Files::createTempFile, dir, prefix, suffix, attrs); } /** @@ -217,7 +217,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Path createTempFile(final String prefix, final String suffix, final FileAttribute<?>... attrs) { - return UncheckedIO.apply(Files::createTempFile, prefix, suffix, attrs); + return Uncheck.apply(Files::createTempFile, prefix, suffix, attrs); } /** @@ -227,7 +227,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static void delete(final Path path) { - UncheckedIO.accept(Files::delete, path); + Uncheck.accept(Files::delete, path); } /** @@ -238,7 +238,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static boolean deleteIfExists(final Path path) { - return UncheckedIO.apply(Files::deleteIfExists, path); + return Uncheck.apply(Files::deleteIfExists, path); } /** @@ -252,7 +252,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Object getAttribute(final Path path, final String attribute, final LinkOption... options) { - return UncheckedIO.apply(Files::getAttribute, path, attribute, options); + return Uncheck.apply(Files::getAttribute, path, attribute, options); } /** @@ -263,7 +263,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static FileStore getFileStore(final Path path) { - return UncheckedIO.apply(Files::getFileStore, path); + return Uncheck.apply(Files::getFileStore, path); } /** @@ -276,7 +276,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static FileTime getLastModifiedTime(final Path path, final LinkOption... options) { - return UncheckedIO.apply(Files::getLastModifiedTime, path, options); + return Uncheck.apply(Files::getLastModifiedTime, path, options); } /** @@ -289,7 +289,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static UserPrincipal getOwner(final Path path, final LinkOption... options) { - return UncheckedIO.apply(Files::getOwner, path, options); + return Uncheck.apply(Files::getOwner, path, options); } /** @@ -302,7 +302,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Set<PosixFilePermission> getPosixFilePermissions(final Path path, final LinkOption... options) { - return UncheckedIO.apply(Files::getPosixFilePermissions, path, options); + return Uncheck.apply(Files::getPosixFilePermissions, path, options); } /** @@ -313,7 +313,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static boolean isHidden(final Path path) { - return UncheckedIO.apply(Files::isHidden, path); + return Uncheck.apply(Files::isHidden, path); } /** @@ -326,7 +326,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static boolean isSameFile(final Path path, final Path path2) { - return UncheckedIO.apply(Files::isSameFile, path, path2); + return Uncheck.apply(Files::isSameFile, path, path2); } /** @@ -337,7 +337,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Stream<String> lines(final Path path) { - return UncheckedIO.apply(Files::lines, path); + return Uncheck.apply(Files::lines, path); } /** @@ -349,7 +349,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Stream<String> lines(final Path path, final Charset cs) { - return UncheckedIO.apply(Files::lines, path, cs); + return Uncheck.apply(Files::lines, path, cs); } /** @@ -360,7 +360,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Stream<Path> list(final Path dir) { - return UncheckedIO.apply(Files::list, dir); + return Uncheck.apply(Files::list, dir); } /** @@ -374,7 +374,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static Path move(final Path source, final Path target, final CopyOption... options) { - return UncheckedIO.apply(Files::move, source, target, options); + return Uncheck.apply(Files::move, source, target, options); } /** @@ -386,7 +386,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static BufferedReader newBufferedReader(final Path path) { - return UncheckedIO.apply(Files::newBufferedReader, path); + return Uncheck.apply(Files::newBufferedReader, path); } /** @@ -399,7 +399,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static BufferedReader newBufferedReader(final Path path, final Charset cs) { - return UncheckedIO.apply(Files::newBufferedReader, path, cs); + return Uncheck.apply(Files::newBufferedReader, path, cs); } /** @@ -413,7 +413,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static BufferedWriter newBufferedWriter(final Path path, final Charset cs, final OpenOption... options) { - return UncheckedIO.apply(Files::newBufferedWriter, path, cs, options); + return Uncheck.apply(Files::newBufferedWriter, path, cs, options); } /** @@ -426,7 +426,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static BufferedWriter newBufferedWriter(final Path path, final OpenOption... options) { - return UncheckedIO.apply(Files::newBufferedWriter, path, options); + return Uncheck.apply(Files::newBufferedWriter, path, options); } /** @@ -439,7 +439,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static SeekableByteChannel newByteChannel(final Path path, final OpenOption... options) { - return UncheckedIO.apply(Files::newByteChannel, path, options); + return Uncheck.apply(Files::newByteChannel, path, options); } /** @@ -453,7 +453,7 @@ public class FilesUncheck { * @throws UncheckedIOException Wraps an {@link IOException}. */ public static SeekableByteChannel newByteChannel(final Path path, final Set<? extends OpenOption> options, final FileAttribute<?>... attrs) { - return UncheckedIO.apply(Files::newByteChannel, path, options, attrs); + return Uncheck.apply(Files::newByteChannel, path, options, attrs); } /** @@ -464,7 +464,7 @@ public class FilesUncheck { * @return See delegate. See delegate. */ public static DirectoryStream<Path> newDirectoryStream(final Path dir) { - return UncheckedIO.apply(Files::newDirectoryStream, dir); + return Uncheck.apply(Files::newDirectoryStream, dir); } /** @@ -476,7 +476,7 @@ public class FilesUncheck { * @return See delegate. */ public static DirectoryStream<Path> newDirectoryStream(final Path dir, final String glob) { - return UncheckedIO.apply(Files::newDirectoryStream, dir, glob); + return Uncheck.apply(Files::newDirectoryStream, dir, glob); } /** @@ -488,7 +488,7 @@ public class FilesUncheck { * @return See delegate. */ public static DirectoryStream<Path> newDirectoryStream(final Path dir, final DirectoryStream.Filter<? super Path> filter) { - return UncheckedIO.apply(Files::newDirectoryStream, dir, filter); + return Uncheck.apply(Files::newDirectoryStream, dir, filter); } /** @@ -500,7 +500,7 @@ public class FilesUncheck { * @return See delegate. */ public static InputStream newInputStream(final Path path, final OpenOption... options) { - return UncheckedIO.apply(Files::newInputStream, path, options); + return Uncheck.apply(Files::newInputStream, path, options); } /** @@ -512,7 +512,7 @@ public class FilesUncheck { * @return See delegate. */ public static OutputStream newOutputStream(final Path path, final OpenOption... options) { - return UncheckedIO.apply(Files::newOutputStream, path, options); + return Uncheck.apply(Files::newOutputStream, path, options); } /** @@ -523,7 +523,7 @@ public class FilesUncheck { * @return See delegate. */ public static String probeContentType(final Path path) { - return UncheckedIO.apply(Files::probeContentType, path); + return Uncheck.apply(Files::probeContentType, path); } /** @@ -533,7 +533,7 @@ public class FilesUncheck { * @return See delegate. */ public static byte[] readAllBytes(final Path path) { - return UncheckedIO.apply(Files::readAllBytes, path); + return Uncheck.apply(Files::readAllBytes, path); } /** @@ -543,7 +543,7 @@ public class FilesUncheck { * @return See delegate. */ public static List<String> readAllLines(final Path path) { - return UncheckedIO.apply(Files::readAllLines, path); + return Uncheck.apply(Files::readAllLines, path); } /** @@ -555,7 +555,7 @@ public class FilesUncheck { * @return See delegate. */ public static List<String> readAllLines(final Path path, final Charset cs) { - return UncheckedIO.apply(Files::readAllLines, path, cs); + return Uncheck.apply(Files::readAllLines, path, cs); } /** @@ -569,7 +569,7 @@ public class FilesUncheck { * @return See delegate. */ public static <A extends BasicFileAttributes> A readAttributes(final Path path, final Class<A> type, final LinkOption... options) { - return UncheckedIO.apply(Files::readAttributes, path, type, options); + return Uncheck.apply(Files::readAttributes, path, type, options); } /** @@ -582,7 +582,7 @@ public class FilesUncheck { * @return See delegate. */ public static Map<String, Object> readAttributes(final Path path, final String attributes, final LinkOption... options) { - return UncheckedIO.apply(Files::readAttributes, path, attributes, options); + return Uncheck.apply(Files::readAttributes, path, attributes, options); } /** @@ -593,7 +593,7 @@ public class FilesUncheck { * @return See delegate. */ public static Path readSymbolicLink(final Path link) { - return UncheckedIO.apply(Files::readSymbolicLink, link); + return Uncheck.apply(Files::readSymbolicLink, link); } /** @@ -607,7 +607,7 @@ public class FilesUncheck { * @return See delegate. */ public static Path setAttribute(final Path path, final String attribute, final Object value, final LinkOption... options) { - return UncheckedIO.apply(Files::setAttribute, path, attribute, value, options); + return Uncheck.apply(Files::setAttribute, path, attribute, value, options); } /** @@ -619,7 +619,7 @@ public class FilesUncheck { * @return See delegate. */ public static Path setLastModifiedTime(final Path path, final FileTime time) { - return UncheckedIO.apply(Files::setLastModifiedTime, path, time); + return Uncheck.apply(Files::setLastModifiedTime, path, time); } /** @@ -631,7 +631,7 @@ public class FilesUncheck { * @return See delegate. */ public static Path setOwner(final Path path, final UserPrincipal owner) { - return UncheckedIO.apply(Files::setOwner, path, owner); + return Uncheck.apply(Files::setOwner, path, owner); } /** @@ -643,7 +643,7 @@ public class FilesUncheck { * @return See delegate. */ public static Path setPosixFilePermissions(final Path path, final Set<PosixFilePermission> perms) { - return UncheckedIO.apply(Files::setPosixFilePermissions, path, perms); + return Uncheck.apply(Files::setPosixFilePermissions, path, perms); } /** @@ -653,7 +653,7 @@ public class FilesUncheck { * @return See delegate. */ public static long size(final Path path) { - return UncheckedIO.apply(Files::size, path); + return Uncheck.apply(Files::size, path); } /** @@ -666,7 +666,7 @@ public class FilesUncheck { * @return See delegate. */ public static Stream<Path> walk(final Path start, final int maxDepth, final FileVisitOption... options) { - return UncheckedIO.apply(Files::walk, start, maxDepth, options); + return Uncheck.apply(Files::walk, start, maxDepth, options); } /** @@ -678,7 +678,7 @@ public class FilesUncheck { * @return See delegate. */ public static Stream<Path> walk(final Path start, final FileVisitOption... options) { - return UncheckedIO.apply(Files::walk, start, options); + return Uncheck.apply(Files::walk, start, options); } /** @@ -690,7 +690,7 @@ public class FilesUncheck { * @return See delegate. */ public static Path walkFileTree(final Path start, final FileVisitor<? super Path> visitor) { - return UncheckedIO.apply(Files::walkFileTree, start, visitor); + return Uncheck.apply(Files::walkFileTree, start, visitor); } /** @@ -704,7 +704,7 @@ public class FilesUncheck { * @return See delegate. */ public static Path walkFileTree(final Path start, final Set<FileVisitOption> options, final int maxDepth, final FileVisitor<? super Path> visitor) { - return UncheckedIO.apply(Files::walkFileTree, start, options, maxDepth, visitor); + return Uncheck.apply(Files::walkFileTree, start, options, maxDepth, visitor); } /** @@ -717,7 +717,7 @@ public class FilesUncheck { * @return See delegate. */ public static Path write(final Path path, final byte[] bytes, final OpenOption... options) { - return UncheckedIO.apply(Files::write, path, bytes, options); + return Uncheck.apply(Files::write, path, bytes, options); } /** @@ -731,7 +731,7 @@ public class FilesUncheck { * @return See delegate. */ public static Path write(final Path path, final Iterable<? extends CharSequence> lines, final Charset cs, final OpenOption... options) { - return UncheckedIO.apply(Files::write, path, lines, cs, options); + return Uncheck.apply(Files::write, path, lines, cs, options); } /** @@ -744,7 +744,7 @@ public class FilesUncheck { * @return See delegate. */ public static Path write(final Path path, final Iterable<? extends CharSequence> lines, final OpenOption... options) { - return UncheckedIO.apply(Files::write, path, lines, options); + return Uncheck.apply(Files::write, path, lines, options); } /** 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 f8b2d470..18d06e50 100644 --- a/src/main/java/org/apache/commons/io/file/PathUtils.java +++ b/src/main/java/org/apache/commons/io/file/PathUtils.java @@ -70,7 +70,7 @@ import java.util.stream.Stream; import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; -import org.apache.commons.io.UncheckedIO; +import org.apache.commons.io.Uncheck; import org.apache.commons.io.file.Counters.PathCounters; import org.apache.commons.io.file.attribute.FileTimes; import org.apache.commons.io.filefilter.IOFileFilter; @@ -1198,7 +1198,7 @@ public final class PathUtils { /** * Reads the BasicFileAttributes from the given path. Returns null instead of throwing - * {@link UnsupportedOperationException}. Throws {@link UncheckedIO} instead of {@link IOException}. + * {@link UnsupportedOperationException}. Throws {@link Uncheck} instead of {@link IOException}. * * @param <A> The {@link BasicFileAttributes} type * @param path The Path to test. @@ -1210,7 +1210,7 @@ public final class PathUtils { */ public static <A extends BasicFileAttributes> A readAttributes(final Path path, final Class<A> type, final LinkOption... options) { try { - return path == null ? null : UncheckedIO.apply(Files::readAttributes, path, type, options); + return path == null ? null : Uncheck.apply(Files::readAttributes, path, type, options); } catch (final UnsupportedOperationException e) { // For example, on Windows. return null; diff --git a/src/main/java/org/apache/commons/io/function/IOPredicate.java b/src/main/java/org/apache/commons/io/function/IOPredicate.java index f94aba96..f12b1f97 100644 --- a/src/main/java/org/apache/commons/io/function/IOPredicate.java +++ b/src/main/java/org/apache/commons/io/function/IOPredicate.java @@ -22,7 +22,7 @@ import java.io.UncheckedIOException; import java.util.Objects; import java.util.function.Predicate; -import org.apache.commons.io.UncheckedIO; +import org.apache.commons.io.Uncheck; /** * Like {@link Predicate} but throws {@link IOException}. @@ -92,7 +92,7 @@ public interface IOPredicate<T> { * @return an unchecked Predicate. */ default Predicate<T> asPredicate() { - return t -> UncheckedIO.test(this, t); + return t -> Uncheck.test(this, t); } /** diff --git a/src/main/java/org/apache/commons/io/input/UncheckedBufferedReader.java b/src/main/java/org/apache/commons/io/input/UncheckedBufferedReader.java index a73b73cd..8ab8b544 100644 --- a/src/main/java/org/apache/commons/io/input/UncheckedBufferedReader.java +++ b/src/main/java/org/apache/commons/io/input/UncheckedBufferedReader.java @@ -23,7 +23,7 @@ import java.io.Reader; import java.io.UncheckedIOException; import java.nio.CharBuffer; -import org.apache.commons.io.UncheckedIO; +import org.apache.commons.io.Uncheck; /** * A {@link BufferedReader} that throws {@link UncheckedIOException} instead of {@link IOException}. @@ -72,7 +72,7 @@ public class UncheckedBufferedReader extends BufferedReader { */ @Override public void close() throws UncheckedIOException { - UncheckedIO.run(super::close); + Uncheck.run(super::close); } /** @@ -80,7 +80,7 @@ public class UncheckedBufferedReader extends BufferedReader { */ @Override public void mark(final int readAheadLimit) throws UncheckedIOException { - UncheckedIO.accept(super::mark, readAheadLimit); + Uncheck.accept(super::mark, readAheadLimit); } /** @@ -88,7 +88,7 @@ public class UncheckedBufferedReader extends BufferedReader { */ @Override public int read() throws UncheckedIOException { - return UncheckedIO.get(super::read); + return Uncheck.get(super::read); } /** @@ -96,7 +96,7 @@ public class UncheckedBufferedReader extends BufferedReader { */ @Override public int read(final char[] cbuf) throws UncheckedIOException { - return UncheckedIO.apply(super::read, cbuf); + return Uncheck.apply(super::read, cbuf); } /** @@ -104,7 +104,7 @@ public class UncheckedBufferedReader extends BufferedReader { */ @Override public int read(final char[] cbuf, final int off, final int len) throws UncheckedIOException { - return UncheckedIO.apply(super::read, cbuf, off, len); + return Uncheck.apply(super::read, cbuf, off, len); } /** @@ -112,7 +112,7 @@ public class UncheckedBufferedReader extends BufferedReader { */ @Override public int read(final CharBuffer target) throws UncheckedIOException { - return UncheckedIO.apply(super::read, target); + return Uncheck.apply(super::read, target); } /** @@ -120,7 +120,7 @@ public class UncheckedBufferedReader extends BufferedReader { */ @Override public String readLine() throws UncheckedIOException { - return UncheckedIO.get(super::readLine); + return Uncheck.get(super::readLine); } /** @@ -128,7 +128,7 @@ public class UncheckedBufferedReader extends BufferedReader { */ @Override public boolean ready() throws UncheckedIOException { - return UncheckedIO.get(super::ready); + return Uncheck.get(super::ready); } /** @@ -136,7 +136,7 @@ public class UncheckedBufferedReader extends BufferedReader { */ @Override public void reset() throws UncheckedIOException { - UncheckedIO.run(super::reset); + Uncheck.run(super::reset); } /** @@ -144,7 +144,7 @@ public class UncheckedBufferedReader extends BufferedReader { */ @Override public long skip(final long n) throws UncheckedIOException { - return UncheckedIO.apply(super::skip, n); + return Uncheck.apply(super::skip, n); } } diff --git a/src/main/java/org/apache/commons/io/input/UncheckedFilterInputStream.java b/src/main/java/org/apache/commons/io/input/UncheckedFilterInputStream.java index 9571d723..60d4bb46 100644 --- a/src/main/java/org/apache/commons/io/input/UncheckedFilterInputStream.java +++ b/src/main/java/org/apache/commons/io/input/UncheckedFilterInputStream.java @@ -24,7 +24,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; -import org.apache.commons.io.UncheckedIO; +import org.apache.commons.io.Uncheck; /** * A {@link BufferedReader} that throws {@link UncheckedIOException} instead of {@link IOException}. @@ -62,7 +62,7 @@ public class UncheckedFilterInputStream extends FilterInputStream { */ @Override public int available() throws UncheckedIOException { - return UncheckedIO.get(super::available); + return Uncheck.get(super::available); } /** @@ -70,7 +70,7 @@ public class UncheckedFilterInputStream extends FilterInputStream { */ @Override public void close() throws UncheckedIOException { - UncheckedIO.run(super::close); + Uncheck.run(super::close); } /** @@ -78,7 +78,7 @@ public class UncheckedFilterInputStream extends FilterInputStream { */ @Override public int read() throws UncheckedIOException { - return UncheckedIO.get(super::read); + return Uncheck.get(super::read); } /** @@ -86,7 +86,7 @@ public class UncheckedFilterInputStream extends FilterInputStream { */ @Override public int read(final byte[] b) throws UncheckedIOException { - return UncheckedIO.apply(super::read, b); + return Uncheck.apply(super::read, b); } /** @@ -94,7 +94,7 @@ public class UncheckedFilterInputStream extends FilterInputStream { */ @Override public int read(final byte[] b, final int off, final int len) throws UncheckedIOException { - return UncheckedIO.apply(super::read, b, off, len); + return Uncheck.apply(super::read, b, off, len); } /** @@ -102,7 +102,7 @@ public class UncheckedFilterInputStream extends FilterInputStream { */ @Override public synchronized void reset() throws UncheckedIOException { - UncheckedIO.run(super::reset); + Uncheck.run(super::reset); } /** @@ -110,7 +110,7 @@ public class UncheckedFilterInputStream extends FilterInputStream { */ @Override public long skip(final long n) throws UncheckedIOException { - return UncheckedIO.apply(super::skip, n); + return Uncheck.apply(super::skip, n); } } diff --git a/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java b/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java index f0a68a12..a91088bf 100644 --- a/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java +++ b/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java @@ -23,7 +23,7 @@ import java.io.Reader; import java.io.UncheckedIOException; import java.nio.CharBuffer; -import org.apache.commons.io.UncheckedIO; +import org.apache.commons.io.Uncheck; /** * A {@link FilterReader} that throws {@link UncheckedIOException} instead of {@link IOException}. @@ -61,7 +61,7 @@ public class UncheckedFilterReader extends FilterReader { */ @Override public void close() throws UncheckedIOException { - UncheckedIO.run(super::close); + Uncheck.run(super::close); } /** @@ -69,7 +69,7 @@ public class UncheckedFilterReader extends FilterReader { */ @Override public void mark(final int readAheadLimit) throws UncheckedIOException { - UncheckedIO.accept(super::mark, readAheadLimit); + Uncheck.accept(super::mark, readAheadLimit); } /** @@ -77,7 +77,7 @@ public class UncheckedFilterReader extends FilterReader { */ @Override public int read() throws UncheckedIOException { - return UncheckedIO.get(super::read); + return Uncheck.get(super::read); } /** @@ -85,7 +85,7 @@ public class UncheckedFilterReader extends FilterReader { */ @Override public int read(final char[] cbuf) throws UncheckedIOException { - return UncheckedIO.apply(super::read, cbuf); + return Uncheck.apply(super::read, cbuf); } /** @@ -93,7 +93,7 @@ public class UncheckedFilterReader extends FilterReader { */ @Override public int read(final char[] cbuf, final int off, final int len) throws UncheckedIOException { - return UncheckedIO.apply(super::read, cbuf, off, len); + return Uncheck.apply(super::read, cbuf, off, len); } /** @@ -101,7 +101,7 @@ public class UncheckedFilterReader extends FilterReader { */ @Override public int read(final CharBuffer target) throws UncheckedIOException { - return UncheckedIO.apply(super::read, target); + return Uncheck.apply(super::read, target); } /** @@ -109,7 +109,7 @@ public class UncheckedFilterReader extends FilterReader { */ @Override public boolean ready() throws UncheckedIOException { - return UncheckedIO.get(super::ready); + return Uncheck.get(super::ready); } /** @@ -117,7 +117,7 @@ public class UncheckedFilterReader extends FilterReader { */ @Override public void reset() throws UncheckedIOException { - UncheckedIO.run(super::reset); + Uncheck.run(super::reset); } /** @@ -125,7 +125,7 @@ public class UncheckedFilterReader extends FilterReader { */ @Override public long skip(final long n) throws UncheckedIOException { - return UncheckedIO.apply(super::skip, n); + return Uncheck.apply(super::skip, n); } } diff --git a/src/main/java/org/apache/commons/io/output/UncheckedAppendableImpl.java b/src/main/java/org/apache/commons/io/output/UncheckedAppendableImpl.java index 48aa3e00..53afcc92 100644 --- a/src/main/java/org/apache/commons/io/output/UncheckedAppendableImpl.java +++ b/src/main/java/org/apache/commons/io/output/UncheckedAppendableImpl.java @@ -21,7 +21,7 @@ import java.io.IOException; import java.io.UncheckedIOException; import java.util.Objects; -import org.apache.commons.io.UncheckedIO; +import org.apache.commons.io.Uncheck; /** * An {@link Appendable} implementation that throws {@link UncheckedIOException} instead of {@link IOException}. @@ -41,19 +41,19 @@ class UncheckedAppendableImpl implements UncheckedAppendable { @Override public UncheckedAppendable append(final char c) { - UncheckedIO.apply(appendable::append, c); + Uncheck.apply(appendable::append, c); return this; } @Override public UncheckedAppendable append(final CharSequence csq) { - UncheckedIO.apply(appendable::append, csq); + Uncheck.apply(appendable::append, csq); return this; } @Override public UncheckedAppendable append(final CharSequence csq, final int start, final int end) { - UncheckedIO.apply(appendable::append, csq, start, end); + Uncheck.apply(appendable::append, csq, start, end); return this; } diff --git a/src/main/java/org/apache/commons/io/output/UncheckedFilterOutputStream.java b/src/main/java/org/apache/commons/io/output/UncheckedFilterOutputStream.java index 31c92756..e73ac541 100644 --- a/src/main/java/org/apache/commons/io/output/UncheckedFilterOutputStream.java +++ b/src/main/java/org/apache/commons/io/output/UncheckedFilterOutputStream.java @@ -22,7 +22,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.UncheckedIOException; -import org.apache.commons.io.UncheckedIO; +import org.apache.commons.io.Uncheck; /** * A {@link FilterOutputStream} that throws {@link UncheckedIOException} instead of {@link UncheckedIOException}. @@ -59,7 +59,7 @@ public class UncheckedFilterOutputStream extends FilterOutputStream { */ @Override public void close() throws UncheckedIOException { - UncheckedIO.run(super::close); + Uncheck.run(super::close); } /** @@ -67,7 +67,7 @@ public class UncheckedFilterOutputStream extends FilterOutputStream { */ @Override public void flush() throws UncheckedIOException { - UncheckedIO.run(super::flush); + Uncheck.run(super::flush); } /** @@ -75,7 +75,7 @@ public class UncheckedFilterOutputStream extends FilterOutputStream { */ @Override public void write(final byte[] b) throws UncheckedIOException { - UncheckedIO.accept(super::write, b); + Uncheck.accept(super::write, b); } /** @@ -83,7 +83,7 @@ public class UncheckedFilterOutputStream extends FilterOutputStream { */ @Override public void write(final byte[] b, final int off, final int len) throws UncheckedIOException { - UncheckedIO.accept(super::write, b, off, len); + Uncheck.accept(super::write, b, off, len); } /** @@ -91,7 +91,7 @@ public class UncheckedFilterOutputStream extends FilterOutputStream { */ @Override public void write(final int b) throws UncheckedIOException { - UncheckedIO.accept(super::write, b); + Uncheck.accept(super::write, b); } } diff --git a/src/main/java/org/apache/commons/io/output/UncheckedFilterWriter.java b/src/main/java/org/apache/commons/io/output/UncheckedFilterWriter.java index 5be5c1f3..c6f9599c 100644 --- a/src/main/java/org/apache/commons/io/output/UncheckedFilterWriter.java +++ b/src/main/java/org/apache/commons/io/output/UncheckedFilterWriter.java @@ -22,6 +22,8 @@ import java.io.IOException; import java.io.UncheckedIOException; import java.io.Writer; +import org.apache.commons.io.Uncheck; + /** * A {@link FilterWriter} that throws {@link UncheckedIOException} instead of {@link IOException}. * @@ -58,11 +60,7 @@ public class UncheckedFilterWriter extends FilterWriter { */ @Override public Writer append(final char c) throws UncheckedIOException { - try { - return super.append(c); - } catch (final IOException e) { - throw uncheck(e); - } + return Uncheck.apply(super::append, c); } /** @@ -70,11 +68,7 @@ public class UncheckedFilterWriter extends FilterWriter { */ @Override public Writer append(final CharSequence csq) throws UncheckedIOException { - try { - return super.append(csq); - } catch (final IOException e) { - throw uncheck(e); - } + return Uncheck.apply(super::append, csq); } /** @@ -82,11 +76,7 @@ public class UncheckedFilterWriter extends FilterWriter { */ @Override public Writer append(final CharSequence csq, final int start, final int end) throws UncheckedIOException { - try { - return super.append(csq, start, end); - } catch (final IOException e) { - throw uncheck(e); - } + return Uncheck.apply(super::append, csq, start, end); } /** @@ -94,11 +84,7 @@ public class UncheckedFilterWriter extends FilterWriter { */ @Override public void close() throws UncheckedIOException { - try { - super.close(); - } catch (final IOException e) { - throw uncheck(e); - } + Uncheck.run(super::close); } /** @@ -106,15 +92,7 @@ public class UncheckedFilterWriter extends FilterWriter { */ @Override public void flush() throws UncheckedIOException { - try { - super.flush(); - } catch (final IOException e) { - throw uncheck(e); - } - } - - private UncheckedIOException uncheck(final IOException e) { - return new UncheckedIOException(e); + Uncheck.run(super::flush); } /** @@ -122,11 +100,7 @@ public class UncheckedFilterWriter extends FilterWriter { */ @Override public void write(final char[] cbuf) throws UncheckedIOException { - try { - super.write(cbuf); - } catch (final IOException e) { - throw uncheck(e); - } + Uncheck.accept(super::write, cbuf); } /** @@ -134,11 +108,7 @@ public class UncheckedFilterWriter extends FilterWriter { */ @Override public void write(final char[] cbuf, final int off, final int len) throws UncheckedIOException { - try { - super.write(cbuf, off, len); - } catch (final IOException e) { - throw uncheck(e); - } + Uncheck.accept(super::write, cbuf, off, len); } /** @@ -146,11 +116,7 @@ public class UncheckedFilterWriter extends FilterWriter { */ @Override public void write(final int c) throws UncheckedIOException { - try { - super.write(c); - } catch (final IOException e) { - throw uncheck(e); - } + Uncheck.accept(super::write, c); } /** @@ -158,11 +124,7 @@ public class UncheckedFilterWriter extends FilterWriter { */ @Override public void write(final String str) throws UncheckedIOException { - try { - super.write(str); - } catch (final IOException e) { - throw uncheck(e); - } + Uncheck.accept(super::write, str); } /** @@ -170,11 +132,7 @@ public class UncheckedFilterWriter extends FilterWriter { */ @Override public void write(final String str, final int off, final int len) throws UncheckedIOException { - try { - super.write(str, off, len); - } catch (final IOException e) { - throw uncheck(e); - } + Uncheck.accept(super::write, str, off, len); } } diff --git a/src/test/java/org/apache/commons/io/UncheckedIOExceptionsTest.java b/src/test/java/org/apache/commons/io/UncheckedIOExceptionsTest.java index 160d38ea..4e0f83f9 100644 --- a/src/test/java/org/apache/commons/io/UncheckedIOExceptionsTest.java +++ b/src/test/java/org/apache/commons/io/UncheckedIOExceptionsTest.java @@ -25,7 +25,7 @@ import java.io.UncheckedIOException; import org.junit.jupiter.api.Test; /** - * Tests {@link UncheckedIO}. + * Tests {@link Uncheck}. */ public class UncheckedIOExceptionsTest { diff --git a/src/test/java/org/apache/commons/io/UncheckedIOTest.java b/src/test/java/org/apache/commons/io/UncheckedIOTest.java index 6628d83d..5830862d 100644 --- a/src/test/java/org/apache/commons/io/UncheckedIOTest.java +++ b/src/test/java/org/apache/commons/io/UncheckedIOTest.java @@ -30,7 +30,7 @@ import org.apache.commons.io.function.IOTriFunction; import org.junit.jupiter.api.Test; /** - * Tests {@link UncheckedIO}. + * Tests {@link Uncheck}. */ public class UncheckedIOTest { @@ -41,62 +41,62 @@ public class UncheckedIOTest { } /** - * Tests {@link UncheckedIO#accept(IOConsumer, Object)}. + * Tests {@link Uncheck#accept(IOConsumer, Object)}. */ @Test public void testAccept() { final ByteArrayInputStream stream = newInputStream(); - UncheckedIO.accept(n -> stream.skip(n), 1); - assertEquals('b', UncheckedIO.get(stream::read).intValue()); + Uncheck.accept(n -> stream.skip(n), 1); + assertEquals('b', Uncheck.get(stream::read).intValue()); } /** - * Tests {@link UncheckedIO#apply(IOFunction, Object)}. + * Tests {@link Uncheck#apply(IOFunction, Object)}. */ @Test public void testApply1() { final ByteArrayInputStream stream = newInputStream(); - assertEquals(1, UncheckedIO.apply(n -> stream.skip(n), 1).intValue()); - assertEquals('b', UncheckedIO.get(stream::read).intValue()); + assertEquals(1, Uncheck.apply(n -> stream.skip(n), 1).intValue()); + assertEquals('b', Uncheck.get(stream::read).intValue()); } /** - * Tests {@link UncheckedIO#apply(IOBiFunction, Object, Object)}. + * Tests {@link Uncheck#apply(IOBiFunction, Object, Object)}. */ @Test public void testApply2() { final ByteArrayInputStream stream = newInputStream(); final byte[] buf = new byte[BYTES.length]; - assertEquals(1, UncheckedIO.apply((o, l) -> stream.read(buf, o, l), 0, 1).intValue()); + assertEquals(1, Uncheck.apply((o, l) -> stream.read(buf, o, l), 0, 1).intValue()); assertEquals('a', buf[0]); } /** - * Tests {@link UncheckedIO#apply(IOTriFunction, Object, Object, Object)}. + * Tests {@link Uncheck#apply(IOTriFunction, Object, Object, Object)}. */ @Test public void testApply3() { final ByteArrayInputStream stream = newInputStream(); final byte[] buf = new byte[BYTES.length]; - assertEquals(1, UncheckedIO.apply((b, o, l) -> stream.read(b, o, l), buf, 0, 1).intValue()); + assertEquals(1, Uncheck.apply((b, o, l) -> stream.read(b, o, l), buf, 0, 1).intValue()); assertEquals('a', buf[0]); } /** - * Tests {@link UncheckedIO#get(IOSupplier)}. + * Tests {@link Uncheck#get(IOSupplier)}. */ @Test public void testGet() { - assertEquals('a', UncheckedIO.get(() -> newInputStream().read()).intValue()); + assertEquals('a', Uncheck.get(() -> newInputStream().read()).intValue()); } /** - * Tests {@link UncheckedIO#run(IORunnable)}. + * Tests {@link Uncheck#run(IORunnable)}. */ @Test public void testRun() { final ByteArrayInputStream stream = newInputStream(); - UncheckedIO.run(() -> stream.skip(1)); - assertEquals('b', UncheckedIO.get(stream::read).intValue()); + Uncheck.run(() -> stream.skip(1)); + assertEquals('b', Uncheck.get(stream::read).intValue()); } } diff --git a/src/test/java/org/apache/commons/io/file/FilesUncheckTest.java b/src/test/java/org/apache/commons/io/file/FilesUncheckTest.java index fd858203..6bcb1041 100644 --- a/src/test/java/org/apache/commons/io/file/FilesUncheckTest.java +++ b/src/test/java/org/apache/commons/io/file/FilesUncheckTest.java @@ -53,7 +53,7 @@ import java.util.HashSet; import java.util.Set; import org.apache.commons.io.IOUtils; -import org.apache.commons.io.UncheckedIO; +import org.apache.commons.io.Uncheck; import org.apache.commons.io.input.NullInputStream; import org.apache.commons.io.output.NullOutputStream; import org.apache.commons.lang3.ArrayUtils; @@ -226,7 +226,7 @@ public class FilesUncheckTest { @Test public void testNewBufferedReaderPath() { - UncheckedIO.run(() -> { + Uncheck.run(() -> { try (BufferedReader reader = FilesUncheck.newBufferedReader(FILE_PATH_EMPTY)) { IOUtils.consume(reader); } @@ -235,7 +235,7 @@ public class FilesUncheckTest { @Test public void testNewBufferedReaderPathCharset() { - UncheckedIO.run(() -> { + Uncheck.run(() -> { try (BufferedReader reader = FilesUncheck.newBufferedReader(FILE_PATH_EMPTY, StandardCharsets.UTF_8)) { IOUtils.consume(reader); } @@ -245,7 +245,7 @@ public class FilesUncheckTest { @Test public void testNewBufferedWriterPathCharsetOpenOptionArray() { final Path tempPath = FilesUncheck.createTempFile(PREFIX, SUFFIX); - UncheckedIO.run(() -> { + Uncheck.run(() -> { try (BufferedWriter writer = FilesUncheck.newBufferedWriter(tempPath, StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING)) { writer.append("test"); } @@ -256,7 +256,7 @@ public class FilesUncheckTest { @Test public void testNewBufferedWriterPathOpenOptionArray() { final Path tempPath = FilesUncheck.createTempFile(PREFIX, SUFFIX); - UncheckedIO.run(() -> { + Uncheck.run(() -> { try (BufferedWriter writer = FilesUncheck.newBufferedWriter(tempPath, StandardOpenOption.TRUNCATE_EXISTING)) { writer.append("test"); } @@ -266,7 +266,7 @@ public class FilesUncheckTest { @Test public void testNewByteChannelPathOpenOptionArray() { - assertEquals(0, UncheckedIO.get(() -> { + assertEquals(0, Uncheck.get(() -> { try (SeekableByteChannel c = FilesUncheck.newByteChannel(FILE_PATH_EMPTY, StandardOpenOption.READ)) { return c.size(); } @@ -277,7 +277,7 @@ public class FilesUncheckTest { public void testNewByteChannelPathSetOfQextendsOpenOptionFileAttributeOfQArray() { final Set<OpenOption> options = new HashSet<>(); options.add(StandardOpenOption.READ); - assertEquals(0, UncheckedIO.get(() -> { + assertEquals(0, Uncheck.get(() -> { try (SeekableByteChannel c = FilesUncheck.newByteChannel(FILE_PATH_EMPTY, options, EMPTY_FILE_ATTRIBUTES_ARRAY)) { return c.size(); } @@ -286,7 +286,7 @@ public class FilesUncheckTest { @Test public void testNewDirectoryStreamPath() { - UncheckedIO.run(() -> { + Uncheck.run(() -> { try (final DirectoryStream<Path> directoryStream = FilesUncheck.newDirectoryStream(TARGET_PATH)) { directoryStream.forEach(e -> assertEquals(TARGET_PATH, e.getParent())); } @@ -295,7 +295,7 @@ public class FilesUncheckTest { @Test public void testNewDirectoryStreamPathString() { - UncheckedIO.run(() -> { + Uncheck.run(() -> { try (final DirectoryStream<Path> directoryStream = FilesUncheck.newDirectoryStream(TARGET_PATH, "*.xml")) { directoryStream.forEach(e -> assertEquals(TARGET_PATH, e.getParent())); } @@ -304,7 +304,7 @@ public class FilesUncheckTest { @Test public void testNewDirectoryStreamPathFilterOfQsuperPath() { - UncheckedIO.run(() -> { + Uncheck.run(() -> { try (final DirectoryStream<Path> directoryStream = FilesUncheck.newDirectoryStream(TARGET_PATH, e -> true)) { directoryStream.forEach(e -> assertEquals(TARGET_PATH, e.getParent())); } @@ -313,7 +313,7 @@ public class FilesUncheckTest { @Test public void testNewInputStream() { - assertEquals(0, UncheckedIO.get(() -> { + assertEquals(0, Uncheck.get(() -> { try (InputStream in = FilesUncheck.newInputStream(FILE_PATH_EMPTY, StandardOpenOption.READ)) { return in.available(); } @@ -323,7 +323,7 @@ public class FilesUncheckTest { @Test public void testNewOutputStream() { final Path tempPath = FilesUncheck.createTempFile(PREFIX, SUFFIX); - UncheckedIO.run(() -> { + Uncheck.run(() -> { try (OutputStream stream = FilesUncheck.newOutputStream(tempPath, StandardOpenOption.TRUNCATE_EXISTING)) { stream.write("test".getBytes()); }