Skip to content

Commit 178cb65

Browse files
committed
Commits after SUREFIRE-2058 regarding AbstractStreamDecoder
1 parent 157d2d9 commit 178cb65

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -305,32 +305,24 @@ private String readString( @Nonnull final Memento memento, @Nonnegative final in
305305
memento.getDecoder().reset();
306306
final CharBuffer output = memento.getCharBuffer();
307307
( (Buffer) output ).clear();
308-
final ByteBuffer input = memento.getByteBuffer();
309308
final List<String> strings = new ArrayList<>();
310309
int countDecodedBytes = 0;
311310
for ( boolean endOfInput = false; !endOfInput; )
312311
{
313-
final int bytesToRead = totalBytes - countDecodedBytes;
312+
final int bytesToRead = totalBytes - countDecodedBytes; // our wish to read bytes as much as possible
314313
read( memento, bytesToRead );
315-
int bytesToDecode = min( input.remaining(), bytesToRead );
314+
final ByteBuffer input = memento.getByteBuffer();
315+
int bytesToDecode = min( input.remaining(), bytesToRead ); // our guarantee of available bytes in buffer
316316
final boolean isLastChunk = bytesToDecode == bytesToRead;
317317
endOfInput = countDecodedBytes + bytesToDecode >= totalBytes;
318-
do
319-
{
320-
boolean endOfChunk = output.remaining() >= bytesToRead;
321-
boolean endOfOutput = isLastChunk && endOfChunk;
322-
int readInputBytes = decodeString( memento.getDecoder(), input, output, bytesToDecode, endOfOutput,
323-
memento.getLine().getPositionByteBuffer() );
324-
bytesToDecode -= readInputBytes;
325-
countDecodedBytes += readInputBytes;
326-
}
327-
while ( isLastChunk && bytesToDecode > 0 && output.hasRemaining() );
328-
329-
if ( isLastChunk || !output.hasRemaining() )
330-
{
331-
strings.add( ( (Buffer) output ).flip().toString() );
332-
( (Buffer) output ).clear();
333-
}
318+
boolean endOfChunk = output.remaining() >= bytesToRead;
319+
boolean endOfOutput = isLastChunk && endOfChunk;
320+
int readInputBytes = decodeString( memento.getDecoder(), input, output, bytesToDecode, endOfOutput,
321+
memento.getLine().getPositionByteBuffer() );
322+
countDecodedBytes += readInputBytes;
323+
strings.add( ( (Buffer) output ).flip().toString() );
324+
( (Buffer) output ).clear();
325+
memento.getLine().setPositionByteBuffer( 0 );
334326
}
335327

336328
memento.getDecoder().reset();

0 commit comments

Comments
 (0)