Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
8f1768e1
提交
8f1768e1
authored
8月 26, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New debugging file system implementation that logs each file access.
上级
f68db854
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
291 行增加
和
0 行删除
+291
-0
FileObjectDebug.java
h2/src/test/org/h2/test/utils/FileObjectDebug.java
+76
-0
FileSystemDebug.java
h2/src/test/org/h2/test/utils/FileSystemDebug.java
+215
-0
没有找到文件。
h2/src/test/org/h2/test/utils/FileObjectDebug.java
0 → 100644
浏览文件 @
8f1768e1
/*
* 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.IOException
;
import
org.h2.store.fs.FileObject
;
/**
* A debugging file that logs all operations.
*/
public
class
FileObjectDebug
implements
FileObject
{
private
final
FileSystemDebug
fs
;
private
final
FileObject
file
;
private
final
String
name
;
FileObjectDebug
(
FileSystemDebug
fs
,
FileObject
file
)
{
this
.
fs
=
fs
;
this
.
file
=
file
;
this
.
name
=
file
.
getName
();
}
public
void
close
()
throws
IOException
{
debug
(
"close"
);
file
.
close
();
}
public
long
getFilePointer
()
throws
IOException
{
debug
(
"getFilePointer"
);
return
file
.
getFilePointer
();
}
public
String
getName
()
{
debug
(
"getName"
);
return
FileSystemDebug
.
PREFIX
+
file
.
getName
();
}
public
long
length
()
throws
IOException
{
debug
(
"length"
);
return
file
.
length
();
}
public
void
readFully
(
byte
[]
b
,
int
off
,
int
len
)
throws
IOException
{
debug
(
"readFully"
,
off
,
len
);
file
.
readFully
(
b
,
off
,
len
);
}
public
void
seek
(
long
pos
)
throws
IOException
{
debug
(
"seek"
,
pos
);
file
.
seek
(
pos
);
}
public
void
setFileLength
(
long
newLength
)
throws
IOException
{
debug
(
"setFileLength"
,
newLength
);
file
.
setFileLength
(
newLength
);
}
public
void
sync
()
throws
IOException
{
debug
(
"sync"
);
file
.
sync
();
}
public
void
write
(
byte
[]
b
,
int
off
,
int
len
)
throws
IOException
{
debug
(
"write"
,
off
,
len
);
file
.
write
(
b
,
off
,
len
);
}
private
void
debug
(
String
method
,
Object
...
params
)
{
fs
.
debug
(
method
,
name
,
params
);
}
}
h2/src/test/org/h2/test/utils/FileSystemDebug.java
0 → 100644
浏览文件 @
8f1768e1
/*
* 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.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.sql.SQLException
;
import
org.h2.message.Message
;
import
org.h2.store.fs.FileObject
;
import
org.h2.store.fs.FileSystem
;
/**
* A debugging file system that logs all operations.
*/
public
class
FileSystemDebug
extends
FileSystem
{
/**
* The prefix used for a debugging file system.
*/
static
final
String
PREFIX
=
"debug:"
;
private
static
final
FileSystemDebug
INSTANCE
=
new
FileSystemDebug
();
/**
* Register the file system.
*/
public
static
void
register
()
{
FileSystem
.
register
(
INSTANCE
);
}
public
boolean
canWrite
(
String
fileName
)
{
fileName
=
translateFileName
(
fileName
);
debug
(
"canWrite"
,
fileName
);
return
FileSystem
.
getInstance
(
fileName
).
canWrite
(
fileName
);
}
public
void
copy
(
String
original
,
String
copy
)
throws
SQLException
{
original
=
translateFileName
(
original
);
copy
=
translateFileName
(
copy
);
debug
(
"copy"
,
original
,
copy
);
FileSystem
.
getInstance
(
original
).
copy
(
original
,
copy
);
}
public
void
createDirs
(
String
fileName
)
throws
SQLException
{
fileName
=
translateFileName
(
fileName
);
debug
(
"createDirs"
,
fileName
);
FileSystem
.
getInstance
(
fileName
).
createDirs
(
fileName
);
}
public
boolean
createNewFile
(
String
fileName
)
throws
SQLException
{
fileName
=
translateFileName
(
fileName
);
debug
(
"createNewFile"
,
fileName
);
return
FileSystem
.
getInstance
(
fileName
).
createNewFile
(
fileName
);
}
public
String
createTempFile
(
String
prefix
,
String
suffix
,
boolean
deleteOnExit
,
boolean
inTempDir
)
throws
IOException
{
prefix
=
translateFileName
(
prefix
);
debug
(
"createTempFile"
,
prefix
,
suffix
,
deleteOnExit
,
inTempDir
);
return
PREFIX
+
FileSystem
.
getInstance
(
prefix
).
createTempFile
(
prefix
,
suffix
,
deleteOnExit
,
inTempDir
);
}
public
void
delete
(
String
fileName
)
throws
SQLException
{
fileName
=
translateFileName
(
fileName
);
debug
(
"fileName"
,
fileName
);
FileSystem
.
getInstance
(
fileName
).
delete
(
fileName
);
}
public
void
deleteRecursive
(
String
directory
)
throws
SQLException
{
directory
=
translateFileName
(
directory
);
debug
(
"deleteRecursive"
,
directory
);
FileSystem
.
getInstance
(
directory
).
deleteRecursive
(
directory
);
}
public
boolean
exists
(
String
fileName
)
{
fileName
=
translateFileName
(
fileName
);
debug
(
"exists"
,
fileName
);
return
FileSystem
.
getInstance
(
fileName
).
exists
(
fileName
);
}
public
boolean
fileStartsWith
(
String
fileName
,
String
prefix
)
{
fileName
=
translateFileName
(
fileName
);
prefix
=
translateFileName
(
prefix
);
debug
(
"fileStartsWith"
,
fileName
,
prefix
);
return
FileSystem
.
getInstance
(
fileName
).
fileStartsWith
(
fileName
,
prefix
);
}
public
String
getAbsolutePath
(
String
fileName
)
{
fileName
=
translateFileName
(
fileName
);
debug
(
"getAbsolutePath"
,
fileName
);
return
PREFIX
+
FileSystem
.
getInstance
(
fileName
).
getAbsolutePath
(
fileName
);
}
public
String
getFileName
(
String
name
)
throws
SQLException
{
name
=
translateFileName
(
name
);
debug
(
"getFileName"
,
name
);
return
FileSystem
.
getInstance
(
name
).
getFileName
(
name
);
}
public
long
getLastModified
(
String
fileName
)
{
fileName
=
translateFileName
(
fileName
);
debug
(
"getLastModified"
,
fileName
);
return
FileSystem
.
getInstance
(
fileName
).
getLastModified
(
fileName
);
}
public
String
getParent
(
String
fileName
)
{
fileName
=
translateFileName
(
fileName
);
debug
(
"getParent"
,
fileName
);
return
PREFIX
+
FileSystem
.
getInstance
(
fileName
).
getParent
(
fileName
);
}
public
boolean
isAbsolute
(
String
fileName
)
{
fileName
=
translateFileName
(
fileName
);
debug
(
"isAbsolute"
,
fileName
);
return
FileSystem
.
getInstance
(
fileName
).
isAbsolute
(
fileName
);
}
public
boolean
isDirectory
(
String
fileName
)
{
fileName
=
translateFileName
(
fileName
);
debug
(
"isDirectory"
,
fileName
);
return
FileSystem
.
getInstance
(
fileName
).
isDirectory
(
fileName
);
}
public
boolean
isReadOnly
(
String
fileName
)
{
fileName
=
translateFileName
(
fileName
);
debug
(
"isReadOnly"
,
fileName
);
return
FileSystem
.
getInstance
(
fileName
).
isReadOnly
(
fileName
);
}
public
long
length
(
String
fileName
)
{
fileName
=
translateFileName
(
fileName
);
debug
(
"length"
,
fileName
);
return
FileSystem
.
getInstance
(
fileName
).
length
(
fileName
);
}
public
String
[]
listFiles
(
String
directory
)
throws
SQLException
{
directory
=
translateFileName
(
directory
);
debug
(
"listFiles"
,
directory
);
String
[]
list
=
FileSystem
.
getInstance
(
directory
).
listFiles
(
directory
);
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
list
[
i
]
=
PREFIX
+
list
[
i
];
}
return
list
;
}
public
String
normalize
(
String
fileName
)
throws
SQLException
{
fileName
=
translateFileName
(
fileName
);
debug
(
"normalize"
,
fileName
);
return
PREFIX
+
FileSystem
.
getInstance
(
fileName
).
normalize
(
fileName
);
}
public
InputStream
openFileInputStream
(
String
fileName
)
throws
IOException
{
fileName
=
translateFileName
(
fileName
);
debug
(
"openFileInputStream"
,
fileName
);
return
FileSystem
.
getInstance
(
fileName
).
openFileInputStream
(
fileName
);
}
public
FileObject
openFileObject
(
String
fileName
,
String
mode
)
throws
IOException
{
fileName
=
translateFileName
(
fileName
);
debug
(
"openFileObject"
,
fileName
,
mode
);
return
new
FileObjectDebug
(
this
,
FileSystem
.
getInstance
(
fileName
).
openFileObject
(
fileName
,
mode
));
}
public
OutputStream
openFileOutputStream
(
String
fileName
,
boolean
append
)
throws
SQLException
{
fileName
=
translateFileName
(
fileName
);
debug
(
"openFileOutputStream"
,
fileName
,
append
);
return
FileSystem
.
getInstance
(
fileName
).
openFileOutputStream
(
fileName
,
append
);
}
public
void
rename
(
String
oldName
,
String
newName
)
throws
SQLException
{
oldName
=
translateFileName
(
oldName
);
newName
=
translateFileName
(
newName
);
debug
(
"rename"
,
oldName
,
newName
);
FileSystem
.
getInstance
(
oldName
).
copy
(
oldName
,
newName
);
}
public
boolean
tryDelete
(
String
fileName
)
{
fileName
=
translateFileName
(
fileName
);
debug
(
"tryDelete"
,
fileName
);
return
FileSystem
.
getInstance
(
fileName
).
tryDelete
(
fileName
);
}
protected
boolean
accepts
(
String
fileName
)
{
return
fileName
.
startsWith
(
PREFIX
);
}
private
String
translateFileName
(
String
fileName
)
{
if
(!
fileName
.
startsWith
(
PREFIX
))
{
Message
.
throwInternalError
(
fileName
+
" doesn't start with "
+
PREFIX
);
}
return
fileName
.
substring
(
PREFIX
.
length
());
}
/**
* Print a debug message.
*
* @param method the method name
* @param fileName the file name
* @param params parameters if any
*/
void
debug
(
String
method
,
String
fileName
,
Object
...
params
)
{
StringBuilder
buff
=
new
StringBuilder
(
" "
);
buff
.
append
(
fileName
).
append
(
' '
).
append
(
method
);
for
(
Object
s
:
params
)
{
buff
.
append
(
' '
).
append
(
s
);
}
System
.
out
.
println
(
buff
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论