Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
a02391fb
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看板
提交
a02391fb
编写于
8月 08, 2016
作者:
S
snikandrova
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8162876: [TEST_BUG] sun/net/www/protocol/http/HttpInputStream.java fails intermittently
Reviewed-by: chegar
上级
a703651e
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
89 addition
and
71 deletion
+89
-71
test/sun/net/www/protocol/http/HttpInputStream.java
test/sun/net/www/protocol/http/HttpInputStream.java
+89
-71
未找到文件。
test/sun/net/www/protocol/http/HttpInputStream.java
浏览文件 @
a02391fb
/*
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003,
2016,
Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -23,77 +23,95 @@
...
@@ -23,77 +23,95 @@
/* @test
/* @test
* @bug 4937598
* @bug 4937598
* @summary http://www.clipstream.com v
edi
o does not play; read() problem
* @summary http://www.clipstream.com v
ide
o does not play; read() problem
*/
*/
import
java.util.*
;
import
java.io.*
;
import
java.net.*
;
import
java.text.*
;
public
class
HttpInputStream
implements
Runnable
{
ServerSocket
serverSock
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.net.URL
;
public
void
run
()
{
public
class
HttpInputStream
{
try
{
Socket
s
=
serverSock
.
accept
();
InputStream
in
=
s
.
getInputStream
();
byte
b
[]
=
new
byte
[
4096
];
// assume we read the entire http request
private
static
final
int
CONTENT_LENGTH
=
20
;
// (bad assumption but okay for test case)
int
nread
=
in
.
read
(
b
);
OutputStream
o
=
s
.
getOutputStream
();
static
class
Server
implements
AutoCloseable
,
Runnable
{
o
.
write
(
"HTTP/1.1 200 OK"
.
getBytes
()
);
final
ServerSocket
serverSocket
;
o
.
write
(
"Content-Length: 20"
.
getBytes
()
);
static
final
byte
[]
requestEnd
=
new
byte
[]{
'\r'
,
'\n'
,
'\r'
,
'\n'
};
o
.
write
(
(
byte
)
'\r'
);
static
final
int
TIMEOUT
=
10
*
1000
;
o
.
write
(
(
byte
)
'\n'
);
o
.
write
(
(
byte
)
'\r'
);
o
.
write
(
(
byte
)
'\n'
);
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
Server
()
throws
IOException
{
o
.
write
((
byte
)
0xff
);
serverSocket
=
new
ServerSocket
(
0
);
}
}
o
.
flush
();
void
readOneRequest
(
InputStream
is
)
throws
IOException
{
o
.
close
();
int
requestEndCount
=
0
,
r
;
while
((
r
=
is
.
read
())
!=
-
1
)
{
}
catch
(
Exception
e
)
{
}
if
(
r
==
requestEnd
[
requestEndCount
])
{
requestEndCount
++;
if
(
requestEndCount
==
4
)
{
break
;
}
}
else
{
requestEndCount
=
0
;
}
}
}
}
@Override
public
void
run
()
{
try
(
Socket
s
=
serverSocket
.
accept
())
{
s
.
setSoTimeout
(
TIMEOUT
);
readOneRequest
(
s
.
getInputStream
());
try
(
OutputStream
os
=
s
.
getOutputStream
())
{
os
.
write
(
"HTTP/1.1 200 OK"
.
getBytes
());
os
.
write
((
"Content-Length: "
+
CONTENT_LENGTH
).
getBytes
());
os
.
write
(
"\r\n\r\n"
.
getBytes
());
for
(
int
i
=
0
;
i
<
CONTENT_LENGTH
;
i
++)
{
os
.
write
(
0xff
);
}
os
.
flush
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
HttpInputStream
()
throws
Exception
{
@Override
public
void
close
()
throws
IOException
{
serverSock
=
new
ServerSocket
(
0
);
if
(!
serverSocket
.
isClosed
())
{
int
port
=
serverSock
.
getLocalPort
();
serverSocket
.
close
();
}
}
Thread
thr
=
new
Thread
(
this
);
public
int
getPort
()
{
thr
.
start
();
return
serverSocket
.
getLocalPort
();
}
}
Date
date
=
new
Date
(
new
Date
().
getTime
()-
1440000
);
// this time yesterday
URL
url
;
HttpURLConnection
con
;
url
=
new
URL
(
"http://localhost:"
+
String
.
valueOf
(
port
)
+
private
static
int
read
(
InputStream
is
)
throws
IOException
{
"/anything"
);
int
len
=
0
;
con
=
(
HttpURLConnection
)
url
.
openConnection
();
while
(
is
.
read
()
!=
-
1
)
{
len
++;
}
return
len
;
}
int
ret
=
con
.
getResponseCode
();
public
static
void
main
(
String
args
[])
throws
IOException
{
byte
[]
b
=
new
byte
[
20
];
try
(
Server
server
=
new
Server
())
{
InputStream
is
=
con
.
getInputStream
();
(
new
Thread
(
server
)).
start
();
int
i
=
0
,
count
=
0
;
URL
url
=
new
URL
(
"http://localhost:"
+
server
.
getPort
()
+
"/anything"
);
while
((
i
=
is
.
read
())
!=
-
1
)
{
try
(
InputStream
is
=
url
.
openConnection
().
getInputStream
())
{
System
.
out
.
println
(
"i = "
+
i
);
if
(
read
(
is
)
!=
CONTENT_LENGTH
)
{
count
++;
}
if
(
count
!=
20
)
{
throw
new
RuntimeException
(
"HttpInputStream.read() failed with 0xff"
);
throw
new
RuntimeException
(
"HttpInputStream.read() failed with 0xff"
);
}
}
}
}
}
public
static
void
main
(
String
args
[])
throws
Exception
{
new
HttpInputStream
();
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录