/** * Creates a byte buffer based on a newly allocated byte array. * * @param capacity * the capacity of the new buffer * @return the created byte buffer. * @throws IllegalArgumentException * if {@code capacity < 0}. */ public static ByteBuffer allocate(int capacity) { if (capacity < 0) { throw new java.lang.IllegalArgumentException(); } return(BufferFactory.newByteBuffer(capacity)); }
/** * Creates a new byte buffer by wrapping the given byte array. * <p /> * The new buffer's position will be {@code start}, limit will be * {@code start + len}, capacity will be the length of the array. * * @param array * the byte array which the new buffer will be based on. * @param start * the start index, must not be negative and not greater than * {@code array.length}. * @param len * the length, must not be negative and not greater than * {@code array.length - start}. * @return the created byte buffer. * @exception IndexOutOfBoundsException * if either {@code start} or {@code len} is invalid. */ public static ByteBuffer wrap(byte[] array, int start, int len) { int length = array.Length; if ((start < 0) || (len < 0) || ((long)start + (long)len > length)) { throw new java.lang.IndexOutOfBoundsException(); } ByteBuffer buf = BufferFactory.newByteBuffer(array); buf.positionJ = start; buf.limitJ = start + len; return(buf); }
/** * Creates a direct byte buffer based on a newly allocated memory block. * * @param capacity * the capacity of the new buffer * @return the created byte buffer. * @throws IllegalArgumentException * if {@code capacity < 0}. * * public static ByteBuffer allocateDirect(int capacity) { * if (capacity < 0) { * throw new java.lang.IllegalArgumentException(); * } * return BufferFactory.newDirectByteBuffer(capacity); * }*/ /** * Creates a new byte buffer by wrapping the given byte array. * <p /> * Calling this method has the same effect as * {@code wrap(array, 0, array.length)}. * * @param array * the byte array which the new buffer will be based on * @return the created byte buffer. */ public static ByteBuffer wrap(byte[] array) { return(BufferFactory.newByteBuffer(array)); }