svn commit: r1863444 - in /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util: UtilObject.java test/UtilObjectTests.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1863444 - in /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util: UtilObject.java test/UtilObjectTests.java

mthl
Author: mthl
Date: Fri Jul 19 22:13:43 2019
New Revision: 1863444

URL: http://svn.apache.org/viewvc?rev=1863444&view=rev
Log:
Improved: Remove useless ‘UtilObject#getBytes’
(OFBIZ-11140)

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilObjectTests.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java?rev=1863444&r1=1863443&r2=1863444&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java Fri Jul 19 22:13:43 2019
@@ -21,7 +21,6 @@ package org.apache.ofbiz.base.util;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.ObjectOutputStream;
 import java.lang.reflect.Array;
 import java.util.Iterator;
@@ -41,21 +40,6 @@ public final class UtilObject {
 
     public static final String module = UtilObject.class.getName();
 
-    public static byte[] getBytes(InputStream is) {
-        byte[] buffer = new byte[4 * 1024];
-        byte[] data = null;
-        try (ByteArrayOutputStream bos = new ByteArrayOutputStream()){
-            int numBytesRead;
-            while ((numBytesRead = is.read(buffer)) != -1) {
-                bos.write(buffer, 0, numBytesRead);
-            }
-            data = bos.toByteArray();
-        } catch (IOException e) {
-            Debug.logError(e, module);
-        }
-        return data;
-    }
-
     /** Serialize an object to a byte array */
     public static byte[] getBytes(Object obj) {
         byte[] data = null;

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilObjectTests.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilObjectTests.java?rev=1863444&r1=1863443&r2=1863444&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilObjectTests.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilObjectTests.java Fri Jul 19 22:13:43 2019
@@ -156,31 +156,6 @@ public class UtilObjectTests extends Gen
         in.close();
     }
 
-    public void testGetBytes_Stream() {
-        boolean errorOn = Debug.isOn(Debug.ERROR);
-        try {
-            Debug.set(Debug.ERROR, false);
-            byte[] source = new byte[] { 0, 1, 2, 3, 4, 5, 6 };
-            byte[] result = UtilObject.getBytes(new ByteArrayInputStream(source));
-            assertNotNull("initial result", result);
-            assertEquals("initial equals", source, result);
-            assertNull("error after read", UtilObject.getBytes(new ErrorInjector(new ByteArrayInputStream(source), 3)));
-            byte[] closeResult = UtilObject.getBytes(new ErrorInjector(new ByteArrayInputStream(source), true));
-            assertNotNull("error on close", closeResult);
-            assertEquals("error on close equals", source, result);
-            Exception caught = null;
-            try {
-                UtilObject.getBytes(null);
-            } catch (NullPointerException e) {
-                caught = e;
-            } finally {
-                assertNotNull("null stream exception", caught);
-            }
-        } finally {
-            Debug.set(Debug.ERROR, errorOn);
-        }
-    }
-
     @SuppressWarnings("serial")
     public static class SerializationInjector implements Serializable {
         private boolean onRead;