diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java b/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java index facf30bcb5..7405414807 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java @@ -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 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();