Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
761e618b
提交
761e618b
authored
4月 24, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New output catcher (converts to HTML)
上级
71cbfc09
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
221 行增加
和
0 行删除
+221
-0
OutputCatcher.java
h2/src/test/org/h2/test/utils/OutputCatcher.java
+206
-0
package.html
h2/src/test/org/h2/test/utils/package.html
+15
-0
没有找到文件。
h2/src/test/org/h2/test/utils/OutputCatcher.java
0 → 100644
浏览文件 @
761e618b
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License, Version
* 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html). Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
utils
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.FilterOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.PrintStream
;
import
java.io.PrintWriter
;
/**
* A tool to capture the output of System.out and System.err. The regular output
* still occurs, but it is additionally available as a String.
*/
public
class
OutputCatcher
{
/**
* The HTML text will contain this string if something was written to System.err.
*/
public
static
final
String
START_ERROR
=
"<span style=\"color:red;\">"
;
private
ByteArrayOutputStream
buff
=
new
ByteArrayOutputStream
();
private
HtmlOutputStream
html
;
private
DualOutputStream
out
,
err
;
private
String
output
;
private
OutputCatcher
()
{
html
=
new
HtmlOutputStream
(
buff
);
out
=
new
DualOutputStream
(
html
,
System
.
out
,
false
);
err
=
new
DualOutputStream
(
html
,
System
.
err
,
true
);
System
.
setOut
(
new
PrintStream
(
out
,
true
));
System
.
setErr
(
new
PrintStream
(
err
,
true
));
}
/**
* Stop catching output.
*/
public
void
stop
()
{
System
.
out
.
flush
();
System
.
setOut
(
out
.
print
);
System
.
err
.
flush
();
System
.
setErr
(
err
.
print
);
output
=
new
String
(
buff
.
toByteArray
());
}
/**
* Write the output to a HTML file.
*
* @param title the title
* @param fileName the file name
*/
public
void
writeTo
(
String
title
,
String
fileName
)
throws
IOException
{
File
file
=
new
File
(
fileName
);
file
.
getParentFile
().
mkdirs
();
PrintWriter
writer
=
new
PrintWriter
(
new
FileOutputStream
(
file
));
writer
.
write
(
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
);
writer
.
write
(
"<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n"
);
writer
.
write
(
"<head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" /><title>\n"
);
writer
.
print
(
title
);
writer
.
print
(
"</title><link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheet.css\" />\n"
);
writer
.
print
(
"</head><body style=\"margin: 20px;\">\n"
);
writer
.
print
(
"<h1>"
+
title
+
"</h1><br />\n"
);
writer
.
print
(
output
);
writer
.
write
(
"\n</body></html>"
);
writer
.
close
();
}
/**
* Create a new output catcher and start it.
*
* @return the output catcher
*/
public
static
OutputCatcher
start
()
{
return
new
OutputCatcher
();
}
/**
* An output stream that writes to both a HTML stream and a print stream.
*/
static
class
DualOutputStream
extends
FilterOutputStream
{
private
final
HtmlOutputStream
out
;
private
final
PrintStream
print
;
private
final
boolean
error
;
DualOutputStream
(
HtmlOutputStream
out
,
PrintStream
print
,
boolean
error
)
{
super
(
out
);
this
.
out
=
out
;
this
.
print
=
print
;
this
.
error
=
error
;
}
public
void
close
()
throws
IOException
{
print
.
close
();
super
.
close
();
}
public
void
flush
()
throws
IOException
{
print
.
flush
();
super
.
flush
();
}
public
void
write
(
int
b
)
throws
IOException
{
print
.
write
(
b
);
out
.
write
(
error
,
b
);
}
}
/**
* An output stream that has two modes: error mode and regular mode.
*/
static
class
HtmlOutputStream
extends
FilterOutputStream
{
private
static
final
byte
[]
START
=
START_ERROR
.
getBytes
();
private
static
final
byte
[]
END
=
"</span>"
.
getBytes
();
private
static
final
byte
[]
BR
=
"<br />\n"
.
getBytes
();
private
static
final
byte
[]
NBSP
=
" "
.
getBytes
();
private
static
final
byte
[]
LT
=
"<"
.
getBytes
();
private
static
final
byte
[]
GT
=
">"
.
getBytes
();
private
static
final
byte
[]
AMP
=
"&"
.
getBytes
();
private
boolean
error
;
private
boolean
hasError
;
private
boolean
convertSpace
;
HtmlOutputStream
(
OutputStream
out
)
{
super
(
out
);
}
/**
* Check if the error mode was used.
*
* @return true if it was
*/
boolean
hasError
()
{
return
hasError
;
}
/**
* Enable or disable the error mode.
*
* @param error the flag
*/
void
setError
(
boolean
error
)
throws
IOException
{
if
(
error
!=
this
.
error
)
{
if
(
error
)
{
hasError
=
true
;
super
.
write
(
START
);
}
else
{
super
.
write
(
END
);
}
this
.
error
=
error
;
}
}
/**
* Write a character.
*
* @param error if the character comes from the error stream
* @param b the character
*/
void
write
(
boolean
error
,
int
b
)
throws
IOException
{
setError
(
error
);
switch
(
b
)
{
case
'\n'
:
super
.
write
(
BR
);
convertSpace
=
true
;
break
;
case
'\t'
:
super
.
write
(
NBSP
);
super
.
write
(
NBSP
);
break
;
case
' '
:
if
(
convertSpace
)
{
super
.
write
(
NBSP
);
}
else
{
super
.
write
(
b
);
}
break
;
case
'<'
:
super
.
write
(
LT
);
break
;
case
'>'
:
super
.
write
(
GT
);
break
;
case
'&'
:
super
.
write
(
AMP
);
break
;
default
:
if
(
b
>=
128
)
{
super
.
write
((
"&#"
+
b
+
";"
).
getBytes
());
}
else
{
super
.
write
(
b
);
}
convertSpace
=
false
;
}
}
}
}
h2/src/test/org/h2/test/utils/package.html
0 → 100644
浏览文件 @
761e618b
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License, Version 1.0,
and under the Eclipse Public License, Version 1.0
(http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html
xmlns=
"http://www.w3.org/1999/xhtml"
lang=
"en"
xml:lang=
"en"
>
<head><meta
http-equiv=
"Content-Type"
content=
"text/html;charset=utf-8"
/><title>
Javadoc package documentation
</title></head><body
style=
"font: 9pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;"
>
Utility classes used by the tests.
</body></html>
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论