Skip to content

Commit

Permalink
#8993: fix wrong usages of from(ByteBuffer,boolean)
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
  • Loading branch information
lorban committed Dec 6, 2022
1 parent 8fbc5c9 commit 3ccb0da
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public Content.Chunk read()
// TODO: use a ByteBuffer pool and direct ByteBuffers?
ByteBuffer byteBuffer = UTF_8.encode(builder.toString());
state = State.CONTENT;
yield Content.Chunk.from(byteBuffer, false);
yield Content.Chunk.from(byteBuffer, false, () -> {});
}
case CONTENT ->
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ public Content.Chunk read()
if (last)
terminated = Content.Chunk.EOF;
}
if (!buffer.hasRemaining())
return last ? Content.Chunk.EOF : Content.Chunk.EMPTY;
return Content.Chunk.from(buffer, last);
return Content.Chunk.from(buffer, last, () -> {});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,31 @@
public class MockHttpStream implements HttpStream
{
private static final Throwable SUCCEEDED = new Throwable();
private static final Content.Chunk DEMAND = Content.Chunk.EMPTY;
private static final Content.Chunk DEMAND = new Content.Chunk() {
@Override
public ByteBuffer getByteBuffer()
{
return BufferUtil.EMPTY_BUFFER;
}

@Override
public boolean isLast()
{
return false;
}

@Override
public void retain()
{
throw new UnsupportedOperationException();
}

@Override
public boolean release()
{
return true;
}
};
private final long _nanoTime = NanoTime.now();
private final AtomicReference<Content.Chunk> _content = new AtomicReference<>();
private final AtomicReference<Throwable> _complete = new AtomicReference<>();
Expand Down Expand Up @@ -65,7 +89,7 @@ public boolean isDemanding()

public Runnable addContent(ByteBuffer buffer, boolean last)
{
return addContent((last && BufferUtil.isEmpty(buffer)) ? Content.Chunk.EOF : Content.Chunk.from(buffer, last));
return addContent(Content.Chunk.from(buffer, last, () -> {}));
}

public Runnable addContent(String content, boolean last)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private Parts parse(ServletContextRequest.ServletApiRequest request) throws IOEx
formData.parse(Content.Chunk.EOF);
break;
}
formData.parse(Content.Chunk.from(ByteBuffer.wrap(buffer, 0, read), false));
formData.parse(Content.Chunk.from(ByteBuffer.wrap(buffer, 0, read), false, () -> {}));
}

return new Parts(formData);
Expand Down

0 comments on commit 3ccb0da

Please sign in to comment.