Browse Source

rename: IOUtils#close -> closeAny

Mariusz Czarnowski 4 năm trước cách đây
mục cha
commit
5a295fbb02

+ 6 - 6
assira.core/src/main/java/net/ranides/assira/io/BufferAdapter.java

@@ -143,7 +143,7 @@ public final class BufferAdapter {
         @Override
         public void close() throws IOException {
             try {
-                IOUtils.close(buffer, IOUtils::rethrow);
+                IOUtils.closeAny(buffer, IOUtils::rethrow);
             } finally {
                 buffer = EMPTY;
             }
@@ -232,7 +232,7 @@ public final class BufferAdapter {
         @Override
         public void close() throws IOException {
             try {
-                IOUtils.close(buffer, IOUtils::rethrow);
+                IOUtils.closeAny(buffer, IOUtils::rethrow);
             } finally {
                 buffer = EMPTY;
             }
@@ -286,7 +286,7 @@ public final class BufferAdapter {
         @Override
         public void close() throws IOException {
             try {
-                IOUtils.close(buffer, IOUtils::rethrow);
+                IOUtils.closeAny(buffer, IOUtils::rethrow);
             } finally {
                 buffer = EMPTY;
             }
@@ -330,7 +330,7 @@ public final class BufferAdapter {
         @Override
         public void close() throws IOException {
             try {
-                IOUtils.close(buffer, IOUtils::rethrow);
+                IOUtils.closeAny(buffer, IOUtils::rethrow);
             } finally {
                 buffer = EMPTY;
             }
@@ -392,7 +392,7 @@ public final class BufferAdapter {
         public void close() throws IOException {
             try {
                 flush();
-                IOUtils.close(buffer, IOUtils::rethrow);
+                IOUtils.closeAny(buffer, IOUtils::rethrow);
             } finally {
                 buffer = EMPTY;
             }
@@ -480,7 +480,7 @@ public final class BufferAdapter {
         public void close() throws IOException {
             try {
                 flush();
-                IOUtils.close(buffer, IOUtils::rethrow);
+                IOUtils.closeAny(buffer, IOUtils::rethrow);
             } finally {
                 buffer = EMPTY;
             }

+ 4 - 4
assira.core/src/main/java/net/ranides/assira/io/DataAdapter.java

@@ -83,7 +83,7 @@ public final class DataAdapter {
 
         @Override
         public void close() throws IOException {
-            IOUtils.close(odata, IOUtils::rethrow);
+            IOUtils.closeAny(odata, IOUtils::rethrow);
         }
 
     }
@@ -145,7 +145,7 @@ public final class DataAdapter {
 
         @Override
         public void close() throws IOException {
-            IOUtils.close(idata, IOUtils::rethrow);
+            IOUtils.closeAny(idata, IOUtils::rethrow);
         }
 
     }
@@ -166,7 +166,7 @@ public final class DataAdapter {
         @Override
         public void close() throws IOException {
             flush();
-            IOUtils.close(odata, IOUtils::rethrow);
+            IOUtils.closeAny(odata, IOUtils::rethrow);
         }
         
         @Override
@@ -230,7 +230,7 @@ public final class DataAdapter {
         
         @Override
         public void close() throws IOException {
-            IOUtils.close(idata, IOUtils::rethrow);
+            IOUtils.closeAny(idata, IOUtils::rethrow);
         }
         
         @Override

+ 2 - 2
assira.core/src/main/java/net/ranides/assira/io/IOStreams.java

@@ -178,8 +178,8 @@ public final class IOStreams {
             } catch(Exception cause) {
                 handler.accept(cause);
             } finally {
-                IOUtils.close(input, handler);
-                IOUtils.close(output, handler);
+                IOUtils.closeAny(input, handler);
+                IOUtils.closeAny(output, handler);
             }
         });
         thread.start();

+ 3 - 3
assira.core/src/main/java/net/ranides/assira/io/IOUtils.java

@@ -58,7 +58,7 @@ public final class IOUtils {
         }
     }
     
-    public static boolean close(Object object) throws Exception {
+    public static boolean closeAny(Object object) throws Exception {
         if(object instanceof Closeable) {
             ((Closeable)object).close();
             return true;
@@ -70,9 +70,9 @@ public final class IOUtils {
         return false;
     }
     
-    public static boolean close(Object object, Consumer<Exception> handler) {
+    public static boolean closeAny(Object object, Consumer<Exception> handler) {
         try {
-            return close(object);
+            return closeAny(object);
         } catch(Exception cause) {
             if(null != handler) {
                 handler.accept(cause);

+ 14 - 16
assira.core/src/test/java/net/ranides/assira/io/IOUtilsTest.java

@@ -44,17 +44,17 @@ public class IOUtilsTest {
     public void testClose_Object() throws Exception {
         List<Integer> out = new ArrayList<>();
         
-        assertFalse( IOUtils.close((Object)null) );
-        assertTrue( IOUtils.close((Object) (Closeable)() -> { out.add(7); }) );
-        assertTrue( IOUtils.close((Object) (AutoCloseable)() -> { out.add(8); }) );
+        assertFalse( IOUtils.closeAny(null) );
+        assertTrue( IOUtils.closeAny((Closeable)() -> { out.add(7); }) );
+        assertTrue( IOUtils.closeAny((AutoCloseable)() -> { out.add(8); }) );
         
         assertEquals(Arrays.asList(7,8), out);
                 
         assertThrows(IOException.class, ()->{
-            IOUtils.close((Object)new CFile("IO"));
+            IOUtils.closeAny(new CFile("IO"));
         });
         assertThrows(SQLException.class, ()->{
-            IOUtils.close((Object)new SFile());
+            IOUtils.closeAny(new SFile());
         });
     }
     
@@ -62,8 +62,8 @@ public class IOUtilsTest {
     public void testClose_Closeable() throws IOException {
         List<Integer> out = new ArrayList<>();
         
-        assertFalse( IOUtils.close((Closeable)null) );
-        assertTrue( IOUtils.close((Closeable)() -> { out.add(7); }) );
+        assertFalse( IOUtils.close(null) );
+        assertTrue( IOUtils.close(() -> { out.add(7); }) );
         
         assertEquals(Arrays.asList(7), out);
                 
@@ -76,27 +76,25 @@ public class IOUtilsTest {
     public void testClose_Consumer() {
         List<Throwable> errors = new ArrayList<>();
         
-        EventListener<Events.Failure> listener = (e) -> {
-            errors.add(e.cause());
-        };
+        EventListener<Events.Failure> listener = (e) -> errors.add(e.cause());
         
         // listener
-        IOUtils.close(new CFile("IO"), listener.consumer(e -> Events.failure(e)));
+        IOUtils.close(new CFile("IO"), listener.consumer(Events::failure));
         
         // listener
-        IOUtils.close(new SFile(), listener.consumer(Events::failure));
+        IOUtils.closeAny(new SFile(), listener.consumer(Events::failure));
         
         // consumer
-        IOUtils.close(new CFile("NC"), (Exception e) -> errors.add(e));
+        IOUtils.closeAny(new CFile("NC"), e -> errors.add(e));
         
         // real NOP - ignore exception silently
-        IOUtils.close(new SFile(), e -> {});
+        IOUtils.closeAny(new SFile(), e -> {});
         
         // "safe" NOP - write exception to log (with WARN level)
-        IOUtils.close(new SFile(), null);
+        IOUtils.closeAny(new SFile(), null);
                 
         // explicit logger
-        IOUtils.close(new SFile(), e -> LOGGER.error("close!", e));
+        IOUtils.closeAny(new SFile(), e -> LOGGER.error("close!", e));
         
         List<String> expected = Arrays.asList(
                 "java.io.IOException: IO",