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 bcfaee9860..de197d5a45 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 @@ -171,7 +171,7 @@ protected Charset readCharset( @Nonnull Memento memento ) throws IOException, Ma protected String readString( @Nonnull Memento memento ) throws IOException, MalformedFrameException { - memento.getCharBuffer().clear(); + ( (Buffer) memento.getCharBuffer() ).clear(); int readCount = readInt( memento ); if ( readCount < 0 ) { @@ -293,7 +293,7 @@ private String readString( @Nonnull final Memento memento, @Nonnegative final in { memento.getDecoder().reset(); final CharBuffer output = memento.getCharBuffer(); - output.clear(); + ( (Buffer) output ).clear(); final ByteBuffer input = memento.getByteBuffer(); final List strings = new ArrayList<>(); int countDecodedBytes = 0; @@ -317,13 +317,13 @@ private String readString( @Nonnull final Memento memento, @Nonnegative final in if ( isLastChunk || !output.hasRemaining() ) { - strings.add( output.flip().toString() ); - output.clear(); + strings.add( ( (Buffer) output ).flip().toString() ); + ( (Buffer) output ).clear(); } } memento.getDecoder().reset(); - output.clear(); + ( (Buffer) output ).clear(); return toString( strings ); } diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoderTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoderTest.java index 36ef828bc2..8d4e1c521b 100644 --- a/surefire-api/src/test/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoderTest.java +++ b/surefire-api/src/test/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoderTest.java @@ -151,7 +151,7 @@ public void shouldDecodeHappyCase() throws Exception ByteBuffer input = ByteBuffer.allocate( 1024 ); ( (Buffer) input.put( PATTERN2_BYTES ) ).flip(); int bytesToDecode = PATTERN2_BYTES.length; - CharBuffer output = CharBuffer.allocate( 1024 ); + Buffer output = CharBuffer.allocate( 1024 ); int readBytes = invokeMethod( AbstractStreamDecoder.class, "decodeString", decoder, input, output, bytesToDecode, true, 0 ); @@ -172,7 +172,7 @@ public void shouldDecodeShifted() throws Exception .put( 91, (byte) 'B' ) .put( 92, (byte) 'C' ) ) .position( 90 ); - CharBuffer output = CharBuffer.allocate( 1024 ); + Buffer output = CharBuffer.allocate( 1024 ); int readBytes = invokeMethod( AbstractStreamDecoder.class, "decodeString", decoder, input, output, 2, true, 0 ); @@ -371,9 +371,9 @@ public void shouldDecode100Bytes() throws Exception { decoder.reset() .decode( buffer, chars, true ); // CharsetDecoder 71 nanos - s = chars.flip().toString(); // CharsetDecoder + toString = 91 nanos + s = ( (Buffer) chars ).flip().toString(); // CharsetDecoder + toString = 91 nanos ( (Buffer) buffer ).clear(); - chars.clear(); + ( (Buffer) chars ).clear(); } long l2 = System.currentTimeMillis(); System.out.println( "decoded 100 bytes within " + ( l2 - l1 ) + " millis (10 million cycles)" );