src/java.base/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 40195 jdk/src/java.base/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template@a13e4945de1d
child 48356 29e165bdf669
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
     2
 * Copyright (c) 2000, 2016, 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
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
    30
import jdk.internal.misc.Unsafe;
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
    31
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
class ByteBufferAs$Type$Buffer$RW$$BO$                  // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
    39
    // Cached unsafe-access object
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
    40
    private static final Unsafe unsafe = Bits.unsafe();
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
    41
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    protected final ByteBuffer bb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb) {   // package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        super(-1, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
              bb.remaining() >> $LG_BYTES_PER_VALUE$,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
              bb.remaining() >> $LG_BYTES_PER_VALUE$);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        this.bb = bb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        // enforce limit == capacity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        int cap = this.capacity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        this.limit(cap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        int pos = this.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        assert (pos <= cap);
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    57
        address = bb.address;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        super(bb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                                     int mark, int pos, int lim, int cap,
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    65
                                     long addr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        super(mark, pos, lim, cap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        this.bb = bb;
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    70
        address = addr;
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    71
        assert address >= bb.address;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
#else[rw]
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    73
        super(bb, mark, pos, lim, cap, addr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public $Type$Buffer slice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        int pos = this.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        int lim = this.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        int rem = (pos <= lim ? lim - pos : 0);
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    82
        long addr = byteOffset(pos);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    83
        return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, addr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public $Type$Buffer duplicate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                                    this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                                    this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                                    this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                                    this.capacity(),
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
    92
                                                    address);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public $Type$Buffer asReadOnlyBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return new ByteBufferAs$Type$BufferR$BO$(bb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                                                 this.markValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                                 this.position(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                                 this.limit(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                                 this.capacity(),
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
   102
                                                 address);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
   110
    private int ix(int i) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
   111
        int off = (int) (address - bb.address);
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
   112
        return (i << $LG_BYTES_PER_VALUE$) + off;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
   115
    protected long byteOffset(long i) {
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
   116
        return (i << $LG_BYTES_PER_VALUE$) + address;
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   117
    }
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   118
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public $type$ get() {
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   120
        $memtype$ x = unsafe.get$Memtype$Unaligned(bb.hb, byteOffset(nextGetIndex()),
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   121
            {#if[boB]?true:false});
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   122
        return $fromBits$(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public $type$ get(int i) {
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   126
        $memtype$ x = unsafe.get$Memtype$Unaligned(bb.hb, byteOffset(checkIndex(i)),
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   127
            {#if[boB]?true:false});
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   128
        return $fromBits$(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   131
#if[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   132
   $type$ getUnchecked(int i) {
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   133
        $memtype$ x = unsafe.get$Memtype$Unaligned(bb.hb, byteOffset(i),
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   134
            {#if[boB]?true:false});
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   135
        return $fromBits$(x);
17922
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   136
    }
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   137
#end[streamableType]
d56eec572de5 8014854: (bf) CharBuffer.chars too slow with default implementation
alanb
parents: 5506
diff changeset
   138
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public $Type$Buffer put($type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
#if[rw]
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   143
        $memtype$ y = $toBits$(x);
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   144
        unsafe.put$Memtype$Unaligned(bb.hb, byteOffset(nextPutIndex()), y,
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   145
            {#if[boB]?true:false});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public $Type$Buffer put(int i, $type$ x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
#if[rw]
40180
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   154
        $memtype$ y = $toBits$(x);
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   155
        unsafe.put$Memtype$Unaligned(bb.hb, byteOffset(checkIndex(i)), y,
e53a90882a23 8151163: All Buffer implementations should leverage Unsafe unaligned accessors
psandoz
parents: 25859
diff changeset
   156
            {#if[boB]?true:false});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
#else[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        throw new ReadOnlyBufferException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
#end[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public $Type$Buffer compact() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
#if[rw]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        ByteBuffer db = bb.duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        db.limit(ix(lim));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        db.position(ix(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        ByteBuffer sb = db.slice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        sb.position(pos << $LG_BYTES_PER_VALUE$);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        sb.compact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        position(rem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        limit(capacity());
1634
3871c2046043 6593946: (bf) X-Buffer.compact() does not discard mark as specified
alanb
parents: 1247
diff changeset
   178
        discardMark();
2
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 boolean isDirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return bb.isDirect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public boolean isReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return {#if[rw]?false:true};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
#if[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public String toString(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if ((end > limit()) || (start > end))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            int len = end - start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            char[] ca = new char[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            CharBuffer cb = CharBuffer.wrap(ca);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            CharBuffer db = this.duplicate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            db.position(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            db.limit(end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            cb.put(db);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            return new String(ca);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        } catch (StringIndexOutOfBoundsException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    // --- Methods to support CharSequence ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
1224
8c1bc7c5dd00 6733145: (bf) CharBuffer.subSequence can be updated to take advantage of covariant returns
martin
parents: 2
diff changeset
   215
    public CharBuffer subSequence(int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        int pos = position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        int lim = limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        pos = (pos <= lim ? pos : lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        int len = lim - pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if ((start < 0) || (end > len) || (start > end))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            throw new IndexOutOfBoundsException();
2593
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   224
        return new ByteBufferAsCharBuffer$RW$$BO$(bb,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   225
                                                  -1,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   226
                                                  pos + start,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   227
                                                  pos + end,
76032557be03 6795561: (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
alanb
parents: 1634
diff changeset
   228
                                                  capacity(),
40195
a13e4945de1d 8162458: Buffer view implementations use incorrect offset for Unsafe access
psandoz
parents: 40180
diff changeset
   229
                                                  address);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
#end[char]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public ByteOrder order() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
#if[boB]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return ByteOrder.BIG_ENDIAN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
#end[boB]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
#if[boL]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        return ByteOrder.LITTLE_ENDIAN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
#end[boL]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
}