Home | History | Annotate | Download | only in nio
      1 /* Licensed to the Apache Software Foundation (ASF) under one or more
      2  * contributor license agreements.  See the NOTICE file distributed with
      3  * this work for additional information regarding copyright ownership.
      4  * The ASF licenses this file to You under the Apache License, Version 2.0
      5  * (the "License"); you may not use this file except in compliance with
      6  * the License.  You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     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, MemoryBlock block) {
     26         super(capacity, block);
     27     }
     28 
     29     @Override
     30     public final CharBuffer asCharBuffer() {
     31         return CharToByteBufferAdapter.asCharBuffer(this);
     32     }
     33 
     34     @Override
     35     public final DoubleBuffer asDoubleBuffer() {
     36         return DoubleToByteBufferAdapter.asDoubleBuffer(this);
     37     }
     38 
     39     @Override
     40     public final FloatBuffer asFloatBuffer() {
     41         return FloatToByteBufferAdapter.asFloatBuffer(this);
     42     }
     43 
     44     @Override
     45     public final IntBuffer asIntBuffer() {
     46         return IntToByteBufferAdapter.asIntBuffer(this);
     47     }
     48 
     49     @Override
     50     public final LongBuffer asLongBuffer() {
     51         return LongToByteBufferAdapter.asLongBuffer(this);
     52     }
     53 
     54     @Override
     55     public final ShortBuffer asShortBuffer() {
     56         return ShortToByteBufferAdapter.asShortBuffer(this);
     57     }
     58 
     59     @Override
     60     public char getChar() {
     61         return (char) getShort();
     62     }
     63 
     64     @Override
     65     public char getChar(int index) {
     66         return (char) getShort(index);
     67     }
     68 
     69     @Override
     70     public ByteBuffer putChar(char value) {
     71         return putShort((short) value);
     72     }
     73 
     74     @Override
     75     public ByteBuffer putChar(int index, char value) {
     76         return putShort(index, (short) value);
     77     }
     78 }
     79