Skip to content

Commit bbdf6c1

Browse files
committed
netty: fix outputstream with new buffer size
1 parent d681c37 commit bbdf6c1

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

modules/jooby-netty/src/main/java/io/jooby/internal/netty/NettyOutputStream.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,20 @@ public class NettyOutputStream extends OutputStream {
2323
private final ChannelHandlerContext context;
2424
private final ChannelFutureListener closeListener;
2525
private HttpResponse headers;
26-
private AtomicBoolean closed = new AtomicBoolean(false);
26+
private final AtomicBoolean closed = new AtomicBoolean(false);
2727

2828
public NettyOutputStream(
2929
NettyContext ctx, ChannelHandlerContext context, int bufferSize, HttpResponse headers) {
3030
this.ctx = ctx;
31-
this.buffer = context.alloc().buffer(0, bufferSize);
31+
this.buffer = context.alloc().heapBuffer(bufferSize, bufferSize);
3232
this.context = context;
3333
this.headers = headers;
3434
this.closeListener = ctx;
3535
}
3636

3737
@Override
3838
public void write(int b) {
39-
writeHeaders();
40-
41-
if (buffer.maxWritableBytes() < 1) {
42-
flush(null, null);
43-
}
44-
buffer.writeByte(b);
39+
write(new byte[] {(byte) b}, 0, 1);
4540
}
4641

4742
@Override

modules/jooby-netty/src/test/java/io/jooby/internal/netty/Issue3554.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void shouldCloseOutputStreamOnce() throws IOException {
2929
when(buffer.readableBytes()).thenReturn(0);
3030

3131
var bufferAllocator = mock(ByteBufAllocator.class);
32-
when(bufferAllocator.buffer(0, 1024)).thenReturn(buffer);
32+
when(bufferAllocator.heapBuffer(1024, 1024)).thenReturn(buffer);
3333

3434
var future = mock(ChannelFuture.class);
3535
var channelContext = mock(ChannelHandlerContext.class);

0 commit comments

Comments
 (0)