|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * You may obtain a copy of the License at |
| 5 | + * |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + * |
| 14 | + */ |
| 15 | +using System; |
| 16 | +using java = biz.ritter.javapi; |
| 17 | + |
| 18 | +namespace biz.ritter.javapi.nio |
| 19 | +{ |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// Provide factory service of buffer classes. |
| 23 | + /// <p> |
| 24 | + /// Since all buffer impl classes are package private (except DirectByteBuffer), |
| 25 | + /// this factory is the only entrance to access buffer functions from outside of |
| 26 | + /// the impl package. |
| 27 | + /// </p> |
| 28 | + /// </summary> |
| 29 | + /// <remarks>Class is ported from Apache Harmony project.</remarks> |
| 30 | + sealed class BufferFactory |
| 31 | + { |
| 32 | + |
| 33 | + /// <summary> |
| 34 | + /// Returns a new byte buffer based on the specified byte array. |
| 35 | + /// |
| 36 | + /// @param array |
| 37 | + /// The byte array |
| 38 | + /// @return A new byte buffer based on the specified byte array. |
| 39 | + /// </summary> |
| 40 | + public static ByteBuffer newByteBuffer(byte [] array) { |
| 41 | + return new ReadWriteHeapByteBuffer(array); |
| 42 | + } |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Returns a new array based byte buffer with the specified capacity. |
| 46 | + /// |
| 47 | + /// @param capacity |
| 48 | + /// The capacity of the new buffer |
| 49 | + /// @return A new array based byte buffer with the specified capacity. |
| 50 | + /// </summary> |
| 51 | + public static ByteBuffer newByteBuffer(int capacity) { |
| 52 | + return new ReadWriteHeapByteBuffer(capacity); |
| 53 | + } |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Returns a new char buffer based on the specified char array. |
| 57 | + /// |
| 58 | + /// @param array |
| 59 | + /// The char array |
| 60 | + /// @return A new char buffer based on the specified char array. |
| 61 | + /// </summary> |
| 62 | + public static CharBuffer newCharBuffer(char [] array) { |
| 63 | + return new ReadWriteCharArrayBuffer(array); |
| 64 | + } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Returns a new readonly char buffer based on the specified char sequence. |
| 68 | + /// |
| 69 | + /// @param chseq |
| 70 | + /// The char sequence |
| 71 | + /// @return A new readonly char buffer based on the specified char sequence. |
| 72 | + /// </summary> |
| 73 | + public static CharBuffer newCharBuffer(java.lang.CharSequence chseq) |
| 74 | + { |
| 75 | + return new CharSequenceAdapter(chseq); |
| 76 | + } |
| 77 | + |
| 78 | + /// <summary> |
| 79 | + /// Returns a new array based char buffer with the specified capacity. |
| 80 | + /// |
| 81 | + /// @param capacity |
| 82 | + /// The capacity of the new buffer |
| 83 | + /// @return A new array based char buffer with the specified capacity. |
| 84 | + /// </summary> |
| 85 | + public static CharBuffer newCharBuffer(int capacity) { |
| 86 | + return new ReadWriteCharArrayBuffer(capacity); |
| 87 | + } |
| 88 | + |
| 89 | +/* |
| 90 | + /// <summary> |
| 91 | + /// Returns a new direct byte buffer with the specified capacity. |
| 92 | + /// |
| 93 | + /// @param capacity |
| 94 | + /// The capacity of the new buffer |
| 95 | + /// @return A new direct byte buffer with the specified capacity. |
| 96 | + /// </summary> |
| 97 | + public static ByteBuffer newDirectByteBuffer(int capacity) { |
| 98 | + return new ReadWriteDirectByteBuffer(capacity); |
| 99 | + } |
| 100 | +
|
| 101 | + /// <summary> |
| 102 | + /// Returns a new double buffer based on the specified double array. |
| 103 | + /// |
| 104 | + /// @param array |
| 105 | + /// The double array |
| 106 | + /// @return A new double buffer based on the specified double array. |
| 107 | + /// </summary> |
| 108 | + public static DoubleBuffer newDoubleBuffer(double array[]) { |
| 109 | + return new ReadWriteDoubleArrayBuffer(array); |
| 110 | + } |
| 111 | +
|
| 112 | + /// <summary> |
| 113 | + /// Returns a new array based double buffer with the specified capacity. |
| 114 | + /// |
| 115 | + /// @param capacity |
| 116 | + /// The capacity of the new buffer |
| 117 | + /// @return A new array based double buffer with the specified capacity. |
| 118 | + /// </summary> |
| 119 | + public static DoubleBuffer newDoubleBuffer(int capacity) { |
| 120 | + return new ReadWriteDoubleArrayBuffer(capacity); |
| 121 | + } |
| 122 | +
|
| 123 | + /// <summary> |
| 124 | + /// Returns a new float buffer based on the specified float array. |
| 125 | + /// |
| 126 | + /// @param array |
| 127 | + /// The float array |
| 128 | + /// @return A new float buffer based on the specified float array. |
| 129 | + /// </summary> |
| 130 | + public static FloatBuffer newFloatBuffer(float array[]) { |
| 131 | + return new ReadWriteFloatArrayBuffer(array); |
| 132 | + } |
| 133 | +
|
| 134 | + /// <summary> |
| 135 | + /// Returns a new array based float buffer with the specified capacity. |
| 136 | + /// |
| 137 | + /// @param capacity |
| 138 | + /// The capacity of the new buffer |
| 139 | + /// @return A new array based float buffer with the specified capacity. |
| 140 | + /// </summary> |
| 141 | + public static FloatBuffer newFloatBuffer(int capacity) { |
| 142 | + return new ReadWriteFloatArrayBuffer(capacity); |
| 143 | + } |
| 144 | +
|
| 145 | + /// <summary> |
| 146 | + /// Returns a new array based int buffer with the specified capacity. |
| 147 | + /// |
| 148 | + /// @param capacity |
| 149 | + /// The capacity of the new buffer |
| 150 | + /// @return A new array based int buffer with the specified capacity. |
| 151 | + /// </summary> |
| 152 | + public static IntBuffer newIntBuffer(int capacity) { |
| 153 | + return new ReadWriteIntArrayBuffer(capacity); |
| 154 | + } |
| 155 | +
|
| 156 | + /// <summary> |
| 157 | + /// Returns a new int buffer based on the specified int array. |
| 158 | + /// |
| 159 | + /// @param array |
| 160 | + /// The int array |
| 161 | + /// @return A new int buffer based on the specified int array. |
| 162 | + /// </summary> |
| 163 | + public static IntBuffer newIntBuffer(int array[]) { |
| 164 | + return new ReadWriteIntArrayBuffer(array); |
| 165 | + } |
| 166 | +
|
| 167 | + /// <summary> |
| 168 | + /// Returns a new array based long buffer with the specified capacity. |
| 169 | + /// |
| 170 | + /// @param capacity |
| 171 | + /// The capacity of the new buffer |
| 172 | + /// @return A new array based long buffer with the specified capacity. |
| 173 | + /// </summary> |
| 174 | + public static LongBuffer newLongBuffer(int capacity) { |
| 175 | + return new ReadWriteLongArrayBuffer(capacity); |
| 176 | + } |
| 177 | +
|
| 178 | + /// <summary> |
| 179 | + /// Returns a new long buffer based on the specified long array. |
| 180 | + /// |
| 181 | + /// @param array |
| 182 | + /// The long array |
| 183 | + /// @return A new long buffer based on the specified long array. |
| 184 | + /// </summary> |
| 185 | + public static LongBuffer newLongBuffer(long array[]) { |
| 186 | + return new ReadWriteLongArrayBuffer(array); |
| 187 | + } |
| 188 | +
|
| 189 | + /// <summary> |
| 190 | + /// Returns a new array based short buffer with the specified capacity. |
| 191 | + /// |
| 192 | + /// @param capacity |
| 193 | + /// The capacity of the new buffer |
| 194 | + /// @return A new array based short buffer with the specified capacity. |
| 195 | + /// </summary> |
| 196 | + public static ShortBuffer newShortBuffer(int capacity) { |
| 197 | + return new ReadWriteShortArrayBuffer(capacity); |
| 198 | + } |
| 199 | +
|
| 200 | + /// <summary> |
| 201 | + /// Returns a new short buffer based on the specified short array. |
| 202 | + /// |
| 203 | + /// @param array |
| 204 | + /// The short array |
| 205 | + /// @return A new short buffer based on the specified short array. |
| 206 | + /// </summary> |
| 207 | + public static ShortBuffer newShortBuffer(short array[]) { |
| 208 | + return new ReadWriteShortArrayBuffer(array); |
| 209 | + } |
| 210 | +*/ |
| 211 | + } |
| 212 | +} |
0 commit comments