[Java] Avoid casting ByteBuffer to Buffer (#6785)

* Revert "avoiding even more NoSuchMethod exceptions (#6729)"

This reverts commit 6fb2c90d9e.

* Revert "avoiding more NoSuchMethod exceptions (#6671)"

This reverts commit 752c7b576d.

* Revert "avoiding NoSuchMethod exception (#6658)"

This reverts commit 813d3632ec.

* Use Java 8 for Kotlin Linux builds to verify
This commit is contained in:
Björn Harrtell
2021-08-31 00:51:06 +02:00
committed by GitHub
parent b20c4d3aad
commit 0e9d79c355
8 changed files with 34 additions and 40 deletions

View File

@@ -92,7 +92,7 @@ public class FlatBufferBuilder {
this.bb_factory = bb_factory;
if (existing_bb != null) {
bb = existing_bb;
((Buffer) bb).clear();
bb.clear();
bb.order(ByteOrder.LITTLE_ENDIAN);
} else {
bb = bb_factory.newByteBuffer(initial_size);
@@ -154,7 +154,7 @@ public class FlatBufferBuilder {
public FlatBufferBuilder init(ByteBuffer existing_bb, ByteBufferFactory bb_factory){
this.bb_factory = bb_factory;
bb = existing_bb;
((Buffer) bb).clear();
bb.clear();
bb.order(ByteOrder.LITTLE_ENDIAN);
minalign = 1;
space = bb.capacity();
@@ -235,7 +235,7 @@ public class FlatBufferBuilder {
*/
public void clear(){
space = bb.capacity();
((Buffer) bb).clear();
bb.clear();
minalign = 1;
while(vtable_in_use > 0) vtable[--vtable_in_use] = 0;
vtable_in_use = 0;
@@ -273,10 +273,10 @@ public class FlatBufferBuilder {
new_buf_size = (old_buf_size & 0xC0000000) != 0 ? MAX_BUFFER_SIZE : old_buf_size << 1;
}
((Buffer) bb).position(0);
bb.position(0);
ByteBuffer nbb = bb_factory.newByteBuffer(new_buf_size);
new_buf_size = ((Buffer) nbb).clear().capacity(); // Ensure the returned buffer is treated as empty
((Buffer) nbb).position(new_buf_size - old_buf_size);
new_buf_size = nbb.clear().capacity(); // Ensure the returned buffer is treated as empty
nbb.position(new_buf_size - old_buf_size);
nbb.put(bb);
return nbb;
}
@@ -527,7 +527,7 @@ public class FlatBufferBuilder {
int length = elem_size * num_elems;
startVector(elem_size, num_elems, alignment);
((Buffer) bb).position(space -= length);
bb.position(space -= length);
// Slice and limit the copy vector to point to the 'array'
ByteBuffer copy = bb.slice().order(ByteOrder.LITTLE_ENDIAN);
@@ -602,7 +602,7 @@ public class FlatBufferBuilder {
int length = utf8.encodedLength(s);
addByte((byte)0);
startVector(1, length, 1);
((Buffer) bb).position(space -= length);
bb.position(space -= length);
utf8.encodeUtf8(s, bb);
return endVector();
}
@@ -617,7 +617,7 @@ public class FlatBufferBuilder {
int length = s.remaining();
addByte((byte)0);
startVector(1, length, 1);
((Buffer) bb).position(space -= length);
bb.position(space -= length);
bb.put(s);
return endVector();
}
@@ -631,7 +631,7 @@ public class FlatBufferBuilder {
public int createByteVector(byte[] arr) {
int length = arr.length;
startVector(1, length, 1);
((Buffer) bb).position(space -= length);
bb.position(space -= length);
bb.put(arr);
return endVector();
}
@@ -646,7 +646,7 @@ public class FlatBufferBuilder {
*/
public int createByteVector(byte[] arr, int offset, int length) {
startVector(1, length, 1);
((Buffer) bb).position(space -= length);
bb.position(space -= length);
bb.put(arr, offset, length);
return endVector();
}
@@ -663,7 +663,7 @@ public class FlatBufferBuilder {
public int createByteVector(ByteBuffer byteBuffer) {
int length = byteBuffer.remaining();
startVector(1, length, 1);
((Buffer) bb).position(space -= length);
bb.position(space -= length);
bb.put(byteBuffer);
return endVector();
}
@@ -953,7 +953,7 @@ public class FlatBufferBuilder {
if (size_prefix) {
addInt(bb.capacity() - space);
}
((Buffer) bb).position(space);
bb.position(space);
finished = true;
}
@@ -1067,7 +1067,7 @@ public class FlatBufferBuilder {
public byte[] sizedByteArray(int start, int length){
finished();
byte[] array = new byte[length];
((Buffer) bb).position(start);
bb.position(start);
bb.get(array);
return array;
}
@@ -1089,10 +1089,10 @@ public class FlatBufferBuilder {
*/
public InputStream sizedInputStream() {
finished();
Buffer duplicate = ((Buffer) bb).duplicate();
ByteBuffer duplicate = bb.duplicate();
duplicate.position(space);
duplicate.limit(bb.capacity());
return new ByteBufferBackedInputStream((ByteBuffer) duplicate);
return new ByteBufferBackedInputStream(duplicate);
}
/**