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

tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git

commit 510891fa0050ef491bd2fc01cb29017eecdf7a6f
Author: Thomas Vandahl <[email protected]>
AuthorDate: Thu Mar 19 14:32:33 2026 +0100

    Simplify
---
 .../jcs4/admin/CountingOnlyOutputStream.java       |  2 +-
 .../apache/commons/jcs4/admin/JCSAdminBean.java    | 26 ++++++----------------
 2 files changed, 8 insertions(+), 20 deletions(-)

diff --git 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/admin/CountingOnlyOutputStream.java
 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/admin/CountingOnlyOutputStream.java
index d7f03737..b59b5074 100644
--- 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/admin/CountingOnlyOutputStream.java
+++ 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/admin/CountingOnlyOutputStream.java
@@ -26,7 +26,7 @@ import java.io.OutputStream;
  * Keeps track of the number of bytes written to it, but doesn't write them 
anywhere.
  */
 public class CountingOnlyOutputStream
-    extends OutputStream
+    extends OutputStream implements AutoCloseable
 {
     /** Number of bytes passed through */
     private int count; // TODO should this be long?
diff --git 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/admin/JCSAdminBean.java
 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/admin/JCSAdminBean.java
index 2d16b720..9d2690dc 100644
--- 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/admin/JCSAdminBean.java
+++ 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/admin/JCSAdminBean.java
@@ -262,32 +262,20 @@ public class JCSAdminBean implements JCSJMXBean
             }
             else
             {
-                final Object element = ice.value();
-
                 //CountingOnlyOutputStream: Keeps track of the number of bytes 
written to it, but doesn't write them anywhere.
-                final CountingOnlyOutputStream counter = new 
CountingOnlyOutputStream();
-                try (ObjectOutputStream out = new ObjectOutputStream(counter))
+                try (CountingOnlyOutputStream counter = new 
CountingOnlyOutputStream();
+                     ObjectOutputStream out = new ObjectOutputStream(counter))
                 {
-                    out.writeObject(element);
+                    out.writeObject(ice.value());
+                    out.flush();
+
+                    // 4 bytes lost for the serialization header
+                    size += counter.getCount() - 4;
                 }
                 catch (final IOException e)
                 {
                     throw new IllegalStateException("IOException while trying 
to measure the size of the cached element", e);
                 }
-                finally
-                {
-                       try
-                       {
-                                               counter.close();
-                                       }
-                       catch (final IOException e)
-                       {
-                               // ignore
-                                       }
-                }
-
-                // 4 bytes lost for the serialization header
-                size += counter.getCount() - 4;
             }
         }
 

Reply via email to