01: /* Licensed to the Apache Software Foundation (ASF) under one or more
02: * contributor license agreements. See the NOTICE file distributed with
03: * this work for additional information regarding copyright ownership.
04: * The ASF licenses this file to You under the Apache License, Version 2.0
05: * (the "License"); you may not use this file except in compliance with
06: * the License. You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package java.nio;
18:
19: /**
20: * Serves as the root of other byte buffer impl classes, implements common
21: * methods that can be shared by child classes.
22: */
23: abstract class BaseByteBuffer extends ByteBuffer {
24:
25: protected BaseByteBuffer(int capacity) {
26: super (capacity);
27: }
28:
29: @Override
30: public final CharBuffer asCharBuffer() {
31: return CharToByteBufferAdapter.wrap(this );
32: }
33:
34: @Override
35: public final DoubleBuffer asDoubleBuffer() {
36: return DoubleToByteBufferAdapter.wrap(this );
37: }
38:
39: @Override
40: public final FloatBuffer asFloatBuffer() {
41: return FloatToByteBufferAdapter.wrap(this );
42: }
43:
44: @Override
45: public final IntBuffer asIntBuffer() {
46: return IntToByteBufferAdapter.wrap(this );
47: }
48:
49: @Override
50: public final LongBuffer asLongBuffer() {
51: return LongToByteBufferAdapter.wrap(this );
52: }
53:
54: @Override
55: public final ShortBuffer asShortBuffer() {
56: return ShortToByteBufferAdapter.wrap(this );
57: }
58:
59: @Override
60: public final char getChar() {
61: return (char) getShort();
62: }
63:
64: @Override
65: public final char getChar(int index) {
66: return (char) getShort(index);
67: }
68:
69: @Override
70: public final ByteBuffer putChar(char value) {
71: return putShort((short) value);
72: }
73:
74: @Override
75: public final ByteBuffer putChar(int index, char value) {
76: return putShort(index, (short) value);
77: }
78: }
|