From 711256e6cf41aa29a2d1f5821d1bc69344b766e8 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 1 Aug 2022 09:09:50 +0300 Subject: [PATCH] Use InputStream.transferTo instead of manually using a byte array --- .../common/providers/serialisers/FileBodyHandler.java | 6 +----- .../serialisers/InputStreamMessageBodyHandler.java | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/providers/serialisers/FileBodyHandler.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/providers/serialisers/FileBodyHandler.java index d2484bf146444..de2b80663a2f7 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/providers/serialisers/FileBodyHandler.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/providers/serialisers/FileBodyHandler.java @@ -36,11 +36,7 @@ public File readFrom(Class type, Type genericType, } try (OutputStream output = new BufferedOutputStream(new FileOutputStream(downloadedFile))) { - int read; - final byte[] buf = new byte[2048]; - while ((read = entityStream.read(buf)) != -1) { - output.write(buf, 0, read); - } + entityStream.transferTo(output); } return downloadedFile; diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/providers/serialisers/InputStreamMessageBodyHandler.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/providers/serialisers/InputStreamMessageBodyHandler.java index b5eb4010aadc2..383464b513a18 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/providers/serialisers/InputStreamMessageBodyHandler.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/providers/serialisers/InputStreamMessageBodyHandler.java @@ -34,11 +34,7 @@ public void writeTo(InputStream inputStream, Class type, Type genericType, An protected void writeTo(InputStream inputStream, OutputStream entityStream) throws IOException { try { - byte[] buffer = new byte[8192]; - int c; - while ((c = inputStream.read(buffer)) != -1) { - entityStream.write(buffer, 0, c); - } + inputStream.transferTo(entityStream); } finally { try { inputStream.close();