Skip to content

Commit

Permalink
[SUREFIRE-1982] Fix failures (java.nio.ChartBuffer) when compiled on …
Browse files Browse the repository at this point in the history
…Java 9+ and run on Java 8
  • Loading branch information
Tibor17 committed Jan 19, 2022
1 parent 2da8f9b commit 747c757
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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<String> strings = new ArrayList<>();
int countDecodedBytes = 0;
Expand All @@ -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 );
}
Expand Down
Expand Up @@ -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 );

Expand All @@ -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 );

Expand Down Expand Up @@ -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)" );
Expand Down

0 comments on commit 747c757

Please sign in to comment.