Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
46bfc4ba
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
3
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
46bfc4ba
编写于
11月 22, 2013
作者:
C
coffeys
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
447e7b17
7d23245d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
84 addition
and
79 deletion
+84
-79
src/share/classes/java/lang/String.java
src/share/classes/java/lang/String.java
+32
-31
test/java/nio/channels/FileChannel/Size.java
test/java/nio/channels/FileChannel/Size.java
+35
-45
test/java/nio/file/Files/Misc.java
test/java/nio/file/Files/Misc.java
+17
-3
未找到文件。
src/share/classes/java/lang/String.java
浏览文件 @
46bfc4ba
...
...
@@ -123,7 +123,7 @@ public final class String
* Class String is special cased within the Serialization Stream Protocol.
*
* A String instance is written into an ObjectOutputStream according to
* <a href="{@doc
root}
../platform/serialization/spec/output.html">
* <a href="{@doc
Root}/
../platform/serialization/spec/output.html">
* Object Serialization Specification, Section 6.2, "Stream Elements"</a>
*/
private
static
final
ObjectStreamField
[]
serialPersistentFields
=
...
...
@@ -1893,7 +1893,7 @@ public final class String
}
/**
* Returns a
new
string that is a substring of this string. The
* Returns a string that is a substring of this string. The
* substring begins with the character at the specified index and
* extends to the end of this string. <p>
* Examples:
...
...
@@ -1921,7 +1921,7 @@ public final class String
}
/**
* Returns a
new
string that is a substring of this string. The
* Returns a string that is a substring of this string. The
* substring begins at the specified {@code beginIndex} and
* extends to the character at index {@code endIndex - 1}.
* Thus the length of the substring is {@code endIndex-beginIndex}.
...
...
@@ -1970,6 +1970,7 @@ public final class String
* <blockquote><pre>
* str.substring(begin, end)</pre></blockquote>
*
* @apiNote
* This method is defined so that the {@code String} class can implement
* the {@link CharSequence} interface.
*
...
...
@@ -1993,8 +1994,8 @@ public final class String
* Concatenates the specified string to the end of this string.
* <p>
* If the length of the argument string is {@code 0}, then this
* {@code String} object is returned. Otherwise, a
new
* {@code String} object is
created, representing
a character
* {@code String} object is returned. Otherwise, a
* {@code String} object is
returned that represents
a character
* sequence that is the concatenation of the character sequence
* represented by this {@code String} object and the character
* sequence represented by the argument string.<p>
...
...
@@ -2021,13 +2022,13 @@ public final class String
}
/**
* Returns a
new
string resulting from replacing all occurrences of
* Returns a string resulting from replacing all occurrences of
* {@code oldChar} in this string with {@code newChar}.
* <p>
* If the character {@code oldChar} does not occur in the
* character sequence represented by this {@code String} object,
* then a reference to this {@code String} object is returned.
* Otherwise, a
new {@code String} object is creat
ed that
* Otherwise, a
{@code String} object is return
ed that
* represents a character sequence identical to the character sequence
* represented by this {@code String} object, except that every
* occurrence of {@code oldChar} is replaced by an occurrence
...
...
@@ -2818,8 +2819,8 @@ public final class String
}
/**
* Returns a
copy of the string, with leading and trailing whitespace
*
omitt
ed.
* Returns a
string whose value is this string, with any leading and trailing
*
whitespace remov
ed.
* <p>
* If this {@code String} object represents an empty character
* sequence, or the first and last characters of character sequence
...
...
@@ -2828,15 +2829,15 @@ public final class String
* reference to this {@code String} object is returned.
* <p>
* Otherwise, if there is no character with a code greater than
* {@code '\u005Cu0020'} in the string, then a
new
* {@code String} object representing an empty string is
created
*
and
returned.
* {@code '\u005Cu0020'} in the string, then a
* {@code String} object representing an empty string is
* returned.
* <p>
* Otherwise, let <i>k</i> be the index of the first character in the
* string whose code is greater than {@code '\u005Cu0020'}, and let
* <i>m</i> be the index of the last character in the string whose code
* is greater than {@code '\u005Cu0020'}. A
new
{@code String}
* object is
creat
ed, representing the substring of this string that
* is greater than {@code '\u005Cu0020'}. A {@code String}
* object is
return
ed, representing the substring of this string that
* begins with the character at index <i>k</i> and ends with the
* character at index <i>m</i>-that is, the result of
* {@code this.substring(k, m + 1)}.
...
...
@@ -2844,7 +2845,7 @@ public final class String
* This method may be used to trim whitespace (as defined above) from
* the beginning and end of a string.
*
* @return A
copy of this string with
leading and trailing white
* @return A
string whose value is this string, with any
leading and trailing white
* space removed, or this string if it has no leading or
* trailing white space.
*/
...
...
@@ -2981,12 +2982,12 @@ public final class String
/**
* Returns the string representation of the {@code char} array
* argument. The contents of the character array are copied; subsequent
* modification of the character array does not affect the
newly
*
created
string.
* modification of the character array does not affect the
returned
* string.
*
* @param data
a {@code char}
array.
* @return a
newly allocated string representing the same sequence of
* character
s contained in the character array argument
.
* @param data
the character
array.
* @return a
{@code String} that contains the characters of the
* character
array
.
*/
public
static
String
valueOf
(
char
data
[])
{
return
new
String
(
data
);
...
...
@@ -3000,14 +3001,13 @@ public final class String
* character of the subarray. The {@code count} argument
* specifies the length of the subarray. The contents of the subarray
* are copied; subsequent modification of the character array does not
* affect the
newly creat
ed string.
* affect the
return
ed string.
*
* @param data the character array.
* @param offset the initial offset into the value of the
* {@code String}.
* @param count the length of the value of the {@code String}.
* @return a string representing the sequence of characters contained
* in the subarray of the character array argument.
* @param offset initial offset of the subarray.
* @param count length of the subarray.
* @return a {@code String} that contains the characters of the
* specified subarray of the character array.
* @exception IndexOutOfBoundsException if {@code offset} is
* negative, or {@code count} is negative, or
* {@code offset+count} is larger than
...
...
@@ -3018,23 +3018,24 @@ public final class String
}
/**
* Returns a String that represents the character sequence in the
* array specified.
* Equivalent to {@link #valueOf(char[], int, int)}.
*
* @param data the character array.
* @param offset initial offset of the subarray.
* @param count length of the subarray.
* @return a {@code String} that contains the characters of the
* specified subarray of the character array.
* @exception IndexOutOfBoundsException if {@code offset} is
* negative, or {@code count} is negative, or
* {@code offset+count} is larger than
* {@code data.length}.
*/
public
static
String
copyValueOf
(
char
data
[],
int
offset
,
int
count
)
{
// All public String constructors now copy the data.
return
new
String
(
data
,
offset
,
count
);
}
/**
* Returns a String that represents the character sequence in the
* array specified.
* Equivalent to {@link #valueOf(char[])}.
*
* @param data the character array.
* @return a {@code String} that contains the characters of the
...
...
test/java/nio/channels/FileChannel/Size.java
浏览文件 @
46bfc4ba
/*
* Copyright (c) 2000, 201
2
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 201
3
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
...
...
@@ -39,67 +39,57 @@ import java.util.Random;
public
class
Size
{
private
static
Random
generator
=
new
Random
();
private
static
File
blah
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
test
1
();
test
2
();
test
SmallFile
();
test
LargeFile
();
}
private
static
void
test
1
()
throws
Exception
{
blah
=
File
.
createTempFile
(
"blah"
,
null
);
blah
.
deleteOnExit
();
private
static
void
test
SmallFile
()
throws
Exception
{
File
smallFile
=
new
File
(
"smallFileTest"
);
Random
generator
=
new
Random
();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
long
testSize
=
generator
.
nextInt
(
1000
);
initTestFile
(
blah
,
testSize
);
FileInputStream
fis
=
new
FileInputStream
(
blah
);
FileChannel
c
=
fis
.
getChannel
();
if
(
c
.
size
()
!=
testSize
)
throw
new
RuntimeException
(
"Size failed"
);
c
.
close
();
fis
.
close
();
initTestFile
(
smallFile
,
testSize
);
try
(
FileChannel
c
=
new
FileInputStream
(
smallFile
).
getChannel
())
{
if
(
c
.
size
()
!=
testSize
)
{
throw
new
RuntimeException
(
"Size failed in testSmallFile. "
+
"Expect size "
+
testSize
+
", actual size "
+
c
.
size
());
}
}
}
blah
.
delete
();
smallFile
.
deleteOnExit
();
}
// Test for bug 4563125
private
static
void
test2
()
throws
Exception
{
// Windows and Linux can't handle the really large file sizes for a truncate
// or a positional write required by the test for 4563125
String
osName
=
System
.
getProperty
(
"os.name"
);
if
(
osName
.
startsWith
(
"SunOS"
)
||
osName
.
contains
(
"OS X"
))
{
blah
=
File
.
createTempFile
(
"blah"
,
null
);
long
testSize
=
((
long
)
Integer
.
MAX_VALUE
)
*
2
;
initTestFile
(
blah
,
10
);
RandomAccessFile
raf
=
new
RandomAccessFile
(
blah
,
"rw"
);
FileChannel
fc
=
raf
.
getChannel
();
private
static
void
testLargeFile
()
throws
Exception
{
File
largeFile
=
new
File
(
"largeFileTest"
);
long
testSize
=
((
long
)
Integer
.
MAX_VALUE
)
*
2
;
initTestFile
(
largeFile
,
10
);
try
(
FileChannel
fc
=
new
RandomAccessFile
(
largeFile
,
"rw"
).
getChannel
())
{
fc
.
size
();
fc
.
map
(
FileChannel
.
MapMode
.
READ_WRITE
,
testSize
,
10
);
if
(
fc
.
size
()
!=
testSize
+
10
)
throw
new
RuntimeException
(
"Size failed
"
+
fc
.
size
());
fc
.
close
();
raf
.
close
(
);
blah
.
delete
();
if
(
fc
.
size
()
!=
testSize
+
10
)
{
throw
new
RuntimeException
(
"Size failed
in testLargeFile. "
+
"Expect size "
+
(
testSize
+
10
)
+
", actual size "
+
fc
.
size
()
);
}
}
largeFile
.
deleteOnExit
();
}
/**
* Create
s file blah of
specified size in bytes.
* Create
a file with the
specified size in bytes.
*
*/
private
static
void
initTestFile
(
File
blah
,
long
size
)
throws
Exception
{
if
(
blah
.
exists
())
blah
.
delete
();
FileOutputStream
fos
=
new
FileOutputStream
(
blah
);
BufferedWriter
awriter
=
new
BufferedWriter
(
new
OutputStreamWriter
(
fos
,
"8859_1"
));
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
awriter
.
write
(
"e"
);
private
static
void
initTestFile
(
File
f
,
long
size
)
throws
Exception
{
try
(
BufferedWriter
awriter
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
f
),
"8859_1"
)))
{
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
awriter
.
write
(
"e"
);
}
}
awriter
.
flush
();
awriter
.
close
();
}
}
test/java/nio/file/Files/Misc.java
浏览文件 @
46bfc4ba
/*
* Copyright (c) 2008, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 201
3
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
...
...
@@ -313,8 +313,14 @@ public class Misc {
acl
.
add
(
0
,
entry
);
view
.
setAcl
(
acl
);
try
{
assertTrue
(!
isWritable
(
file
));
assertTrue
(!
isExecutable
(
file
));
if
(
isRoot
())
{
// root has all permissions
assertTrue
(
isWritable
(
file
));
assertTrue
(
isExecutable
(
file
));
}
else
{
assertTrue
(!
isWritable
(
file
));
assertTrue
(!
isExecutable
(
file
));
}
}
finally
{
// Restore ACL
acl
.
remove
(
0
);
...
...
@@ -353,4 +359,12 @@ public class Misc {
if
(!
okay
)
throw
new
RuntimeException
(
"Assertion Failed"
);
}
private
static
boolean
isRoot
()
{
if
(
System
.
getProperty
(
"os.name"
).
startsWith
(
"Windows"
))
return
false
;
Path
passwd
=
Paths
.
get
(
"/etc/passwd"
);
return
Files
.
isWritable
(
passwd
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录