You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by ah...@apache.org on 2023/02/25 10:47:13 UTC

[causeway] branch spring6 updated: CAUSEWAY-3304: FileUtils: use 'throwing' variants (spring 6 only)

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch spring6
in repository https://gitbox.apache.org/repos/asf/causeway.git


The following commit(s) were added to refs/heads/spring6 by this push:
     new 6a684f8a2d CAUSEWAY-3304: FileUtils: use 'throwing' variants (spring 6 only)
6a684f8a2d is described below

commit 6a684f8a2d98ddf58b3fd046aa93e698bb6f3012
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sat Feb 25 11:47:07 2023 +0100

    CAUSEWAY-3304: FileUtils: use 'throwing' variants (spring 6 only)
---
 commons/src/main/java/org/apache/causeway/commons/io/FileUtils.java | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/commons/src/main/java/org/apache/causeway/commons/io/FileUtils.java b/commons/src/main/java/org/apache/causeway/commons/io/FileUtils.java
index 77675e0823..6f4829e8c6 100644
--- a/commons/src/main/java/org/apache/causeway/commons/io/FileUtils.java
+++ b/commons/src/main/java/org/apache/causeway/commons/io/FileUtils.java
@@ -36,6 +36,8 @@ import java.util.function.Function;
 import java.util.function.Predicate;
 
 import org.springframework.lang.Nullable;
+import org.springframework.util.function.ThrowingConsumer;
+import org.springframework.util.function.ThrowingFunction;
 
 import org.apache.causeway.commons.functional.Try;
 import org.apache.causeway.commons.internal.exceptions._Exceptions;
@@ -60,7 +62,7 @@ public class FileUtils {
      * @return either a successful or failed {@link Try} (non-null);
      *     if the file is null or not readable, the failure may hold a {@link NoSuchFileException} or other i/o related exceptions
      */
-    public Try<Void> tryRead(final @Nullable File file, final @NonNull Consumer<InputStream> inputStreamConsumer) {
+    public Try<Void> tryRead(final @Nullable File file, final @NonNull ThrowingConsumer<InputStream> inputStreamConsumer) {
         return Try.run(()->{
             try(val inputStream = new FileInputStream(existingFileElseFail(file))){
                 inputStreamConsumer.accept(inputStream);
@@ -76,7 +78,7 @@ public class FileUtils {
      *      where in the success case, the Try is holding the returned value from the given {@link Function inputStreamMapper};
      *      if the file is null or not readable, the failure may hold a {@link NoSuchFileException} or other i/o related exceptions
      */
-    public <T> Try<T> tryMap(final @Nullable File file, final @NonNull Function<InputStream, T> inputStreamMapper) {
+    public <T> Try<T> tryMap(final @Nullable File file, final @NonNull ThrowingFunction<InputStream, T> inputStreamMapper) {
         return Try.call(()->{
             try(val inputStream = new FileInputStream(existingFileElseFail(file))){
                 return inputStreamMapper.apply(inputStream);