Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
1479dc06
提交
1479dc06
authored
9月 21, 2011
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improved compatibility with the Java 7 FileSystem abstraction (improved tests).
上级
1dd6fdda
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
47 行增加
和
33 行删除
+47
-33
FilePathDisk.java
h2/src/main/org/h2/store/fs/FilePathDisk.java
+5
-7
FilePathMem.java
h2/src/main/org/h2/store/fs/FilePathMem.java
+0
-21
FilePathSplit.java
h2/src/main/org/h2/store/fs/FilePathSplit.java
+1
-2
TestFileSystem.java
h2/src/test/org/h2/test/unit/TestFileSystem.java
+41
-3
没有找到文件。
h2/src/main/org/h2/store/fs/FilePathDisk.java
浏览文件 @
1479dc06
...
...
@@ -54,6 +54,9 @@ public class FilePathDisk extends FilePath {
*/
protected
static
String
translateFileName
(
String
fileName
)
{
fileName
=
fileName
.
replace
(
'\\'
,
'/'
);
if
(
fileName
.
startsWith
(
"file:"
))
{
fileName
=
fileName
.
substring
(
"file:"
.
length
());
}
return
expandUserHomeDirectory
(
fileName
);
}
...
...
@@ -65,16 +68,11 @@ public class FilePathDisk extends FilePath {
* @return the native file name
*/
public
static
String
expandUserHomeDirectory
(
String
fileName
)
{
boolean
prefix
=
false
;
if
(
fileName
.
startsWith
(
"file:"
))
{
prefix
=
true
;
fileName
=
fileName
.
substring
(
"file:"
.
length
());
}
if
(
fileName
.
startsWith
(
"~"
)
&&
(
fileName
.
length
()
==
1
||
fileName
.
startsWith
(
"~/"
)
||
fileName
.
startsWith
(
"~\\"
)))
{
if
(
fileName
.
startsWith
(
"~"
)
&&
(
fileName
.
length
()
==
1
||
fileName
.
startsWith
(
"~/"
)))
{
String
userDir
=
SysProperties
.
USER_HOME
;
fileName
=
userDir
+
fileName
.
substring
(
1
);
}
return
prefix
?
"file:"
+
fileName
:
fileName
;
return
fileName
;
}
public
void
moveTo
(
FilePath
newName
)
{
...
...
h2/src/main/org/h2/store/fs/FilePathMem.java
浏览文件 @
1479dc06
...
...
@@ -314,7 +314,6 @@ class FileMemData {
private
byte
[][]
data
;
private
long
lastModified
;
private
boolean
isReadOnly
;
private
volatile
boolean
locked
;
static
{
byte
[]
n
=
new
byte
[
BLOCK_SIZE
];
...
...
@@ -564,26 +563,6 @@ class FileMemData {
return
true
;
}
/**
* Lock the file.
*
* @return if successful
*/
synchronized
boolean
tryLock
()
{
if
(
locked
)
{
return
false
;
}
locked
=
true
;
return
true
;
}
/**
* Unlock the file.
*/
public
synchronized
void
releaseLock
()
{
locked
=
false
;
}
}
h2/src/main/org/h2/store/fs/FilePathSplit.java
浏览文件 @
1479dc06
...
...
@@ -151,8 +151,7 @@ public class FilePathSplit extends FilePathWrapper {
closeAndThrow
(
array
.
length
-
1
,
array
,
c
,
maxLength
);
}
}
FileSplit
fo
=
new
FileSplit
(
this
,
mode
,
array
,
length
,
maxLength
);
return
fo
;
return
new
FileSplit
(
this
,
mode
,
array
,
length
,
maxLength
);
}
private
long
getDefaultMaxLength
()
{
...
...
h2/src/test/org/h2/test/unit/TestFileSystem.java
浏览文件 @
1479dc06
...
...
@@ -174,7 +174,7 @@ public class TestFileSystem extends TestBase {
FileUtils
.
delete
(
getBaseDir
()
+
"/fsMem.zip"
);
}
private
void
testDatabaseInJar
()
throws
SQL
Exception
{
private
void
testDatabaseInJar
()
throws
Exception
{
if
(
getBaseDir
().
indexOf
(
':'
)
>
0
)
{
return
;
}
...
...
@@ -204,6 +204,16 @@ public class TestFileSystem extends TestBase {
assertTrue
(!
FileUtils
.
isDirectory
(
f
));
assertTrue
(
FileUtils
.
size
(
f
)
>
0
);
assertTrue
(
f
.
endsWith
(
FileUtils
.
getName
(
f
)));
assertEquals
(
0
,
FileUtils
.
lastModified
(
f
));
FileUtils
.
setReadOnly
(
f
);
assertFalse
(
FileUtils
.
canWrite
(
f
));
InputStream
in
=
FileUtils
.
newInputStream
(
f
);
int
len
=
0
;
while
(
in
.
read
()
>=
0
)
{
len
++;
}
assertEquals
(
len
,
FileUtils
.
size
(
f
));
testReadOnly
(
f
);
}
String
urlJar
=
"jdbc:h2:zip:"
+
getBaseDir
()
+
"/fsJar.zip!/fsJar"
;
conn
=
DriverManager
.
getConnection
(
urlJar
,
"sa"
,
"sa"
);
...
...
@@ -223,10 +233,35 @@ public class TestFileSystem extends TestBase {
FileUtils
.
delete
(
getBaseDir
()
+
"/fsJar.zip"
);
}
private
void
testReadOnly
(
final
String
f
)
throws
IOException
{
new
AssertThrows
(
DbException
.
class
)
{
public
void
test
()
{
FileUtils
.
newOutputStream
(
f
,
false
);
}};
new
AssertThrows
(
DbException
.
class
)
{
public
void
test
()
{
FileUtils
.
moveTo
(
f
,
f
);
}};
new
AssertThrows
(
DbException
.
class
)
{
public
void
test
()
{
FileUtils
.
moveTo
(
f
,
f
);
}};
new
AssertThrows
(
IOException
.
class
)
{
public
void
test
()
throws
IOException
{
FileUtils
.
createTempFile
(
f
,
".tmp"
,
false
,
false
);
}};
final
FileChannel
channel
=
FileUtils
.
open
(
f
,
"r"
);
new
AssertThrows
(
IOException
.
class
)
{
public
void
test
()
throws
IOException
{
channel
.
write
(
ByteBuffer
.
allocate
(
1
));
}};
new
AssertThrows
(
IOException
.
class
)
{
public
void
test
()
throws
IOException
{
channel
.
truncate
(
0
);
}};
assertTrue
(
null
==
channel
.
tryLock
());
channel
.
force
(
false
);
channel
.
close
();
}
private
void
testUserHome
()
{
String
fileName
=
FileUtils
.
toRealPath
(
"~/test"
);
String
userDir
=
System
.
getProperty
(
"user.home"
).
replace
(
'\\'
,
'/'
);
assertTrue
(
fileName
.
startsWith
(
userDir
));
assertTrue
(
FileUtils
.
toRealPath
(
"~/test"
).
startsWith
(
userDir
));
assertTrue
(
FileUtils
.
toRealPath
(
"file:~/test"
).
startsWith
(
userDir
));
}
private
void
testFileSystem
(
String
fsBase
)
throws
Exception
{
...
...
@@ -313,6 +348,9 @@ public class TestFileSystem extends TestBase {
new
AssertThrows
(
UnsupportedOperationException
.
class
)
{
public
void
test
()
throws
IOException
{
channel
.
transferTo
(
0
,
0
,
channel
);
}};
new
AssertThrows
(
UnsupportedOperationException
.
class
)
{
public
void
test
()
throws
IOException
{
channel
.
lock
();
}};
channel
.
close
();
FileUtils
.
delete
(
fileName
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论