Use releaseOnClose to release the ByteBuf when the output stream is closed (#14263)
This commit is contained in:
parent
48df310ce7
commit
b831c26e83
|
|
@ -18,11 +18,8 @@ package org.apache.dubbo.remoting.http12.h1;
|
|||
|
||||
import org.apache.dubbo.remoting.http12.HttpOutputMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import io.netty.buffer.ByteBufOutputStream;
|
||||
|
||||
public class Http1OutputMessage implements HttpOutputMessage {
|
||||
|
||||
private final OutputStream outputStream;
|
||||
|
|
@ -35,12 +32,4 @@ public class Http1OutputMessage implements HttpOutputMessage {
|
|||
public OutputStream getBody() {
|
||||
return outputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (outputStream instanceof ByteBufOutputStream) {
|
||||
((ByteBufOutputStream) outputStream).buffer().release();
|
||||
}
|
||||
outputStream.close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,8 @@
|
|||
*/
|
||||
package org.apache.dubbo.remoting.http12.h2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import io.netty.buffer.ByteBufOutputStream;
|
||||
|
||||
public class Http2OutputMessageFrame implements Http2OutputMessage {
|
||||
|
||||
private final OutputStream body;
|
||||
|
|
@ -45,14 +42,6 @@ public class Http2OutputMessageFrame implements Http2OutputMessage {
|
|||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (body instanceof ByteBufOutputStream) {
|
||||
((ByteBufOutputStream) body).buffer().release();
|
||||
}
|
||||
body.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEndStream() {
|
||||
return endStream;
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class NettyHttp1Channel implements HttpChannel {
|
|||
|
||||
@Override
|
||||
public HttpOutputMessage newOutputMessage() {
|
||||
return new Http1OutputMessage(new ByteBufOutputStream(channel.alloc().buffer()));
|
||||
return new Http1OutputMessage(new ByteBufOutputStream(channel.alloc().buffer(), true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class NettyH2StreamChannel implements H2StreamChannel {
|
|||
@Override
|
||||
public Http2OutputMessage newOutputMessage(boolean endStream) {
|
||||
ByteBuf buffer = http2StreamChannel.alloc().buffer();
|
||||
ByteBufOutputStream outputStream = new ByteBufOutputStream(buffer);
|
||||
ByteBufOutputStream outputStream = new ByteBufOutputStream(buffer, true);
|
||||
return new Http2OutputMessageFrame(outputStream, endStream);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue