Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/nio/StringCharBuffer.java
38829 views
1
/*
2
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package java.nio;
27
28
29
// ## If the sequence is a string, use reflection to share its array
30
31
class StringCharBuffer // package-private
32
extends CharBuffer
33
{
34
CharSequence str;
35
36
StringCharBuffer(CharSequence s, int start, int end) { // package-private
37
super(-1, start, end, s.length());
38
int n = s.length();
39
if ((start < 0) || (start > n) || (end < start) || (end > n))
40
throw new IndexOutOfBoundsException();
41
str = s;
42
}
43
44
public CharBuffer slice() {
45
int pos = this.position();
46
int lim = this.limit();
47
int rem = (pos <= lim ? lim - pos : 0);
48
return new StringCharBuffer(str,
49
-1,
50
0,
51
rem,
52
rem,
53
offset + pos);
54
}
55
56
private StringCharBuffer(CharSequence s,
57
int mark,
58
int pos,
59
int limit,
60
int cap,
61
int offset) {
62
super(mark, pos, limit, cap, null, offset);
63
str = s;
64
}
65
66
public CharBuffer duplicate() {
67
return new StringCharBuffer(str, markValue(),
68
position(), limit(), capacity(), offset);
69
}
70
71
public CharBuffer asReadOnlyBuffer() {
72
return duplicate();
73
}
74
75
public final char get() {
76
return str.charAt(nextGetIndex() + offset);
77
}
78
79
public final char get(int index) {
80
return str.charAt(checkIndex(index) + offset);
81
}
82
83
char getUnchecked(int index) {
84
return str.charAt(index + offset);
85
}
86
87
// ## Override bulk get methods for better performance
88
89
public final CharBuffer put(char c) {
90
throw new ReadOnlyBufferException();
91
}
92
93
public final CharBuffer put(int index, char c) {
94
throw new ReadOnlyBufferException();
95
}
96
97
public final CharBuffer compact() {
98
throw new ReadOnlyBufferException();
99
}
100
101
public final boolean isReadOnly() {
102
return true;
103
}
104
105
final String toString(int start, int end) {
106
return str.toString().substring(start + offset, end + offset);
107
}
108
109
public final CharBuffer subSequence(int start, int end) {
110
try {
111
int pos = position();
112
return new StringCharBuffer(str,
113
-1,
114
pos + checkIndex(start, pos),
115
pos + checkIndex(end, pos),
116
capacity(),
117
offset);
118
} catch (IllegalArgumentException x) {
119
throw new IndexOutOfBoundsException();
120
}
121
}
122
123
public boolean isDirect() {
124
return false;
125
}
126
127
public ByteOrder order() {
128
return ByteOrder.nativeOrder();
129
}
130
131
}
132
133