Skip to content

Commit 72d53cf

Browse files
committed
No need to allocate empty byte arrays over and over.
1 parent 7045200 commit 72d53cf

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/main/java/org/apache/commons/io/IOUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public class IOUtils {
105105
// Writer. Each method should take at least one of these as a parameter,
106106
// or return one of them.
107107

108+
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
109+
108110
/**
109111
* The default buffer size ({@value}) to use in copy methods.
110112
*/
@@ -2233,7 +2235,7 @@ public static byte[] toByteArray(final InputStream input, final int size) throws
22332235
}
22342236

22352237
if (size == 0) {
2236-
return new byte[0];
2238+
return EMPTY_BYTE_ARRAY;
22372239
}
22382240

22392241
final byte[] data = new byte[size];

0 commit comments

Comments
 (0)