jdk/src/share/classes/java/nio/Heap-X-Buffer.java
author xdono
Thu, 02 Oct 2008 19:58:32 -0700
changeset 1247 b4c26443dee5
parent 1224 8c1bc7c5dd00
child 1634 3871c2046043
permissions -rw-r--r--
6754988: Update copyright year Summary: Update for files that have been modified starting July 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1247
b4c26443dee5 6754988: Update copyright year
xdono
parents: 1224
diff changeset
     2
 * Copyright 2000-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public $Type$Buffer get($type$[] dst, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        checkBounds(offset, length, dst.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (length > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            throw new BufferUnderflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        System.arraycopy(hb, ix(position()), dst, offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        position(position() + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public boolean isDirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public boolean isReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return {#if[rw]?false:true};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public $Type$Buffer put($type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        hb[ix(nextPutIndex())] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public $Type$Buffer put(int i, $type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        hb[ix(checkIndex(i))] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public $Type$Buffer put($type$[] src, int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        checkBounds(offset, length, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (length > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        System.arraycopy(src, offset, hb, ix(position()), length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        position(position() + length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public $Type$Buffer put($Type$Buffer src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (src instanceof Heap$Type$Buffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            if (src == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            Heap$Type$Buffer sb = (Heap$Type$Buffer)src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            int n = sb.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            if (n > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            System.arraycopy(sb.hb, sb.ix(sb.position()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                             hb, ix(position()), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            sb.position(sb.position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            position(position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        } else if (src.isDirect()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            int n = src.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            if (n > remaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                throw new BufferOverflowException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            src.get(hb, ix(position()), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            position(position() + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            super.put(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public $Type$Buffer compact() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        position(remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        limit(capacity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
#if[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    byte _get(int i) {                          // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return hb[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    void _put(int i, byte b) {                  // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        hb[i] = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    // char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public char getChar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return Bits.getChar(this, ix(nextGetIndex(2)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public char getChar(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return Bits.getChar(this, ix(checkIndex(i, 2)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public $Type$Buffer putChar(char x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        Bits.putChar(this, ix(nextPutIndex(2)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public $Type$Buffer putChar(int i, char x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        Bits.putChar(this, ix(checkIndex(i, 2)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public CharBuffer asCharBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        int size = this.remaining() >> 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                ? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                                                               off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                : (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                                                               off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    // short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public short getShort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return Bits.getShort(this, ix(nextGetIndex(2)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public short getShort(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return Bits.getShort(this, ix(checkIndex(i, 2)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public $Type$Buffer putShort(short x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        Bits.putShort(this, ix(nextPutIndex(2)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public $Type$Buffer putShort(int i, short x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        Bits.putShort(this, ix(checkIndex(i, 2)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public ShortBuffer asShortBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        int size = this.remaining() >> 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                ? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                                                                 off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                : (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                                                                 off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    // int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public int getInt() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        return Bits.getInt(this, ix(nextGetIndex(4)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public int getInt(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return Bits.getInt(this, ix(checkIndex(i, 4)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    public $Type$Buffer putInt(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        Bits.putInt(this, ix(nextPutIndex(4)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public $Type$Buffer putInt(int i, int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        Bits.putInt(this, ix(checkIndex(i, 4)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public IntBuffer asIntBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        int size = this.remaining() >> 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                ? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                                                             -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                                                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                                                             off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                : (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                                                             -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                                                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                                                             size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                                                             off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    // long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public long getLong() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        return Bits.getLong(this, ix(nextGetIndex(8)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public long getLong(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return Bits.getLong(this, ix(checkIndex(i, 8)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    public $Type$Buffer putLong(long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        Bits.putLong(this, ix(nextPutIndex(8)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public $Type$Buffer putLong(int i, long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        Bits.putLong(this, ix(checkIndex(i, 8)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public LongBuffer asLongBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        int size = this.remaining() >> 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                ? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                                                               off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                : (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                                                               -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                                                               0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                                                               size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                                                               off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    // float
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    public float getFloat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        return Bits.getFloat(this, ix(nextGetIndex(4)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public float getFloat(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        return Bits.getFloat(this, ix(checkIndex(i, 4)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    public $Type$Buffer putFloat(float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        Bits.putFloat(this, ix(nextPutIndex(4)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    public $Type$Buffer putFloat(int i, float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        Bits.putFloat(this, ix(checkIndex(i, 4)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    public FloatBuffer asFloatBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        int size = this.remaining() >> 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                ? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                                                                 off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                : (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                                                                 -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                                                                 off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    // double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    public double getDouble() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        return Bits.getDouble(this, ix(nextGetIndex(8)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    public double getDouble(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        return Bits.getDouble(this, ix(checkIndex(i, 8)), bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    public $Type$Buffer putDouble(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        Bits.putDouble(this, ix(nextPutIndex(8)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    public $Type$Buffer putDouble(int i, double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        Bits.putDouble(this, ix(checkIndex(i, 8)), x, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    public DoubleBuffer asDoubleBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        int size = this.remaining() >> 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        int off = offset + position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        return (bigEndian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                ? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                                                                   -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                                                                   0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                                                                   off))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                : (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                                                                   -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                                                                   0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                                                                   size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                                                                   off)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
#end[byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    String toString(int start, int end) {               // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            return new String(hb, start + offset, end - start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        } catch (StringIndexOutOfBoundsException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    // --- Methods to support CharSequence ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
1224
8c1bc7c5dd00 6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents: 2
diff changeset
   569
    public CharBuffer subSequence(int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        if ((start < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            || (end > length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            || (start > end))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        int len = end - start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        return new HeapCharBuffer$RW$(hb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                      -1, 0, len, len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                                      offset + position() + start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
#if[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    public ByteOrder order() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        return ByteOrder.nativeOrder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
#end[!byte]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
}