Skip to content

Commit

Permalink
Commits after SUREFIRE-2058 regarding AbstractStreamDecoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibor17 committed Apr 12, 2022
1 parent 157d2d9 commit 178cb65
Showing 1 changed file with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,32 +305,24 @@ private String readString( @Nonnull final Memento memento, @Nonnegative final in
memento.getDecoder().reset();
final CharBuffer output = memento.getCharBuffer();
( (Buffer) output ).clear();
final ByteBuffer input = memento.getByteBuffer();
final List<String> strings = new ArrayList<>();
int countDecodedBytes = 0;
for ( boolean endOfInput = false; !endOfInput; )
{
final int bytesToRead = totalBytes - countDecodedBytes;
final int bytesToRead = totalBytes - countDecodedBytes; // our wish to read bytes as much as possible
read( memento, bytesToRead );
int bytesToDecode = min( input.remaining(), bytesToRead );
final ByteBuffer input = memento.getByteBuffer();
int bytesToDecode = min( input.remaining(), bytesToRead ); // our guarantee of available bytes in buffer
final boolean isLastChunk = bytesToDecode == bytesToRead;
endOfInput = countDecodedBytes + bytesToDecode >= totalBytes;
do
{
boolean endOfChunk = output.remaining() >= bytesToRead;
boolean endOfOutput = isLastChunk && endOfChunk;
int readInputBytes = decodeString( memento.getDecoder(), input, output, bytesToDecode, endOfOutput,
memento.getLine().getPositionByteBuffer() );
bytesToDecode -= readInputBytes;
countDecodedBytes += readInputBytes;
}
while ( isLastChunk && bytesToDecode > 0 && output.hasRemaining() );

if ( isLastChunk || !output.hasRemaining() )
{
strings.add( ( (Buffer) output ).flip().toString() );
( (Buffer) output ).clear();
}
boolean endOfChunk = output.remaining() >= bytesToRead;
boolean endOfOutput = isLastChunk && endOfChunk;
int readInputBytes = decodeString( memento.getDecoder(), input, output, bytesToDecode, endOfOutput,
memento.getLine().getPositionByteBuffer() );
countDecodedBytes += readInputBytes;
strings.add( ( (Buffer) output ).flip().toString() );
( (Buffer) output ).clear();
memento.getLine().setPositionByteBuffer( 0 );
}

memento.getDecoder().reset();
Expand Down

0 comments on commit 178cb65

Please sign in to comment.