mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-28 05:48:06 +00:00
avoiding NoSuchMethod exception (#6658)
This commit is contained in:
@@ -2,6 +2,7 @@ package com.google.flatbuffers;
|
|||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
import java.nio.Buffer;
|
||||||
|
|
||||||
public class ByteBufferReadWriteBuf implements ReadWriteBuf {
|
public class ByteBufferReadWriteBuf implements ReadWriteBuf {
|
||||||
|
|
||||||
@@ -117,9 +118,9 @@ public class ByteBufferReadWriteBuf implements ReadWriteBuf {
|
|||||||
public void set(int index, byte[] value, int start, int length) {
|
public void set(int index, byte[] value, int start, int length) {
|
||||||
requestCapacity(index + (length - start));
|
requestCapacity(index + (length - start));
|
||||||
int curPos = buffer.position();
|
int curPos = buffer.position();
|
||||||
buffer.position(index);
|
((Buffer) buffer).position(index);
|
||||||
buffer.put(value, start, length);
|
buffer.put(value, start, length);
|
||||||
buffer.position(curPos);
|
((Buffer) buffer).position(curPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -154,7 +155,7 @@ public class ByteBufferReadWriteBuf implements ReadWriteBuf {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int writePosition() {
|
public int writePosition() {
|
||||||
return buffer.position();
|
return ((Buffer) buffer).position();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.google.flatbuffers;
|
|||||||
import static com.google.flatbuffers.Constants.*;
|
import static com.google.flatbuffers.Constants.*;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.Buffer;
|
||||||
|
|
||||||
/// @file
|
/// @file
|
||||||
/// @addtogroup flatbuffers_java_api
|
/// @addtogroup flatbuffers_java_api
|
||||||
@@ -49,7 +50,7 @@ public class ByteBufferUtil {
|
|||||||
*/
|
*/
|
||||||
public static ByteBuffer removeSizePrefix(ByteBuffer bb) {
|
public static ByteBuffer removeSizePrefix(ByteBuffer bb) {
|
||||||
ByteBuffer s = bb.duplicate();
|
ByteBuffer s = bb.duplicate();
|
||||||
s.position(s.position() + SIZE_PREFIX_LENGTH);
|
((Buffer) s).position(s.position() + SIZE_PREFIX_LENGTH);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -273,10 +273,10 @@ public class FlatBufferBuilder {
|
|||||||
new_buf_size = (old_buf_size & 0xC0000000) != 0 ? MAX_BUFFER_SIZE : old_buf_size << 1;
|
new_buf_size = (old_buf_size & 0xC0000000) != 0 ? MAX_BUFFER_SIZE : old_buf_size << 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bb.position(0);
|
((Buffer) bb).position(0);
|
||||||
ByteBuffer nbb = bb_factory.newByteBuffer(new_buf_size);
|
ByteBuffer nbb = bb_factory.newByteBuffer(new_buf_size);
|
||||||
new_buf_size = nbb.clear().capacity(); // Ensure the returned buffer is treated as empty
|
new_buf_size = nbb.clear().capacity(); // Ensure the returned buffer is treated as empty
|
||||||
nbb.position(new_buf_size - old_buf_size);
|
((Buffer) nbb).position(new_buf_size - old_buf_size);
|
||||||
nbb.put(bb);
|
nbb.put(bb);
|
||||||
return nbb;
|
return nbb;
|
||||||
}
|
}
|
||||||
@@ -527,7 +527,7 @@ public class FlatBufferBuilder {
|
|||||||
int length = elem_size * num_elems;
|
int length = elem_size * num_elems;
|
||||||
startVector(elem_size, num_elems, alignment);
|
startVector(elem_size, num_elems, alignment);
|
||||||
|
|
||||||
bb.position(space -= length);
|
((Buffer) bb).position(space -= length);
|
||||||
|
|
||||||
// Slice and limit the copy vector to point to the 'array'
|
// Slice and limit the copy vector to point to the 'array'
|
||||||
ByteBuffer copy = bb.slice().order(ByteOrder.LITTLE_ENDIAN);
|
ByteBuffer copy = bb.slice().order(ByteOrder.LITTLE_ENDIAN);
|
||||||
@@ -602,7 +602,7 @@ public class FlatBufferBuilder {
|
|||||||
int length = utf8.encodedLength(s);
|
int length = utf8.encodedLength(s);
|
||||||
addByte((byte)0);
|
addByte((byte)0);
|
||||||
startVector(1, length, 1);
|
startVector(1, length, 1);
|
||||||
bb.position(space -= length);
|
((Buffer) bb).position(space -= length);
|
||||||
utf8.encodeUtf8(s, bb);
|
utf8.encodeUtf8(s, bb);
|
||||||
return endVector();
|
return endVector();
|
||||||
}
|
}
|
||||||
@@ -617,7 +617,7 @@ public class FlatBufferBuilder {
|
|||||||
int length = s.remaining();
|
int length = s.remaining();
|
||||||
addByte((byte)0);
|
addByte((byte)0);
|
||||||
startVector(1, length, 1);
|
startVector(1, length, 1);
|
||||||
bb.position(space -= length);
|
((Buffer) bb).position(space -= length);
|
||||||
bb.put(s);
|
bb.put(s);
|
||||||
return endVector();
|
return endVector();
|
||||||
}
|
}
|
||||||
@@ -631,7 +631,7 @@ public class FlatBufferBuilder {
|
|||||||
public int createByteVector(byte[] arr) {
|
public int createByteVector(byte[] arr) {
|
||||||
int length = arr.length;
|
int length = arr.length;
|
||||||
startVector(1, length, 1);
|
startVector(1, length, 1);
|
||||||
bb.position(space -= length);
|
((Buffer) bb).position(space -= length);
|
||||||
bb.put(arr);
|
bb.put(arr);
|
||||||
return endVector();
|
return endVector();
|
||||||
}
|
}
|
||||||
@@ -646,7 +646,7 @@ public class FlatBufferBuilder {
|
|||||||
*/
|
*/
|
||||||
public int createByteVector(byte[] arr, int offset, int length) {
|
public int createByteVector(byte[] arr, int offset, int length) {
|
||||||
startVector(1, length, 1);
|
startVector(1, length, 1);
|
||||||
bb.position(space -= length);
|
((Buffer) bb).position(space -= length);
|
||||||
bb.put(arr, offset, length);
|
bb.put(arr, offset, length);
|
||||||
return endVector();
|
return endVector();
|
||||||
}
|
}
|
||||||
@@ -663,7 +663,7 @@ public class FlatBufferBuilder {
|
|||||||
public int createByteVector(ByteBuffer byteBuffer) {
|
public int createByteVector(ByteBuffer byteBuffer) {
|
||||||
int length = byteBuffer.remaining();
|
int length = byteBuffer.remaining();
|
||||||
startVector(1, length, 1);
|
startVector(1, length, 1);
|
||||||
bb.position(space -= length);
|
((Buffer) bb).position(space -= length);
|
||||||
bb.put(byteBuffer);
|
bb.put(byteBuffer);
|
||||||
return endVector();
|
return endVector();
|
||||||
}
|
}
|
||||||
@@ -953,7 +953,7 @@ public class FlatBufferBuilder {
|
|||||||
if (size_prefix) {
|
if (size_prefix) {
|
||||||
addInt(bb.capacity() - space);
|
addInt(bb.capacity() - space);
|
||||||
}
|
}
|
||||||
bb.position(space);
|
((Buffer) bb).position(space);
|
||||||
finished = true;
|
finished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1067,7 +1067,7 @@ public class FlatBufferBuilder {
|
|||||||
public byte[] sizedByteArray(int start, int length){
|
public byte[] sizedByteArray(int start, int length){
|
||||||
finished();
|
finished();
|
||||||
byte[] array = new byte[length];
|
byte[] array = new byte[length];
|
||||||
bb.position(start);
|
((Buffer) bb).position(start);
|
||||||
bb.get(array);
|
bb.get(array);
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
@@ -1090,7 +1090,7 @@ public class FlatBufferBuilder {
|
|||||||
public InputStream sizedInputStream() {
|
public InputStream sizedInputStream() {
|
||||||
finished();
|
finished();
|
||||||
ByteBuffer duplicate = bb.duplicate();
|
ByteBuffer duplicate = bb.duplicate();
|
||||||
duplicate.position(space);
|
((Buffer) duplicate).position(space);
|
||||||
duplicate.limit(bb.capacity());
|
duplicate.limit(bb.capacity());
|
||||||
return new ByteBufferBackedInputStream(duplicate);
|
return new ByteBufferBackedInputStream(duplicate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import static com.google.flatbuffers.FlexBuffers.Unsigned.shortToUnsignedInt;
|
|||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.Buffer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/// @file
|
/// @file
|
||||||
@@ -688,7 +689,7 @@ public class FlexBuffers {
|
|||||||
*/
|
*/
|
||||||
public ByteBuffer data() {
|
public ByteBuffer data() {
|
||||||
ByteBuffer dup = ByteBuffer.wrap(bb.data());
|
ByteBuffer dup = ByteBuffer.wrap(bb.data());
|
||||||
dup.position(end);
|
((Buffer) dup).position(end);
|
||||||
dup.limit(end + size());
|
dup.limit(end + size());
|
||||||
return dup.asReadOnlyBuffer().slice();
|
return dup.asReadOnlyBuffer().slice();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.google.flatbuffers;
|
|||||||
|
|
||||||
import static com.google.flatbuffers.Constants.*;
|
import static com.google.flatbuffers.Constants.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.Buffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
/// @cond FLATBUFFERS_INTERNAL
|
/// @cond FLATBUFFERS_INTERNAL
|
||||||
@@ -152,7 +153,7 @@ public class Table {
|
|||||||
if (o == 0) return null;
|
if (o == 0) return null;
|
||||||
ByteBuffer bb = this.bb.duplicate().order(ByteOrder.LITTLE_ENDIAN);
|
ByteBuffer bb = this.bb.duplicate().order(ByteOrder.LITTLE_ENDIAN);
|
||||||
int vectorstart = __vector(o);
|
int vectorstart = __vector(o);
|
||||||
bb.position(vectorstart);
|
((Buffer) bb).position(vectorstart);
|
||||||
bb.limit(vectorstart + __vector_len(o) * elem_size);
|
bb.limit(vectorstart + __vector_len(o) * elem_size);
|
||||||
return bb;
|
return bb;
|
||||||
}
|
}
|
||||||
@@ -174,7 +175,7 @@ public class Table {
|
|||||||
int vectorstart = __vector(o);
|
int vectorstart = __vector(o);
|
||||||
bb.rewind();
|
bb.rewind();
|
||||||
bb.limit(vectorstart + __vector_len(o) * elem_size);
|
bb.limit(vectorstart + __vector_len(o) * elem_size);
|
||||||
bb.position(vectorstart);
|
((Buffer) bb).position(vectorstart);
|
||||||
return bb;
|
return bb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.google.flatbuffers;
|
package com.google.flatbuffers;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.Buffer;
|
||||||
import java.nio.CharBuffer;
|
import java.nio.CharBuffer;
|
||||||
import java.nio.charset.CharacterCodingException;
|
import java.nio.charset.CharacterCodingException;
|
||||||
import java.nio.charset.CharsetDecoder;
|
import java.nio.charset.CharsetDecoder;
|
||||||
@@ -87,7 +88,7 @@ public class Utf8Old extends Utf8 {
|
|||||||
CharsetDecoder decoder = CACHE.get().decoder;
|
CharsetDecoder decoder = CACHE.get().decoder;
|
||||||
decoder.reset();
|
decoder.reset();
|
||||||
buffer = buffer.duplicate();
|
buffer = buffer.duplicate();
|
||||||
buffer.position(offset);
|
((Buffer) buffer).position(offset);
|
||||||
buffer.limit(offset + length);
|
buffer.limit(offset + length);
|
||||||
try {
|
try {
|
||||||
CharBuffer result = decoder.decode(buffer);
|
CharBuffer result = decoder.decode(buffer);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
package com.google.flatbuffers;
|
package com.google.flatbuffers;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.Buffer;
|
||||||
import static java.lang.Character.MAX_SURROGATE;
|
import static java.lang.Character.MAX_SURROGATE;
|
||||||
import static java.lang.Character.MIN_SUPPLEMENTARY_CODE_POINT;
|
import static java.lang.Character.MIN_SUPPLEMENTARY_CODE_POINT;
|
||||||
import static java.lang.Character.MIN_SURROGATE;
|
import static java.lang.Character.MIN_SURROGATE;
|
||||||
@@ -310,7 +311,7 @@ final public class Utf8Safe extends Utf8 {
|
|||||||
}
|
}
|
||||||
if (inIx == inLength) {
|
if (inIx == inLength) {
|
||||||
// Successfully encoded the entire string.
|
// Successfully encoded the entire string.
|
||||||
out.position(outIx + inIx);
|
((Buffer) out).position(outIx + inIx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +354,7 @@ final public class Utf8Safe extends Utf8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Successfully encoded the entire string.
|
// Successfully encoded the entire string.
|
||||||
out.position(outIx);
|
((Buffer) out).position(outIx);
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
// TODO(nathanmittler): Consider making the API throw IndexOutOfBoundsException instead.
|
// TODO(nathanmittler): Consider making the API throw IndexOutOfBoundsException instead.
|
||||||
|
|
||||||
@@ -434,7 +435,7 @@ final public class Utf8Safe extends Utf8 {
|
|||||||
int start = out.arrayOffset();
|
int start = out.arrayOffset();
|
||||||
int end = encodeUtf8Array(in, out.array(), start + out.position(),
|
int end = encodeUtf8Array(in, out.array(), start + out.position(),
|
||||||
out.remaining());
|
out.remaining());
|
||||||
out.position(end - start);
|
((Buffer) out).position(end - start);
|
||||||
} else {
|
} else {
|
||||||
encodeUtf8Buffer(in, out);
|
encodeUtf8Buffer(in, out);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user