/** * Returns the underlying Java array containing the data of the * given Buffer, or null if the Buffer is not backed by a Java array. * * @param b the Buffer to be queried * @return the Java array containing the Buffer's data, or null if * there is none */ static Object getBaseArray(Buffer b) { return b.hasArray() ? b.array() : null; }
/** * 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; } }
public static int[] getIntArrayFromBuffer(Buffer buffer) { int[] array = new int[0]; if (buffer != null) { if (buffer.hasArray()) { array = (int[]) buffer.array(); } else { buffer.rewind(); array = new int[buffer.capacity()]; if (buffer instanceof IntBuffer) { ((IntBuffer) buffer).get(array); } else if (buffer instanceof ShortBuffer) { int count = 0; while (buffer.hasRemaining()) { array[count] = (int) (((ShortBuffer) buffer).get()); ++count; } } } } return array; }
/** * Creates an int array from the provided {@link IntBuffer} or {@link ShortBuffer}. * * @param buffer {@link Buffer} the data source. Should be either a {@link IntBuffer} * or {@link ShortBuffer}. * @return int array containing the data of the buffer. */ public static int[] getIntArrayFromBuffer(Buffer buffer) { int[] array = null; if (buffer.hasArray()) { array = (int[]) buffer.array(); } else { buffer.rewind(); array = new int[buffer.capacity()]; if (buffer instanceof IntBuffer) { ((IntBuffer) buffer).get(array); } else if (buffer instanceof ShortBuffer) { int count = 0; while (buffer.hasRemaining()) { array[count] = (int) (((ShortBuffer) buffer).get()); ++count; } } } return array; } }
src = VM.getLong(VM.getObjectAddress(buffer) + EFFECTIVE_DIRECT_ADDRESS_OFFSET); } else { if (buffer.hasArray()) { array = buffer.array(); offset = buffer.arrayOffset();
@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); } }
if (!indices.getData().hasArray()) { if (indices.getFormat() == Format.UnsignedByte) { ByteBuffer originalIndex = (ByteBuffer) indices.getData(); if (!weights.getData().hasArray()) { FloatBuffer originalWeight = (FloatBuffer) weights.getData(); FloatBuffer arrayWeight = FloatBuffer.allocate(originalWeight.capacity());
@Override public final boolean hasArray() { return buffer.hasArray(); }
/** * Returns the underlying Java array containing the data of the * given Buffer, or null if the Buffer is not backed by a Java array. * * @param b the Buffer to be queried * @return the Java array containing the Buffer's data, or null if * there is none */ static Object getBaseArray(Buffer b) { return b.hasArray() ? b.array() : null; }
/** * Returns the underlying Java array containing the data of the * given Buffer, or null if the Buffer is not backed by a Java array. * * @param b the Buffer to be queried * @return the Java array containing the Buffer's data, or null if * there is none */ static Object getBaseArray(Buffer b) { return b.hasArray() ? b.array() : null; }
/** * Returns the underlying Java array containing the data of the * given Buffer, or null if the Buffer is not backed by a Java array. * * @param b the Buffer to be queried * @return the Java array containing the Buffer's data, or null if * there is none */ static Object getBaseArray(Buffer b) { return b.hasArray() ? b.array() : null; }
/** * Returns the underlying Java array containing the data of the * given Buffer, or null if the Buffer is not backed by a Java array. * * @param b the Buffer to be queried * @return the Java array containing the Buffer's data, or null if * there is none */ static Object getBaseArray(Buffer b) { return b.hasArray() ? b.array() : null; }
/** * 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 underlying Java array containing the data of the * given Buffer, or null if the Buffer is not backed by a Java array. * * @param b the Buffer to be queried * @return the Java array containing the Buffer's data, or null if * there is none */ static Object getBaseArray(Buffer b) { return b.hasArray() ? b.array() : null; }
/** * Returns the underlying Java array containing the data of the * given Buffer, or null if the Buffer is not backed by a Java array. * * @param b the Buffer to be queried * @return the Java array containing the Buffer's data, or null if * there is none */ static Object getBaseArray(Buffer b) { return b.hasArray() ? b.array() : null; }
public static BufferParameterStrategy bufferParameterStrategy(Buffer buffer, ObjectParameterType.ComponentType componentType) { if (buffer == null || buffer.isDirect()) { return BufferParameterStrategy.direct(componentType); } else if (buffer.hasArray()) { return BufferParameterStrategy.heap(componentType); } else { throw new IllegalArgumentException("cannot marshal non-direct, non-array Buffer"); } }
public static BufferParameterStrategy bufferParameterStrategy(Buffer buffer, ObjectParameterType.ComponentType componentType) { if (buffer == null || buffer.isDirect()) { return BufferParameterStrategy.direct(componentType); } else if (buffer.hasArray()) { return BufferParameterStrategy.heap(componentType); } else { throw new IllegalArgumentException("cannot marshal non-direct, non-array Buffer"); } }