OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / main / java / java / nio / BufferFactory.java
1 /*
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 package java.nio;
19
20 /**
21  * Provide factory service of buffer classes.
22  * <p>
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
25  * the impl package.
26  * </p>
27  */
28 final class BufferFactory {
29
30     /**
31      * Returns a new byte buffer based on the specified byte array.
32      *
33      * @param array
34      *            The byte array
35      * @return A new byte buffer based on the specified byte array.
36      */
37     public static ByteBuffer newByteBuffer(byte[] array) {
38         return new ReadWriteHeapByteBuffer(array);
39     }
40
41     /**
42      * Returns a new array based byte buffer with the specified capacity.
43      *
44      * @param capacity
45      *            The capacity of the new buffer
46      * @return A new array based byte buffer with the specified capacity.
47      */
48     public static ByteBuffer newByteBuffer(int capacity) {
49         return new ReadWriteHeapByteBuffer(capacity);
50     }
51
52     /**
53      * Returns a new char buffer based on the specified char array.
54      *
55      * @param array
56      *            The char array
57      * @return A new char buffer based on the specified char array.
58      */
59     public static CharBuffer newCharBuffer(char[] array) {
60         return new ReadWriteCharArrayBuffer(array);
61     }
62
63     /**
64      * Returns a new readonly char buffer based on the specified char sequence.
65      *
66      * @param chseq
67      *            The char sequence
68      * @return A new readonly char buffer based on the specified char sequence.
69      */
70     public static CharBuffer newCharBuffer(CharSequence chseq) {
71         return new CharSequenceAdapter(chseq);
72     }
73
74     /**
75      * Returns a new array based char buffer with the specified capacity.
76      *
77      * @param capacity
78      *            The capacity of the new buffer
79      * @return A new array based char buffer with the specified capacity.
80      */
81     public static CharBuffer newCharBuffer(int capacity) {
82         return new ReadWriteCharArrayBuffer(capacity);
83     }
84
85     /**
86      * Returns a new direct byte buffer with the specified capacity.
87      *
88      * @param capacity
89      *            The capacity of the new buffer
90      * @return A new direct byte buffer with the specified capacity.
91      */
92     public static ByteBuffer newDirectByteBuffer(int capacity) {
93         return new ReadWriteDirectByteBuffer(capacity);
94     }
95
96     /**
97      * Returns a new double buffer based on the specified double array.
98      *
99      * @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 }