Skip to content

Commit 78ad22e

Browse files
committed
Move Java8 loop for readAllBytes into its own method
1 parent 826831e commit 78ad22e

File tree

1 file changed

+11
-7
lines changed
  • utils/src/main/java/datadog/instrument/utils

1 file changed

+11
-7
lines changed

utils/src/main/java/datadog/instrument/utils/JVM.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,18 @@ public static byte[] readAllBytes(InputStream is) throws IOException {
7272
if (JVM.atLeastJava(9)) {
7373
return is.readAllBytes();
7474
} else {
75-
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
76-
int bytesRead;
77-
byte[] buf = new byte[BUFFER_SIZE];
78-
while ((bytesRead = is.read(buf, 0, BUFFER_SIZE)) != -1) {
79-
os.write(buf, 0, bytesRead);
80-
}
81-
return os.toByteArray();
75+
return readAllBytesLoop(is);
76+
}
77+
}
78+
79+
private static byte[] readAllBytesLoop(InputStream is) throws IOException {
80+
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
81+
int bytesRead;
82+
byte[] buf = new byte[BUFFER_SIZE];
83+
while ((bytesRead = is.read(buf, 0, BUFFER_SIZE)) != -1) {
84+
os.write(buf, 0, bytesRead);
8285
}
86+
return os.toByteArray();
8387
}
8488
}
8589
}

0 commit comments

Comments
 (0)