001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package java.nio;
019:
020: /**
021: * Provide factory service of buffer classes.
022: * <p>
023: * Since all buffer impl classes are package private (except DirectByteBuffer),
024: * this factory is the only entrance to access buffer functions from outside of
025: * the impl package.
026: * </p>
027: */
028: final class BufferFactory {
029:
030: /**
031: * Returns a new byte buffer based on the specified byte array.
032: *
033: * @param array
034: * The byte array
035: * @return A new byte buffer based on the specified byte array.
036: */
037: public static ByteBuffer newByteBuffer(byte array[]) {
038: return new ReadWriteHeapByteBuffer(array);
039: }
040:
041: /**
042: * Returns a new array based byte buffer with the specified capacity.
043: *
044: * @param capacity
045: * The capacity of the new buffer
046: * @return A new array based byte buffer with the specified capacity.
047: */
048: public static ByteBuffer newByteBuffer(int capacity) {
049: return new ReadWriteHeapByteBuffer(capacity);
050: }
051:
052: /**
053: * Returns a new char buffer based on the specified char array.
054: *
055: * @param array
056: * The char array
057: * @return A new char buffer based on the specified char array.
058: */
059: public static CharBuffer newCharBuffer(char array[]) {
060: return new ReadWriteCharArrayBuffer(array);
061: }
062:
063: /**
064: * Returns a new readonly char buffer based on the specified char sequence.
065: *
066: * @param chseq
067: * The char sequence
068: * @return A new readonly char buffer based on the specified char sequence.
069: */
070: public static CharBuffer newCharBuffer(CharSequence chseq) {
071: return new CharSequenceAdapter(chseq);
072: }
073:
074: /**
075: * Returns a new array based char buffer with the specified capacity.
076: *
077: * @param capacity
078: * The capacity of the new buffer
079: * @return A new array based char buffer with the specified capacity.
080: */
081: public static CharBuffer newCharBuffer(int capacity) {
082: return new ReadWriteCharArrayBuffer(capacity);
083: }
084:
085: /**
086: * Returns a new direct byte buffer with the specified capacity.
087: *
088: * @param capacity
089: * The capacity of the new buffer
090: * @return A new direct byte buffer with the specified capacity.
091: */
092: public static ByteBuffer newDirectByteBuffer(int capacity) {
093: return new ReadWriteDirectByteBuffer(capacity);
094: }
095:
096: /**
097: * Returns a new double buffer based on the specified double array.
098: *
099: * @param array
100: * The double array
101: * @return A new double buffer based on the specified double array.
102: */
103: public static DoubleBuffer newDoubleBuffer(double array[]) {
104: return new ReadWriteDoubleArrayBuffer(array);
105: }
106:
107: /**
108: * Returns a new array based double buffer with the specified capacity.
109: *
110: * @param capacity
111: * The capacity of the new buffer
112: * @return A new array based double buffer with the specified capacity.
113: */
114: public static DoubleBuffer newDoubleBuffer(int capacity) {
115: return new ReadWriteDoubleArrayBuffer(capacity);
116: }
117:
118: /**
119: * Returns a new float buffer based on the specified float array.
120: *
121: * @param array
122: * The float array
123: * @return A new float buffer based on the specified float array.
124: */
125: public static FloatBuffer newFloatBuffer(float array[]) {
126: return new ReadWriteFloatArrayBuffer(array);
127: }
128:
129: /**
130: * Returns a new array based float buffer with the specified capacity.
131: *
132: * @param capacity
133: * The capacity of the new buffer
134: * @return A new array based float buffer with the specified capacity.
135: */
136: public static FloatBuffer newFloatBuffer(int capacity) {
137: return new ReadWriteFloatArrayBuffer(capacity);
138: }
139:
140: /**
141: * Returns a new array based int buffer with the specified capacity.
142: *
143: * @param capacity
144: * The capacity of the new buffer
145: * @return A new array based int buffer with the specified capacity.
146: */
147: public static IntBuffer newIntBuffer(int capacity) {
148: return new ReadWriteIntArrayBuffer(capacity);
149: }
150:
151: /**
152: * Returns a new int buffer based on the specified int array.
153: *
154: * @param array
155: * The int array
156: * @return A new int buffer based on the specified int array.
157: */
158: public static IntBuffer newIntBuffer(int array[]) {
159: return new ReadWriteIntArrayBuffer(array);
160: }
161:
162: /**
163: * Returns a new array based long buffer with the specified capacity.
164: *
165: * @param capacity
166: * The capacity of the new buffer
167: * @return A new array based long buffer with the specified capacity.
168: */
169: public static LongBuffer newLongBuffer(int capacity) {
170: return new ReadWriteLongArrayBuffer(capacity);
171: }
172:
173: /**
174: * Returns a new long buffer based on the specified long array.
175: *
176: * @param array
177: * The long array
178: * @return A new long buffer based on the specified long array.
179: */
180: public static LongBuffer newLongBuffer(long array[]) {
181: return new ReadWriteLongArrayBuffer(array);
182: }
183:
184: /**
185: * Returns a new array based short buffer with the specified capacity.
186: *
187: * @param capacity
188: * The capacity of the new buffer
189: * @return A new array based short buffer with the specified capacity.
190: */
191: public static ShortBuffer newShortBuffer(int capacity) {
192: return new ReadWriteShortArrayBuffer(capacity);
193: }
194:
195: /**
196: * Returns a new short buffer based on the specified short array.
197: *
198: * @param array
199: * The short array
200: * @return A new short buffer based on the specified short array.
201: */
202: public static ShortBuffer newShortBuffer(short array[]) {
203: return new ReadWriteShortArrayBuffer(array);
204: }
205:
206: }
|