2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 * Provide factory service of buffer classes.
23 * Since all buffer impl classes are package private (except DirectByteBuffer),
24 * this factory is the only entrance to access buffer functions from outside of
28 final class BufferFactory {
31 * Returns a new byte buffer based on the specified byte array.
35 * @return A new byte buffer based on the specified byte array.
37 public static ByteBuffer newByteBuffer(byte[] array) {
38 return new ReadWriteHeapByteBuffer(array);
42 * Returns a new array based byte buffer with the specified capacity.
45 * The capacity of the new buffer
46 * @return A new array based byte buffer with the specified capacity.
48 public static ByteBuffer newByteBuffer(int capacity) {
49 return new ReadWriteHeapByteBuffer(capacity);
53 * Returns a new char buffer based on the specified char array.
57 * @return A new char buffer based on the specified char array.
59 public static CharBuffer newCharBuffer(char[] array) {
60 return new ReadWriteCharArrayBuffer(array);
64 * Returns a new readonly char buffer based on the specified char sequence.
68 * @return A new readonly char buffer based on the specified char sequence.
70 public static CharBuffer newCharBuffer(CharSequence chseq) {
71 return new CharSequenceAdapter(chseq);
75 * Returns a new array based char buffer with the specified capacity.
78 * The capacity of the new buffer
79 * @return A new array based char buffer with the specified capacity.
81 public static CharBuffer newCharBuffer(int capacity) {
82 return new ReadWriteCharArrayBuffer(capacity);
86 * Returns a new direct byte buffer with the specified capacity.
89 * The capacity of the new buffer
90 * @return A new direct byte buffer with the specified capacity.
92 public static ByteBuffer newDirectByteBuffer(int capacity) {
93 return new ReadWriteDirectByteBuffer(capacity);
97 * Returns a new double buffer based on the specified double array.
101 * @return A new double buffer based on the specified double array.
103 public static DoubleBuffer newDoubleBuffer(double[] array) {
104 return new ReadWriteDoubleArrayBuffer(array);
108 * Returns a new array based double buffer with the specified capacity.
111 * The capacity of the new buffer
112 * @return A new array based double buffer with the specified capacity.
114 public static DoubleBuffer newDoubleBuffer(int capacity) {
115 return new ReadWriteDoubleArrayBuffer(capacity);
119 * Returns a new float buffer based on the specified float array.
123 * @return A new float buffer based on the specified float array.
125 public static FloatBuffer newFloatBuffer(float[] array) {
126 return new ReadWriteFloatArrayBuffer(array);
130 * Returns a new array based float buffer with the specified capacity.
133 * The capacity of the new buffer
134 * @return A new array based float buffer with the specified capacity.
136 public static FloatBuffer newFloatBuffer(int capacity) {
137 return new ReadWriteFloatArrayBuffer(capacity);
141 * Returns a new array based int buffer with the specified capacity.
144 * The capacity of the new buffer
145 * @return A new array based int buffer with the specified capacity.
147 public static IntBuffer newIntBuffer(int capacity) {
148 return new ReadWriteIntArrayBuffer(capacity);
152 * Returns a new int buffer based on the specified int array.
156 * @return A new int buffer based on the specified int array.
158 public static IntBuffer newIntBuffer(int[] array) {
159 return new ReadWriteIntArrayBuffer(array);
163 * Returns a new array based long buffer with the specified capacity.
166 * The capacity of the new buffer
167 * @return A new array based long buffer with the specified capacity.
169 public static LongBuffer newLongBuffer(int capacity) {
170 return new ReadWriteLongArrayBuffer(capacity);
174 * Returns a new long buffer based on the specified long array.
178 * @return A new long buffer based on the specified long array.
180 public static LongBuffer newLongBuffer(long[] array) {
181 return new ReadWriteLongArrayBuffer(array);
185 * Returns a new array based short buffer with the specified capacity.
188 * The capacity of the new buffer
189 * @return A new array based short buffer with the specified capacity.
191 public static ShortBuffer newShortBuffer(int capacity) {
192 return new ReadWriteShortArrayBuffer(capacity);
196 * Returns a new short buffer based on the specified short array.
200 * @return A new short buffer based on the specified short array.
202 public static ShortBuffer newShortBuffer(short[] array) {
203 return new ReadWriteShortArrayBuffer(array);