From 7512d5460893188d4974db09540cf75975d9216d Mon Sep 17 00:00:00 2001 From: Thibault Vallin Date: Tue, 21 Jul 2020 13:48:33 +0200 Subject: [PATCH 1/3] Fix #4522 - override write method in LoggingStream Signed-off-by: tvallin --- .../jersey/logging/LoggingInterceptor.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java b/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java index 5863c7bee5..627d1a215f 100644 --- a/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java +++ b/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2020 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -285,6 +285,24 @@ public void write(final int i) throws IOException { } out.write(i); } + + @Override + public void write(byte[] ba, int off, int len) throws IOException { + if ((off | len | ba.length - (len + off) | off + len) < 0) { + throw new IndexOutOfBoundsException(); + } else { + if ((baos.size() + len) <= maxEntitySize) { + for(int i = 0; i < len; ++i) { + baos.write(ba[off + i]); + out.write(ba[off + i]); + } + } else { + for(int i = 0; i < len; ++i) { + out.write(ba[off + i]); + } + } + } + } } } From 51f906798c55688949f91e0c2ea9a2903aaca5c3 Mon Sep 17 00:00:00 2001 From: Thibault Vallin Date: Tue, 21 Jul 2020 14:38:06 +0200 Subject: [PATCH 2/3] Checkstyle Signed-off-by: tvallin --- .../java/org/glassfish/jersey/logging/LoggingInterceptor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java b/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java index 627d1a215f..db2fc5281d 100644 --- a/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java +++ b/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java @@ -292,12 +292,12 @@ public void write(byte[] ba, int off, int len) throws IOException { throw new IndexOutOfBoundsException(); } else { if ((baos.size() + len) <= maxEntitySize) { - for(int i = 0; i < len; ++i) { + for (int i = 0; i < len; ++i) { baos.write(ba[off + i]); out.write(ba[off + i]); } } else { - for(int i = 0; i < len; ++i) { + for (int i = 0; i < len; ++i) { out.write(ba[off + i]); } } From f417569dcbcf022a55d43e2dc0a135cd91855530 Mon Sep 17 00:00:00 2001 From: Thibault Vallin Date: Fri, 24 Jul 2020 09:16:31 +0200 Subject: [PATCH 3/3] New method implementation Signed-off-by: tvallin --- .../jersey/logging/LoggingInterceptor.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java b/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java index db2fc5281d..c90d8b6470 100644 --- a/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java +++ b/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java @@ -290,18 +290,11 @@ public void write(final int i) throws IOException { public void write(byte[] ba, int off, int len) throws IOException { if ((off | len | ba.length - (len + off) | off + len) < 0) { throw new IndexOutOfBoundsException(); - } else { - if ((baos.size() + len) <= maxEntitySize) { - for (int i = 0; i < len; ++i) { - baos.write(ba[off + i]); - out.write(ba[off + i]); - } - } else { - for (int i = 0; i < len; ++i) { - out.write(ba[off + i]); - } - } } + if ((baos.size() + len) <= maxEntitySize) { + baos.write(ba, off, len); + } + out.write(ba, off, len); } }