Skip to content

Commit

Permalink
Improved: Remove useless ‘UtilObject#getBytes’
Browse files Browse the repository at this point in the history
(OFBIZ-11140)


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1863444 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Jul 19, 2019
1 parent cc85af1 commit 1427c57
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 41 deletions.
Expand Up @@ -21,7 +21,6 @@
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;
Expand All @@ -41,21 +40,6 @@ private 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;
Expand Down
Expand Up @@ -156,31 +156,6 @@ public void testErrorInjector() throws Exception {
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;
Expand Down

0 comments on commit 1427c57

Please sign in to comment.