Esempio n. 1
0
 /*
  * Creates a char buffer based on a newly allocated char array.
  *
  * @param capacity
  *            the capacity of the new buffer.
  * @return the created char buffer.
  * @throws IllegalArgumentException
  *             if {@code capacity} is less than zero.
  */
 public static CharBuffer allocate(int capacity)
 {
     if (capacity < 0)
     {
         throw new java.lang.IllegalArgumentException();
     }
     return(BufferFactory.newCharBuffer(capacity));
 }
Esempio n. 2
0
        /*
         * Creates a new char buffer by wrapping the given char 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 char 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 char buffer.
         * @exception IndexOutOfBoundsException
         *                if either {@code start} or {@code len} is invalid.
         */
        public static CharBuffer wrap(char[] array, int start, int len)
        {
            int length = array.Length;

            if ((start < 0) || (len < 0) || (long)start + (long)len > length)
            {
                throw new java.lang.IndexOutOfBoundsException();
            }

            CharBuffer buf = BufferFactory.newCharBuffer(array);

            buf.positionJ = start;
            buf.limitJ    = start + len;

            return(buf);
        }
Esempio n. 3
0
        /*
         * Creates a new char buffer by wrapping the given char sequence.
         * <p/>
         * The new buffer's position will be {@code start}, limit will be
         * {@code end}, capacity will be the length of the char sequence. The new
         * buffer is read-only.
         *
         * @param chseq
         *            the char sequence which the new buffer will be based on.
         * @param start
         *            the start index, must not be negative and not greater than
         *            {@code chseq.length()}.
         * @param end
         *            the end index, must be no less than {@code start} and no
         *            greater than {@code chseq.length()}.
         * @return the created char buffer.
         * @exception IndexOutOfBoundsException
         *                if either {@code start} or {@code end} is invalid.
         */
        public static CharBuffer wrap(java.lang.CharSequence chseq, int start, int end)
        {
            if (chseq == null)
            {
                throw new java.lang.NullPointerException();
            }
            if (start < 0 || end < start || end > chseq.length())
            {
                throw new java.lang.IndexOutOfBoundsException();
            }

            CharBuffer result = BufferFactory.newCharBuffer(chseq);

            result.positionJ = start;
            result.limitJ    = end;
            return(result);
        }
Esempio n. 4
0
 /*
  * Creates a new char buffer by wrapping the given char sequence.
  * <p/>
  * Calling this method has the same effect as
  * {@code wrap(chseq, 0, chseq.length())}.
  *
  * @param chseq
  *            the char sequence which the new buffer will be based on.
  * @return the created char buffer.
  */
 public static CharBuffer wrap(java.lang.CharSequence chseq)
 {
     return(BufferFactory.newCharBuffer(chseq));
 }
Esempio n. 5
0
        /**
         * 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));
        }