jdk/src/share/classes/java/nio/Heap-X-Buffer.java.template
author alanb
Fri, 31 May 2013 12:17:30 +0100
changeset 17922 d56eec572de5
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8014854: (bf) CharBuffer.chars too slow with default implementation Reviewed-by: erikj, briangoetz, henryjen, psandoz, mduigou
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
     2
 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#warn This file is preprocessed before being compiled
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
package java.nio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A read/write Heap$Type$Buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * A read-only Heap$Type$Buffer.  This class extends the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * read/write class, overriding the mutation methods to throw a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * ReadOnlyBufferException} and overriding the view-buffer methods to return an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * instance of this class rather than of the superclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
class Heap$Type$Buffer$RW$
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    extends {#if[ro]?Heap}$Type$Buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    // For speed these fields are actually declared in X-Buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    // these declarations are here as documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    protected final $type$[] hb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    protected final int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    Heap$Type$Buffer$RW$(int cap, int lim) {            // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        super(-1, 0, lim, cap, new $type$[cap], 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        hb = new $type$[cap];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        super(cap, lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        this.isReadOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    Heap$Type$Buffer$RW$($type$[] buf, int off, int len) { // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        super(-1, off, off + len, buf.length, buf, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        hb = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        super(buf, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        this.isReadOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    protected Heap$Type$Buffer$RW$($type$[] buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                   int mark, int pos, int lim, int cap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                   int off)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        super(mark, pos, lim, cap, buf, off);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        hb = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        offset = off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        super(buf, mark, pos, lim, cap, off);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        this.isReadOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public $Type$Buffer slice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return new Heap$Type$Buffer$RW$(hb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                        -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                        0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                        this.remaining(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                                        this.remaining(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                                        this.position() + offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public $Type$Buffer duplicate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return new Heap$Type$Buffer$RW$(hb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                        this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                        this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                        this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                        this.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                        offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public $Type$Buffer asReadOnlyBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        return new Heap$Type$BufferR(hb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                     this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                     this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                     this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                     this.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                     offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    protected int ix(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return i + offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public $type$ get() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return hb[ix(nextGetIndex())];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public $type$ get(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        return hb[ix(checkIndex(i))];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   142
#if[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   143
    $type$ getUnchecked(int i) {
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   144
	return hb[ix(i)];
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   145
    }
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   146
#end[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   147
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public $Type$Buffer get($type$[] dst, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        checkBounds(offset, length, dst.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (length > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            throw new BufferUnderflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        System.arraycopy(hb, ix(position()), dst, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        position(position() + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public boolean isDirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public boolean isReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return {#if[rw]?false:true};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public $Type$Buffer put($type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        hb[ix(nextPutIndex())] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public $Type$Buffer put(int i, $type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        hb[ix(checkIndex(i))] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public $Type$Buffer put($type$[] src, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        checkBounds(offset, length, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (length > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        System.arraycopy(src, offset, hb, ix(position()), length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        position(position() + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public $Type$Buffer put($Type$Buffer src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if (src instanceof Heap$Type$Buffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            if (src == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            Heap$Type$Buffer sb = (Heap$Type$Buffer)src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            int n = sb.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            if (n > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            System.arraycopy(sb.hb, sb.ix(sb.position()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                             hb, ix(position()), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            sb.position(sb.position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            position(position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        } else if (src.isDirect()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            int n = src.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            if (n > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            src.get(hb, ix(position()), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            position(position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            super.put(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public $Type$Buffer compact() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        position(remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        limit(capacity());
1634
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 1247
diff changeset
   231
        discardMark();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    byte _get(int i) {                          // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return hb[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    void _put(int i, byte b) {                  // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        hb[i] = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    // char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public char getChar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return Bits.getChar(this, ix(nextGetIndex(2)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public char getChar(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return Bits.getChar(this, ix(checkIndex(i, 2)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public $Type$Buffer putChar(char x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        Bits.putChar(this, ix(nextPutIndex(2)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public $Type$Buffer putChar(int i, char x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        Bits.putChar(this, ix(checkIndex(i, 2)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public CharBuffer asCharBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        int size = this.remaining() >> 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                ? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                                                               off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                : (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                                               off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    // short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public short getShort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        return Bits.getShort(this, ix(nextGetIndex(2)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public short getShort(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        return Bits.getShort(this, ix(checkIndex(i, 2)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public $Type$Buffer putShort(short x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        Bits.putShort(this, ix(nextPutIndex(2)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public $Type$Buffer putShort(int i, short x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        Bits.putShort(this, ix(checkIndex(i, 2)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public ShortBuffer asShortBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        int size = this.remaining() >> 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                ? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                                                                 off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                : (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                                                                 off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    // int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    public int getInt() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return Bits.getInt(this, ix(nextGetIndex(4)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public int getInt(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return Bits.getInt(this, ix(checkIndex(i, 4)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public $Type$Buffer putInt(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        Bits.putInt(this, ix(nextPutIndex(4)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    public $Type$Buffer putInt(int i, int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        Bits.putInt(this, ix(checkIndex(i, 4)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    public IntBuffer asIntBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        int size = this.remaining() >> 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                ? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                                                             -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                                                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                                                             off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                : (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                                                             -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                                                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                                                             off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    // long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    public long getLong() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        return Bits.getLong(this, ix(nextGetIndex(8)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    public long getLong(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        return Bits.getLong(this, ix(checkIndex(i, 8)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public $Type$Buffer putLong(long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        Bits.putLong(this, ix(nextPutIndex(8)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    public $Type$Buffer putLong(int i, long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        Bits.putLong(this, ix(checkIndex(i, 8)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public LongBuffer asLongBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        int size = this.remaining() >> 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                ? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                                                               off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                : (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                                                               off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    // float
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public float getFloat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        return Bits.getFloat(this, ix(nextGetIndex(4)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public float getFloat(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        return Bits.getFloat(this, ix(checkIndex(i, 4)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    public $Type$Buffer putFloat(float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        Bits.putFloat(this, ix(nextPutIndex(4)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    public $Type$Buffer putFloat(int i, float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        Bits.putFloat(this, ix(checkIndex(i, 4)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public FloatBuffer asFloatBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        int size = this.remaining() >> 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                ? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                                                                 off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                : (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                                                                 off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    // double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public double getDouble() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        return Bits.getDouble(this, ix(nextGetIndex(8)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    public double getDouble(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        return Bits.getDouble(this, ix(checkIndex(i, 8)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public $Type$Buffer putDouble(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        Bits.putDouble(this, ix(nextPutIndex(8)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    public $Type$Buffer putDouble(int i, double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        Bits.putDouble(this, ix(checkIndex(i, 8)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public DoubleBuffer asDoubleBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        int size = this.remaining() >> 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                ? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                                                                   -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                                                                   0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                                                                   off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                : (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                                                                   -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                                                                   0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                                                                   off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    String toString(int start, int end) {               // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            return new String(hb, start + offset, end - start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        } catch (StringIndexOutOfBoundsException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    // --- Methods to support CharSequence ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
1224
8c1bc7c5dd00 6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents: 2
diff changeset
   576
    public CharBuffer subSequence(int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        if ((start < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            || (end > length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            || (start > end))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            throw new IndexOutOfBoundsException();
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   581
        int pos = position();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        return new HeapCharBuffer$RW$(hb,
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   583
                                      -1,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   584
                                      pos + start,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   585
                                      pos + end,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   586
                                      capacity(),
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   587
                                      offset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
#if[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    public ByteOrder order() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        return ByteOrder.nativeOrder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
#end[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
}