Cross Reference: OpsAfterClose.java
xref
: /
openjdk7
/
jdk
/
test
/
java
/
io
/
FileInputStream
/
OpsAfterClose.java
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
OpsAfterClose.java revision 0
0
N/A
/**
2273
N/A
*
@test
0
N/A
*
@bug
6359397
0
N/A
*
@summary
Test if FileInputStream methods will check if the stream
0
N/A
* has been closed.
0
N/A
*/
0
N/A
0
N/A
import
java
.
io
.*;
0
N/A
0
N/A
public
enum
OpsAfterClose
{
0
N/A
0
N/A
READ
{
boolean
check
(
FileInputStream
r) {
0
N/A
try
{
0
N/A
r.
read
();
0
N/A
}
catch
(
IOException
io
) {
0
N/A
System
.
out
.
print
(
"Excep Msg: "
+
io
.
getMessage
() +
", "
);
0
N/A
return
true
;
0
N/A
}
1472
N/A
return
false
;
1472
N/A
} },
1472
N/A
0
N/A
READ_BUF
{
boolean
check
(
FileInputStream
r) {
0
N/A
try
{
0
N/A
byte
buf
[] =
new
byte
[
2
];
1879
N/A
r.
read
(
buf
);
1879
N/A
}
catch
(
IOException
io
) {
1879
N/A
System
.
out
.
print
(
"Excep Msg: "
+
io
.
getMessage
() +
", "
);
1879
N/A
return
true
;
1879
N/A
}
1879
N/A
return
false
;
0
N/A
} },
0
N/A
READ_BUF_OFF
{
boolean
check
(
FileInputStream
r) {
0
N/A
try
{
0
N/A
byte
buf
[] =
new
byte
[
2
];
0
N/A
int
len
=
1
;
0
N/A
r.
read
(
buf
,
0
,
len
);
0
N/A
}
catch
(
IOException
io
) {
0
N/A
System
.
out
.
print
(
"Excep Msg: "
+
io
.
getMessage
() +
", "
);
0
N/A
return
true
;
0
N/A
}
0
N/A
return
false
;
0
N/A
} },
0
N/A
GET_CHANNEL
{
boolean
check
(
FileInputStream
r) {
0
N/A
r.
getChannel
();
10
N/A
return
true
;
10
N/A
} },
2679
N/A
GET_FD
{
boolean
check
(
FileInputStream
r) {
10
N/A
try
{
10
N/A
r.
getFD
();
10
N/A
return
true
;
10
N/A
}
catch
(
IOException
io
) {
0
N/A
System
.
out
.
print
(
"Excep Msg: "
+
io
.
getMessage
() +
", "
);
0
N/A
return
false
;
0
N/A
}
0
N/A
} },
0
N/A
SKIP
{
boolean
check
(
FileInputStream
r) {
0
N/A
try
{
0
N/A
r.
skip
(
1
);
0
N/A
}
catch
(
IOException
io
) {
0
N/A
System
.
out
.
print
(
"Excep Msg: "
+
io
.
getMessage
() +
", "
);
0
N/A
return
true
;
0
N/A
}
2080
N/A
return
false
;
0
N/A
} },
0
N/A
CLOSE
{
boolean
check
(
FileInputStream
r) {
0
N/A
try
{
0
N/A
r.
close
();
0
N/A
return
true
;
// No Exception thrown on windows
0
N/A
}
catch
(
IOException
io
) {
0
N/A
System
.
out
.
print
(
"Excep Msg: "
+
io
.
getMessage
() +
", "
);
0
N/A
return
true
;
// Exception thrown on solaris and linux
0
N/A
}
0
N/A
} };
3177
N/A
0
N/A
abstract
boolean
check
(
FileInputStream
r);
0
N/A
0
N/A
public
static
void
main
(
String
args
[])
throws
Exception
{
0
N/A
0
N/A
boolean
failed
=
false
;
0
N/A
0
N/A
File
f =
new
File
(
System
.
getProperty
(
"test.dir"
,
"."
),
2679
N/A
"
f.txt
"
);
2679
N/A
f.
createNewFile
();
2679
N/A
f.
deleteOnExit
();
2679
N/A
2679
N/A
FileInputStream
fis
=
new
FileInputStream
(f);
2679
N/A
if
(
testFileInputStream
(
fis
)) {
1601
N/A
throw
new
Exception
(
"Test failed for some of the operation{s}"
+
1601
N/A
" on FileInputStream, check the messages"
);
1601
N/A
}
0
N/A
}
0
N/A
0
N/A
private
static
boolean
testFileInputStream
(
FileInputStream
r)
0
N/A
throws
Exception
{
0
N/A
r.
close
();
10
N/A
boolean
failed
=
false
;
10
N/A
boolean
result
;
10
N/A
System
.
out
.
println
(
"Testing File:"
+ r);
10
N/A
for
(
OpsAfterClose
op
:
OpsAfterClose
.
values
()) {
10
N/A
result
=
op
.
check
(r);
10
N/A
if
(!
result
) {
10
N/A
failed
=
true
;
10
N/A
}
10
N/A
System
.
out
.
println
(
op
+
":"
+
result
);
0
N/A
}
1879
N/A
if
(
failed
) {
1879
N/A
System
.
out
.
println
(
"Test failed for the failed operation{s}"
+
" above for the FileInputStream:"
+ r);
}
return
failed
;
}
}