diff --git a/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/internal/NettyInputStream.java b/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/internal/NettyInputStream.java index 8ff47d67ae..b369f125e9 100644 --- a/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/internal/NettyInputStream.java +++ b/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/internal/NettyInputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2019 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 @@ -68,9 +68,11 @@ public NettyInputStream(LinkedBlockingDeque isList) { this.isList = isList; } - @Override - public int read(byte[] b, int off, int len) throws IOException { + private interface ISReader { + int readFrom(InputStream take) throws IOException; + } + private int readInternal(ISReader isReader) throws IOException { if (end) { return -1; } @@ -83,10 +85,12 @@ public int read(byte[] b, int off, int len) throws IOException { return -1; } - int read = take.read(b, off, len); + int read = isReader.readFrom(take); if (take.available() > 0) { isList.addFirst(take); + } else { + take.close(); } return read; @@ -96,29 +100,13 @@ public int read(byte[] b, int off, int len) throws IOException { } @Override - public int read() throws IOException { - - if (end) { - return -1; - } - - try { - InputStream take = isList.take(); - - if (checkEndOfInput(take)) { - return -1; - } - - int read = take.read(); - - if (take.available() > 0) { - isList.addFirst(take); - } + public int read(byte[] b, int off, int len) throws IOException { + return readInternal(take -> take.read(b, off, len)); + } - return read; - } catch (InterruptedException e) { - throw new IOException("Interrupted.", e); - } + @Override + public int read() throws IOException { + return readInternal(InputStream::read); } @Override diff --git a/containers/netty-http/src/main/java/org/glassfish/jersey/netty/httpserver/JerseyHttp2ServerHandler.java b/containers/netty-http/src/main/java/org/glassfish/jersey/netty/httpserver/JerseyHttp2ServerHandler.java index ddb10891eb..23ce4bdf70 100644 --- a/containers/netty-http/src/main/java/org/glassfish/jersey/netty/httpserver/JerseyHttp2ServerHandler.java +++ b/containers/netty-http/src/main/java/org/glassfish/jersey/netty/httpserver/JerseyHttp2ServerHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2019 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 @@ -88,7 +88,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception * Process incoming data. */ private void onDataRead(ChannelHandlerContext ctx, Http2DataFrame data) throws Exception { - isList.add(new ByteBufInputStream(data.content())); + isList.add(new ByteBufInputStream(data.content(), true)); if (data.isEndStream()) { isList.add(NettyInputStream.END_OF_INPUT); } diff --git a/containers/netty-http/src/main/java/org/glassfish/jersey/netty/httpserver/JerseyServerHandler.java b/containers/netty-http/src/main/java/org/glassfish/jersey/netty/httpserver/JerseyServerHandler.java index 8e3067248a..0876e561f4 100644 --- a/containers/netty-http/src/main/java/org/glassfish/jersey/netty/httpserver/JerseyServerHandler.java +++ b/containers/netty-http/src/main/java/org/glassfish/jersey/netty/httpserver/JerseyServerHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2019 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 @@ -100,7 +100,7 @@ public void run() { ByteBuf content = httpContent.content(); if (content.isReadable()) { - isList.add(new ByteBufInputStream(content)); + isList.add(new ByteBufInputStream(content, true)); } if (msg instanceof LastHttpContent) {