/** * Checks whether the Buffer is backed by a simple array. In java, a Buffer is an abstraction that * can represent various data, from data on disk all the way to native Java arrays. Like all * abstractions, a Buffer might carry a performance penalty. Thus, we sometimes check whether the * Buffer is simply a wrapper around a Java array. In these instances, it might be best, from a * performance point of view, to access the underlying array (using the array()) method. * @param b the provided Buffer * @return whether the Buffer is backed by a simple array */ protected static boolean isBackedBySimpleArray(Buffer b) { return b.hasArray() && (b.arrayOffset() == 0); }
/** * Returns the offset in bytes from the start of the underlying * Java array object containing the data of the given Buffer to * the actual start of the data. The start of the data takes into * account the Buffer's current position. This method is only * meaningful if getBaseArray() returns non-null. * * @param b the Buffer to be queried * @return the data offset in bytes to the start of this Buffer's data */ static int getBaseArrayOffset(Buffer b) { return b.hasArray() ? ((b.arrayOffset() + b.position) << b._elementSizeShift) : 0; } }
if (buffer.hasArray()) { array = buffer.array(); offset = buffer.arrayOffset(); } else { int pos = buffer.position();
@MarshalsPointer(supportedCallTypes = MarshalerFlags.CALL_TYPE_BRIDGE) public static long toNative(Buffer buffer, long flags) { if (buffer == null) { return 0L; } if (!buffer.isDirect() && !buffer.hasArray()) { // Non-direct buffers must be backed by an array to be supported. // We could have made a copy of the buffer contents and returned // a pointer to that but then changes made to the contents by // native code wouldn't be visible in the original buffer and // the semantics would be different depending on the type of // the buffer. throw new IllegalArgumentException("Only direct and array-backed " + "java.nio.Buffers can be marshaled to pointers."); } if (buffer.isDirect()) { return VM.getLong(VM.getObjectAddress(buffer) + EFFECTIVE_DIRECT_ADDRESS_OFFSET); } else { Object array = buffer.array(); int offset = buffer.arrayOffset(); int shift = VM.getInt(VM.getObjectAddress(buffer) + _ELEMENT_SIZE_SHIFT_OFFSET); return VM.getArrayValuesAddress(array) + (offset << shift); } }
@Override public int offset(Object o) { Buffer buffer = (Buffer) o; return buffer.arrayOffset() + buffer.position(); }
@Override public int offset(Object o) { Buffer buffer = (Buffer) o; return buffer.arrayOffset() + buffer.position(); }
@Override public int offset(Object o) { Buffer buffer = (Buffer) o; return buffer.arrayOffset() + buffer.position(); }
@Override public int offset(Object o) { Buffer buffer = (Buffer) o; return buffer.arrayOffset() + buffer.position(); }
@Override public int offset(Object o) { Buffer buffer = (Buffer) o; return buffer.arrayOffset() + buffer.position(); }
@Override public int offset(Object o) { Buffer buffer = (Buffer) o; return buffer.arrayOffset() + buffer.position(); }
/** * Returns the offset in bytes from the start of the underlying * Java array object containing the data of the given Buffer to * the actual start of the data. The start of the data takes into * account the Buffer's current position. This method is only * meaningful if getBaseArray() returns non-null. * * @param b the Buffer to be queried * @return the data offset in bytes to the start of this Buffer's data */ static int getBaseArrayOffset(Buffer b) { return b.hasArray() ? ((b.arrayOffset() + b.position) << b._elementSizeShift) : 0; } }
@Override public final int arrayOffset() { if( hasArray() ) { return buffer.arrayOffset(); } else { return 0; } }
/** * Checks whether the Buffer is backed by a simple array. In java, a Buffer is an abstraction that * can represent various data, from data on disk all the way to native Java arrays. Like all * abstractions, a Buffer might carry a performance penalty. Thus, we sometimes check whether the * Buffer is simply a wrapper around a Java array. In these instances, it might be best, from a * performance point of view, to access the underlying array (using the array()) method. * @param b the provided Buffer * @return whether the Buffer is backed by a simple array */ protected static boolean isBackedBySimpleArray(Buffer b) { return b.hasArray() && (b.arrayOffset() == 0); }
/** * Returns the offset in bytes from the start of the underlying * Java array object containing the data of the given Buffer to * the actual start of the data. The start of the data takes into * account the Buffer's current position. This method is only * meaningful if getBaseArray() returns non-null. * * @param b the Buffer to be queried * @return the data offset in bytes to the start of this Buffer's data */ static int getBaseArrayOffset(Buffer b) { return b.hasArray() ? ((b.arrayOffset() + b.position) << b._elementSizeShift) : 0; } }
/** * Returns the offset in bytes from the start of the underlying * Java array object containing the data of the given Buffer to * the actual start of the data. The start of the data takes into * account the Buffer's current position. This method is only * meaningful if getBaseArray() returns non-null. * * @param b the Buffer to be queried * @return the data offset in bytes to the start of this Buffer's data */ static int getBaseArrayOffset(Buffer b) { return b.hasArray() ? ((b.arrayOffset() + b.position) << b._elementSizeShift) : 0; } }
/** * Returns the offset in bytes from the start of the underlying * Java array object containing the data of the given Buffer to * the actual start of the data. The start of the data takes into * account the Buffer's current position. This method is only * meaningful if getBaseArray() returns non-null. * * @param b the Buffer to be queried * @return the data offset in bytes to the start of this Buffer's data */ static int getBaseArrayOffset(Buffer b) { return b.hasArray() ? ((b.arrayOffset() + b.position) << b._elementSizeShift) : 0; } }
public static long getBufferAddress(Buffer buffer) { if (buffer.isDirect()) { return VM.getLong(VM.getObjectAddress(buffer) + ADDRESS_OFFSET); } else { Object array = buffer.array(); int offset = buffer.arrayOffset(); int shift = getElementShift(array); return VM.getArrayValuesAddress(array) + (offset << shift); } }
public static long getBufferAddress(Buffer buffer) { if (buffer.isDirect()) { return VM.getLong(VM.getObjectAddress(buffer) + EFFECTIVE_DIRECT_ADDRESS_OFFSET); } else { Object array = buffer.array(); int offset = buffer.arrayOffset(); int shift = VM.getInt(VM.getObjectAddress(buffer) + _ELEMENT_SIZE_SHIFT_OFFSET); return VM.getArrayValuesAddress(array) + (offset << shift); } }
public static long getBufferAddress(Buffer buffer) { if (buffer.isDirect()) { return VM.getLong(VM.getObjectAddress(buffer) + EFFECTIVE_DIRECT_ADDRESS_OFFSET); } else { Object array = buffer.array(); int offset = buffer.arrayOffset(); int shift = VM.getInt(VM.getObjectAddress(buffer) + _ELEMENT_SIZE_SHIFT_OFFSET); return VM.getArrayValuesAddress(array) + (offset << shift); } }
public static long getBufferAddress(Buffer buffer) { if (buffer.isDirect()) { return VM.getLong(VM.getObjectAddress(buffer) + EFFECTIVE_DIRECT_ADDRESS_OFFSET); } else { Object array = buffer.array(); int offset = buffer.arrayOffset(); int shift = VM.getInt(VM.getObjectAddress(buffer) + _ELEMENT_SIZE_SHIFT_OFFSET); return VM.getArrayValuesAddress(array) + (offset << shift); } }