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 15, 2022
1 parent 157d2d9 commit 3363a1c
Showing 1 changed file with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,37 +305,26 @@ 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();
( (Buffer) output ).clear();

return toString( strings );
}

Expand Down

0 comments on commit 3363a1c

Please sign in to comment.