Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
6b777caf
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6b777caf
编写于
3月 13, 2008
作者:
A
alanb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6546113: (bf) CharSequence.slice() on wrapped CharSequence doesn't start at buffer position
Reviewed-by: iris Contributed-by: roman.kennke@aicas.com
上级
77da941b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
13 deletion
+58
-13
src/share/classes/java/nio/StringCharBuffer.java
src/share/classes/java/nio/StringCharBuffer.java
+7
-13
test/java/nio/Buffer/StringCharBufferSliceTest.java
test/java/nio/Buffer/StringCharBufferSliceTest.java
+51
-0
未找到文件。
src/share/classes/java/nio/StringCharBuffer.java
浏览文件 @
6b777caf
...
...
@@ -60,16 +60,9 @@ class StringCharBuffer // package-private
str
=
s
;
}
private
StringCharBuffer
(
CharSequence
s
,
int
mark
,
int
pos
,
int
limit
,
int
cap
)
{
super
(
mark
,
pos
,
limit
,
cap
);
str
=
s
;
}
public
CharBuffer
duplicate
()
{
return
new
StringCharBuffer
(
str
,
markValue
(),
position
(),
limit
(),
capacity
());
position
(),
limit
(),
capacity
()
,
offset
);
}
public
CharBuffer
asReadOnlyBuffer
()
{
...
...
@@ -77,11 +70,11 @@ class StringCharBuffer // package-private
}
public
final
char
get
()
{
return
str
.
charAt
(
nextGetIndex
());
return
str
.
charAt
(
nextGetIndex
()
+
offset
);
}
public
final
char
get
(
int
index
)
{
return
str
.
charAt
(
checkIndex
(
index
));
return
str
.
charAt
(
checkIndex
(
index
)
+
offset
);
}
// ## Override bulk get methods for better performance
...
...
@@ -103,15 +96,16 @@ class StringCharBuffer // package-private
}
final
String
toString
(
int
start
,
int
end
)
{
return
str
.
toString
().
substring
(
start
,
end
);
return
str
.
toString
().
substring
(
start
+
offset
,
end
+
offset
);
}
public
final
CharSequence
subSequence
(
int
start
,
int
end
)
{
try
{
int
pos
=
position
();
return
new
StringCharBuffer
(
str
,
return
new
StringCharBuffer
(
str
,
-
1
,
pos
+
checkIndex
(
start
,
pos
),
pos
+
checkIndex
(
end
,
pos
));
pos
+
checkIndex
(
end
,
pos
),
remaining
(),
offset
);
}
catch
(
IllegalArgumentException
x
)
{
throw
new
IndexOutOfBoundsException
();
}
...
...
test/java/nio/Buffer/StringCharBufferSliceTest.java
浏览文件 @
6b777caf
...
...
@@ -53,6 +53,57 @@ public class StringCharBufferSliceTest {
buff
=
CharBuffer
.
wrap
(
in
,
3
,
in
.
length
());
test
(
buff
,
buff
.
slice
());
System
.
out
.
println
(
">>> StringCharBufferSliceTest-main: testing slice result with get()"
);
buff
.
position
(
4
);
buff
.
limit
(
7
);
CharBuffer
slice
=
buff
.
slice
();
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
if
(
slice
.
get
()
!=
buff
.
get
())
{
throw
new
RuntimeException
(
"Wrong characters in slice result."
);
}
}
System
.
out
.
println
(
">>> StringCharBufferSliceTest-main: testing slice result with get(int)"
);
buff
.
position
(
4
);
buff
.
limit
(
7
);
slice
=
buff
.
slice
();
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
if
(
slice
.
get
(
i
)
!=
buff
.
get
(
4
+
i
))
{
throw
new
RuntimeException
(
"Wrong characters in slice result."
);
}
}
System
.
out
.
println
(
">>> StringCharBufferSliceTest-main: testing toString."
);
buff
.
position
(
4
);
buff
.
limit
(
7
);
slice
=
buff
.
slice
();
if
(!
slice
.
toString
().
equals
(
"tes"
))
{
throw
new
RuntimeException
(
"bad toString() after slice(): "
+
slice
.
toString
());
}
System
.
out
.
println
(
">>> StringCharBufferSliceTest-main: testing subSequence."
);
buff
.
position
(
4
);
buff
.
limit
(
8
);
slice
=
buff
.
slice
();
CharSequence
subSeq
=
slice
.
subSequence
(
1
,
3
);
if
(
subSeq
.
charAt
(
0
)
!=
'e'
||
subSeq
.
charAt
(
1
)
!=
's'
)
{
throw
new
RuntimeException
(
"bad subSequence() after slice(): '"
+
subSeq
+
"'"
);
}
System
.
out
.
println
(
">>> StringCharBufferSliceTest-main: testing duplicate."
);
buff
.
position
(
4
);
buff
.
limit
(
8
);
slice
=
buff
.
slice
();
CharBuffer
dupe
=
slice
.
duplicate
();
if
(
dupe
.
charAt
(
0
)
!=
't'
||
dupe
.
charAt
(
1
)
!=
'e'
||
dupe
.
charAt
(
2
)
!=
's'
||
dupe
.
charAt
(
3
)
!=
't'
)
{
throw
new
RuntimeException
(
"bad duplicate() after slice(): '"
+
dupe
+
"'"
);
}
System
.
out
.
println
(
">>> StringCharBufferSliceTest-main: done!"
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录