0N/A/*
2362N/A * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#warn This file is preprocessed before being compiled
0N/A
0N/Apackage java.nio;
0N/A
0N/A
0N/Aclass ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
0N/A extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
0N/A{
0N/A
0N/A#if[rw]
0N/A
0N/A protected final ByteBuffer bb;
0N/A protected final int offset;
0N/A
0N/A#end[rw]
0N/A
0N/A ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb) { // package-private
0N/A#if[rw]
0N/A super(-1, 0,
0N/A bb.remaining() >> $LG_BYTES_PER_VALUE$,
0N/A bb.remaining() >> $LG_BYTES_PER_VALUE$);
0N/A this.bb = bb;
0N/A // enforce limit == capacity
0N/A int cap = this.capacity();
0N/A this.limit(cap);
0N/A int pos = this.position();
0N/A assert (pos <= cap);
0N/A offset = pos;
0N/A#else[rw]
0N/A super(bb);
0N/A#end[rw]
0N/A }
0N/A
0N/A ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb,
0N/A int mark, int pos, int lim, int cap,
0N/A int off)
0N/A {
0N/A#if[rw]
0N/A super(mark, pos, lim, cap);
0N/A this.bb = bb;
0N/A offset = off;
0N/A#else[rw]
0N/A super(bb, mark, pos, lim, cap, off);
0N/A#end[rw]
0N/A }
0N/A
0N/A public $Type$Buffer slice() {
0N/A int pos = this.position();
0N/A int lim = this.limit();
0N/A assert (pos <= lim);
0N/A int rem = (pos <= lim ? lim - pos : 0);
0N/A int off = (pos << $LG_BYTES_PER_VALUE$) + offset;
0N/A assert (off >= 0);
0N/A return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, off);
0N/A }
0N/A
0N/A public $Type$Buffer duplicate() {
0N/A return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
0N/A this.markValue(),
0N/A this.position(),
0N/A this.limit(),
0N/A this.capacity(),
0N/A offset);
0N/A }
0N/A
0N/A public $Type$Buffer asReadOnlyBuffer() {
0N/A#if[rw]
0N/A return new ByteBufferAs$Type$BufferR$BO$(bb,
0N/A this.markValue(),
0N/A this.position(),
0N/A this.limit(),
0N/A this.capacity(),
0N/A offset);
0N/A#else[rw]
0N/A return duplicate();
0N/A#end[rw]
0N/A }
0N/A
0N/A#if[rw]
0N/A
0N/A protected int ix(int i) {
0N/A return (i << $LG_BYTES_PER_VALUE$) + offset;
0N/A }
0N/A
0N/A public $type$ get() {
0N/A return Bits.get$Type$$BO$(bb, ix(nextGetIndex()));
0N/A }
0N/A
0N/A public $type$ get(int i) {
0N/A return Bits.get$Type$$BO$(bb, ix(checkIndex(i)));
0N/A }
0N/A
0N/A#end[rw]
0N/A
0N/A public $Type$Buffer put($type$ x) {
0N/A#if[rw]
0N/A Bits.put$Type$$BO$(bb, ix(nextPutIndex()), x);
0N/A return this;
0N/A#else[rw]
0N/A throw new ReadOnlyBufferException();
0N/A#end[rw]
0N/A }
0N/A
0N/A public $Type$Buffer put(int i, $type$ x) {
0N/A#if[rw]
0N/A Bits.put$Type$$BO$(bb, ix(checkIndex(i)), x);
0N/A return this;
0N/A#else[rw]
0N/A throw new ReadOnlyBufferException();
0N/A#end[rw]
0N/A }
0N/A
0N/A public $Type$Buffer compact() {
0N/A#if[rw]
0N/A int pos = position();
0N/A int lim = limit();
0N/A assert (pos <= lim);
0N/A int rem = (pos <= lim ? lim - pos : 0);
0N/A
0N/A ByteBuffer db = bb.duplicate();
0N/A db.limit(ix(lim));
0N/A db.position(ix(0));
0N/A ByteBuffer sb = db.slice();
0N/A sb.position(pos << $LG_BYTES_PER_VALUE$);
0N/A sb.compact();
0N/A position(rem);
0N/A limit(capacity());
721N/A discardMark();
0N/A return this;
0N/A#else[rw]
0N/A throw new ReadOnlyBufferException();
0N/A#end[rw]
0N/A }
0N/A
0N/A public boolean isDirect() {
0N/A return bb.isDirect();
0N/A }
0N/A
0N/A public boolean isReadOnly() {
0N/A return {#if[rw]?false:true};
0N/A }
0N/A
0N/A#if[char]
0N/A
0N/A public String toString(int start, int end) {
0N/A if ((end > limit()) || (start > end))
0N/A throw new IndexOutOfBoundsException();
0N/A try {
0N/A int len = end - start;
0N/A char[] ca = new char[len];
0N/A CharBuffer cb = CharBuffer.wrap(ca);
0N/A CharBuffer db = this.duplicate();
0N/A db.position(start);
0N/A db.limit(end);
0N/A cb.put(db);
0N/A return new String(ca);
0N/A } catch (StringIndexOutOfBoundsException x) {
0N/A throw new IndexOutOfBoundsException();
0N/A }
0N/A }
0N/A
0N/A
0N/A // --- Methods to support CharSequence ---
0N/A
571N/A public CharBuffer subSequence(int start, int end) {
0N/A int pos = position();
0N/A int lim = limit();
0N/A assert (pos <= lim);
0N/A pos = (pos <= lim ? pos : lim);
0N/A int len = lim - pos;
0N/A
0N/A if ((start < 0) || (end > len) || (start > end))
0N/A throw new IndexOutOfBoundsException();
1108N/A return new ByteBufferAsCharBuffer$RW$$BO$(bb,
1108N/A -1,
1108N/A pos + start,
1108N/A pos + end,
1108N/A capacity(),
1108N/A offset);
0N/A }
0N/A
0N/A#end[char]
0N/A
0N/A
0N/A public ByteOrder order() {
0N/A#if[boB]
0N/A return ByteOrder.BIG_ENDIAN;
0N/A#end[boB]
0N/A#if[boL]
0N/A return ByteOrder.LITTLE_ENDIAN;
0N/A#end[boL]
0N/A }
0N/A
0N/A}