23
23
import java .io .IOException ;
24
24
import java .io .InputStream ;
25
25
import java .io .OutputStream ;
26
+ import java .nio .Buffer ;
26
27
import java .nio .ByteBuffer ;
27
28
import java .nio .charset .Charset ;
28
29
@@ -209,7 +210,8 @@ public int arrayOffset() {
209
210
* A {@link ReadableBuffer} that is backed by a {@link ByteBuffer}.
210
211
*/
211
212
private static class ByteReadableBufferWrapper extends AbstractReadableBuffer {
212
- final ByteBuffer bytes ;
213
+ // Use Buffer instead of ByteBuffer for JDK 9+ compatibility.
214
+ final Buffer bytes ;
213
215
214
216
ByteReadableBufferWrapper (ByteBuffer bytes ) {
215
217
this .bytes = Preconditions .checkNotNull (bytes , "bytes" );
@@ -223,7 +225,7 @@ public int readableBytes() {
223
225
@ Override
224
226
public int readUnsignedByte () {
225
227
checkReadable (1 );
226
- return bytes .get () & 0xFF ;
228
+ return (( ByteBuffer ) bytes ) .get () & 0xFF ;
227
229
}
228
230
229
231
@ Override
@@ -235,7 +237,7 @@ public void skipBytes(int length) {
235
237
@ Override
236
238
public void readBytes (byte [] dest , int destOffset , int length ) {
237
239
checkReadable (length );
238
- bytes .get (dest , destOffset , length );
240
+ (( ByteBuffer ) bytes ) .get (dest , destOffset , length );
239
241
}
240
242
241
243
@ Override
@@ -249,7 +251,7 @@ public void readBytes(ByteBuffer dest) {
249
251
bytes .limit (bytes .position () + length );
250
252
251
253
// Write the bytes and restore the original limit.
252
- dest .put (bytes );
254
+ dest .put (( ByteBuffer ) bytes );
253
255
bytes .limit (prevLimit );
254
256
}
255
257
@@ -262,16 +264,16 @@ public void readBytes(OutputStream dest, int length) throws IOException {
262
264
} else {
263
265
// The buffer doesn't support array(). Copy the data to an intermediate buffer.
264
266
byte [] array = new byte [length ];
265
- bytes .get (array );
267
+ (( ByteBuffer ) bytes ) .get (array );
266
268
dest .write (array );
267
269
}
268
270
}
269
271
270
272
@ Override
271
273
public ByteReadableBufferWrapper readBytes (int length ) {
272
274
checkReadable (length );
273
- ByteBuffer buffer = bytes .duplicate ();
274
- buffer .limit (bytes .position () + length );
275
+ ByteBuffer buffer = (( ByteBuffer ) bytes ) .duplicate ();
276
+ (( Buffer ) buffer ) .limit (bytes .position () + length );
275
277
bytes .position (bytes .position () + length );
276
278
return new ByteReadableBufferWrapper (buffer );
277
279
}
@@ -283,7 +285,7 @@ public boolean hasArray() {
283
285
284
286
@ Override
285
287
public byte [] array () {
286
- return bytes .array ();
288
+ return (( ByteBuffer ) bytes ) .array ();
287
289
}
288
290
289
291
@ Override
0 commit comments