zoltanmeze commented on code in PR #519:
URL: https://github.com/apache/maven-surefire/pull/519#discussion_r849436470


##########
surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java:
##########
@@ -305,32 +313,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 );

Review Comment:
   What's the reason of resetting line position here?
   
   Will give this branch a try later. Maybe compare events dump before and 
after on single test runs, and just see if larger projects have no other 
issues. 
   
   I think I already tried with removed do-while once, because it was 
suspicious at first look. But didn't want to change anything else in #518 , but 
my guess was that that wile condition is never true.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to