Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e78bb783
提交
e78bb783
authored
9月 12, 2011
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improved compatibility with the Java 7 FileSystem abstraction.
上级
6992e031
隐藏空白字符变更
内嵌
并排
正在显示
16 个修改的文件
包含
130 行增加
和
181 行删除
+130
-181
FileLock.java
h2/src/main/org/h2/store/FileLock.java
+17
-24
FileStore.java
h2/src/main/org/h2/store/FileStore.java
+5
-7
TestCsv.java
h2/src/test/org/h2/test/db/TestCsv.java
+19
-24
TestLinkedTable.java
h2/src/test/org/h2/test/db/TestLinkedTable.java
+2
-3
TestOpenClose.java
h2/src/test/org/h2/test/db/TestOpenClose.java
+4
-6
TestReadOnly.java
h2/src/test/org/h2/test/db/TestReadOnly.java
+2
-3
TestCompress.java
h2/src/test/org/h2/test/unit/TestCompress.java
+2
-3
TestFileLockSerialized.java
h2/src/test/org/h2/test/unit/TestFileLockSerialized.java
+2
-5
TestFileSystem.java
h2/src/test/org/h2/test/unit/TestFileSystem.java
+42
-50
TestPageStoreCoverage.java
h2/src/test/org/h2/test/unit/TestPageStoreCoverage.java
+2
-3
TestRecovery.java
h2/src/test/org/h2/test/unit/TestRecovery.java
+1
-2
TestTools.java
h2/src/test/org/h2/test/unit/TestTools.java
+5
-7
TestTraceSystem.java
h2/src/test/org/h2/test/unit/TestTraceSystem.java
+1
-2
FtpControl.java
h2/src/tools/org/h2/dev/ftp/server/FtpControl.java
+14
-17
FtpData.java
h2/src/tools/org/h2/dev/ftp/server/FtpData.java
+4
-5
FtpServer.java
h2/src/tools/org/h2/dev/ftp/server/FtpServer.java
+8
-20
没有找到文件。
h2/src/main/org/h2/store/FileLock.java
浏览文件 @
e78bb783
...
...
@@ -21,7 +21,6 @@ import org.h2.engine.SessionRemote;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.message.TraceSystem
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.util.IOUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.NetUtils
;
...
...
@@ -79,11 +78,6 @@ public class FileLock implements Runnable {
*/
private
volatile
ServerSocket
serverSocket
;
/**
* The file system.
*/
private
FileSystem
fs
;
/**
* The number of milliseconds to sleep after checking a file.
*/
...
...
@@ -125,7 +119,6 @@ public class FileLock implements Runnable {
* @throws DbException if locking was not successful
*/
public
synchronized
void
lock
(
int
fileLockMethod
)
{
this
.
fs
=
FileSystem
.
getInstance
(
fileName
);
checkServer
();
if
(
locked
)
{
DbException
.
throwInternalError
(
"already locked"
);
...
...
@@ -157,7 +150,7 @@ public class FileLock implements Runnable {
try
{
if
(
fileName
!=
null
)
{
if
(
load
().
equals
(
properties
))
{
f
s
.
delete
(
fileName
);
IOUtil
s
.
delete
(
fileName
);
}
}
if
(
serverSocket
!=
null
)
{
...
...
@@ -201,13 +194,13 @@ public class FileLock implements Runnable {
*/
public
Properties
save
()
{
try
{
OutputStream
out
=
f
s
.
openFileOutputStream
(
fileName
,
false
);
OutputStream
out
=
IOUtil
s
.
openFileOutputStream
(
fileName
,
false
);
try
{
properties
.
store
(
out
,
MAGIC
);
}
finally
{
out
.
close
();
}
lastWrite
=
f
s
.
getLastModified
(
fileName
);
lastWrite
=
IOUtil
s
.
getLastModified
(
fileName
);
if
(
trace
.
isDebugEnabled
())
{
trace
.
debug
(
"save "
+
properties
);
}
...
...
@@ -271,7 +264,7 @@ public class FileLock implements Runnable {
private
void
waitUntilOld
()
{
for
(
int
i
=
0
;
i
<
2
*
TIME_GRANULARITY
/
SLEEP_GAP
;
i
++)
{
long
last
=
f
s
.
getLastModified
(
fileName
);
long
last
=
IOUtil
s
.
getLastModified
(
fileName
);
long
dist
=
System
.
currentTimeMillis
()
-
last
;
if
(
dist
<
-
TIME_GRANULARITY
)
{
// lock file modified in the future -
...
...
@@ -303,8 +296,8 @@ public class FileLock implements Runnable {
private
void
lockSerialized
()
{
method
=
SERIALIZED
;
IOUtils
.
createDirectories
(
f
s
.
getParent
(
fileName
));
if
(
f
s
.
createNewFile
(
fileName
))
{
IOUtils
.
createDirectories
(
IOUtil
s
.
getParent
(
fileName
));
if
(
IOUtil
s
.
createNewFile
(
fileName
))
{
properties
=
new
SortedProperties
();
properties
.
setProperty
(
"method"
,
String
.
valueOf
(
method
));
setUniqueId
();
...
...
@@ -326,8 +319,8 @@ public class FileLock implements Runnable {
properties
=
new
SortedProperties
();
properties
.
setProperty
(
"method"
,
String
.
valueOf
(
method
));
setUniqueId
();
IOUtils
.
createDirectories
(
f
s
.
getParent
(
fileName
));
if
(!
f
s
.
createNewFile
(
fileName
))
{
IOUtils
.
createDirectories
(
IOUtil
s
.
getParent
(
fileName
));
if
(!
IOUtil
s
.
createNewFile
(
fileName
))
{
waitUntilOld
();
String
m2
=
load
().
getProperty
(
"method"
,
FILE
);
if
(!
m2
.
equals
(
FILE
))
{
...
...
@@ -338,8 +331,8 @@ public class FileLock implements Runnable {
if
(!
load
().
equals
(
properties
))
{
throw
getExceptionAlreadyInUse
(
"Locked by another process"
);
}
f
s
.
delete
(
fileName
);
if
(!
f
s
.
createNewFile
(
fileName
))
{
IOUtil
s
.
delete
(
fileName
);
if
(!
IOUtil
s
.
createNewFile
(
fileName
))
{
throw
getExceptionFatal
(
"Another process was faster"
,
null
);
}
}
...
...
@@ -363,10 +356,10 @@ public class FileLock implements Runnable {
// if this returns 127.0.0.1,
// the computer is probably not networked
ipAddress
=
NetUtils
.
getLocalAddress
();
IOUtils
.
createDirectories
(
f
s
.
getParent
(
fileName
));
if
(!
f
s
.
createNewFile
(
fileName
))
{
IOUtils
.
createDirectories
(
IOUtil
s
.
getParent
(
fileName
));
if
(!
IOUtil
s
.
createNewFile
(
fileName
))
{
waitUntilOld
();
long
read
=
f
s
.
getLastModified
(
fileName
);
long
read
=
IOUtil
s
.
getLastModified
(
fileName
);
Properties
p2
=
load
();
String
m2
=
p2
.
getProperty
(
"method"
,
SOCKET
);
if
(
m2
.
equals
(
FILE
))
{
...
...
@@ -400,11 +393,11 @@ public class FileLock implements Runnable {
throw
getExceptionFatal
(
"IOException"
,
null
);
}
}
if
(
read
!=
f
s
.
getLastModified
(
fileName
))
{
if
(
read
!=
IOUtil
s
.
getLastModified
(
fileName
))
{
throw
getExceptionFatal
(
"Concurrent update"
,
null
);
}
f
s
.
delete
(
fileName
);
if
(!
f
s
.
createNewFile
(
fileName
))
{
IOUtil
s
.
delete
(
fileName
);
if
(!
IOUtil
s
.
createNewFile
(
fileName
))
{
throw
getExceptionFatal
(
"Another process was faster"
,
null
);
}
}
...
...
@@ -487,7 +480,7 @@ public class FileLock implements Runnable {
while
(
fileName
!=
null
)
{
// trace.debug("watchdog check");
try
{
if
(!
fs
.
exists
(
fileName
)
||
f
s
.
getLastModified
(
fileName
)
!=
lastWrite
)
{
if
(!
IOUtils
.
exists
(
fileName
)
||
IOUtil
s
.
getLastModified
(
fileName
)
!=
lastWrite
)
{
save
();
}
Thread
.
sleep
(
sleep
);
...
...
h2/src/main/org/h2/store/FileStore.java
浏览文件 @
e78bb783
...
...
@@ -14,7 +14,6 @@ import org.h2.engine.Constants;
import
org.h2.message.DbException
;
import
org.h2.security.SecureFileStore
;
import
org.h2.store.fs.FileObject
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.util.IOUtils
;
import
org.h2.util.TempFileDeleter
;
import
org.h2.util.Utils
;
...
...
@@ -71,7 +70,6 @@ public class FileStore {
* @param mode the access mode ("r", "rw", "rws", "rwd")
*/
protected
FileStore
(
DataHandler
handler
,
String
name
,
String
mode
)
{
FileSystem
fs
=
FileSystem
.
getInstance
(
name
);
this
.
handler
=
handler
;
this
.
name
=
name
;
this
.
mode
=
mode
;
...
...
@@ -79,14 +77,14 @@ public class FileStore {
tempFileDeleter
=
handler
.
getTempFileDeleter
();
}
try
{
boolean
exists
=
f
s
.
exists
(
name
);
if
(
exists
&&
!
f
s
.
canWrite
(
name
))
{
boolean
exists
=
IOUtil
s
.
exists
(
name
);
if
(
exists
&&
!
IOUtil
s
.
canWrite
(
name
))
{
mode
=
"r"
;
this
.
mode
=
mode
;
}
else
{
IOUtils
.
createDirectories
(
f
s
.
getParent
(
name
));
IOUtils
.
createDirectories
(
IOUtil
s
.
getParent
(
name
));
}
file
=
f
s
.
openFileObject
(
name
,
mode
);
file
=
IOUtil
s
.
openFileObject
(
name
,
mode
);
if
(
mode
.
length
()
>
2
)
{
synchronousMode
=
true
;
}
...
...
@@ -494,7 +492,7 @@ public class FileStore {
*/
public
void
openFile
()
throws
IOException
{
if
(
file
==
null
)
{
file
=
FileSystem
.
getInstance
(
name
)
.
openFileObject
(
name
,
mode
);
file
=
IOUtils
.
openFileObject
(
name
,
mode
);
file
.
seek
(
filePos
);
}
}
...
...
h2/src/test/org/h2/test/db/TestCsv.java
浏览文件 @
e78bb783
...
...
@@ -24,8 +24,6 @@ import java.util.Random;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Constants
;
import
org.h2.store.fs.FileObject
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Csv
;
import
org.h2.util.IOUtils
;
...
...
@@ -223,17 +221,16 @@ public class TestCsv extends TestBase {
deleteDb
(
"csv"
);
String
fileName
=
getBaseDir
()
+
"/testNull.csv"
;
FileSystem
fs
=
FileSystem
.
getInstance
(
fileName
);
fs
.
delete
(
fileName
);
IOUtils
.
delete
(
fileName
);
FileObject
file
=
fs
.
openFileObject
(
fileName
,
"rw"
);
OutputStream
out
=
IOUtils
.
openFileOutputStream
(
fileName
,
false
);
String
csvContent
=
"\"A\",\"B\",\"C\",\"D\"\n\\N,\"\",\"\\N\","
;
byte
[]
b
=
csvContent
.
getBytes
(
"UTF-8"
);
file
.
write
(
b
,
0
,
b
.
length
);
file
.
close
();
out
.
write
(
b
,
0
,
b
.
length
);
out
.
close
();
Csv
csv
=
Csv
.
getInstance
();
csv
.
setNullString
(
"\\N"
);
ResultSet
rs
=
csv
.
read
(
file
.
getName
()
,
null
,
"UTF8"
);
ResultSet
rs
=
csv
.
read
(
file
Name
,
null
,
"UTF8"
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
assertEquals
(
4
,
meta
.
getColumnCount
());
assertEquals
(
"A"
,
meta
.
getColumnLabel
(
1
));
...
...
@@ -251,16 +248,16 @@ public class TestCsv extends TestBase {
Connection
conn
=
getConnection
(
"csv"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"call csvwrite('"
+
file
.
getName
()
+
stat
.
execute
(
"call csvwrite('"
+
file
Name
+
"', 'select NULL as a, '''' as b, ''\\N'' as c, NULL as d', 'UTF8', ',', '\"', NULL, '\\N', '\n')"
);
InputStreamReader
reader
=
new
InputStreamReader
(
f
s
.
openFileInputStream
(
fileName
));
InputStreamReader
reader
=
new
InputStreamReader
(
IOUtil
s
.
openFileInputStream
(
fileName
));
// on read, an empty string is treated like null,
// but on write a null is always written with the nullString
String
data
=
IOUtils
.
readStringAndClose
(
reader
,
-
1
);
assertEquals
(
csvContent
+
"\\N"
,
data
.
trim
());
conn
.
close
();
f
s
.
delete
(
fileName
);
IOUtil
s
.
delete
(
fileName
);
}
private
void
testRandomData
()
throws
SQLException
{
...
...
@@ -336,12 +333,11 @@ public class TestCsv extends TestBase {
private
void
testFieldDelimiter
()
throws
Exception
{
String
fileName
=
getBaseDir
()
+
"/test.csv"
;
String
fileName2
=
getBaseDir
()
+
"/test2.csv"
;
FileSystem
fs
=
FileSystem
.
getInstance
(
fileName
);
fs
.
delete
(
fileName
);
FileObject
file
=
fs
.
openFileObject
(
fileName
,
"rw"
);
IOUtils
.
delete
(
fileName
);
OutputStream
out
=
IOUtils
.
openFileOutputStream
(
fileName
,
false
);
byte
[]
b
=
"'A'; 'B'\n\'It\\'s nice\'; '\nHello\\*\n'"
.
getBytes
();
file
.
write
(
b
,
0
,
b
.
length
);
file
.
close
();
out
.
write
(
b
,
0
,
b
.
length
);
out
.
close
();
Connection
conn
=
getConnection
(
"csv"
);
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
fileName
+
"', null, null, ';', '''', '\\')"
);
...
...
@@ -367,8 +363,8 @@ public class TestCsv extends TestBase {
assertEquals
(
"\nHello*\n"
,
rs
.
getString
(
2
));
assertFalse
(
rs
.
next
());
conn
.
close
();
f
s
.
delete
(
fileName
);
f
s
.
delete
(
fileName2
);
IOUtil
s
.
delete
(
fileName
);
IOUtil
s
.
delete
(
fileName2
);
}
private
void
testPipe
()
throws
SQLException
{
...
...
@@ -414,12 +410,11 @@ public class TestCsv extends TestBase {
private
void
testRead
()
throws
Exception
{
String
fileName
=
getBaseDir
()
+
"/test.csv"
;
FileSystem
fs
=
FileSystem
.
getInstance
(
fileName
);
fs
.
delete
(
fileName
);
FileObject
file
=
fs
.
openFileObject
(
fileName
,
"rw"
);
IOUtils
.
delete
(
fileName
);
OutputStream
out
=
IOUtils
.
openFileOutputStream
(
fileName
,
false
);
byte
[]
b
=
"a,b,c,d\n201,-2,0,18\n, \"abc\"\"\" ,,\"\"\n 1 ,2 , 3, 4 \n5, 6, 7, 8"
.
getBytes
();
file
.
write
(
b
,
0
,
b
.
length
);
file
.
close
();
out
.
write
(
b
,
0
,
b
.
length
);
out
.
close
();
ResultSet
rs
=
Csv
.
getInstance
().
read
(
fileName
,
null
,
"UTF8"
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
assertEquals
(
4
,
meta
.
getColumnCount
());
...
...
@@ -456,7 +451,7 @@ public class TestCsv extends TestBase {
// 201,2,0,18
// 201,2,0,18
// 201,2,0,18
f
s
.
delete
(
fileName
);
IOUtil
s
.
delete
(
fileName
);
}
private
void
testWriteRead
()
throws
SQLException
{
...
...
h2/src/test/org/h2/test/db/TestLinkedTable.java
浏览文件 @
e78bb783
...
...
@@ -16,7 +16,6 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.sql.Timestamp
;
import
org.h2.constant.ErrorCode
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
...
...
@@ -637,8 +636,8 @@ public class TestLinkedTable extends TestBase {
for
(
String
file
:
files
)
{
String
name
=
IOUtils
.
getFileName
(
file
);
if
((
name
.
startsWith
(
"testLinkedTableInReadOnlyDb"
))
&&
(!
name
.
endsWith
(
".trace.db"
)))
{
FileSystem
.
getInstance
(
file
)
.
setReadOnly
(
file
);
boolean
isReadOnly
=
FileSystem
.
getInstance
(
file
)
.
isReadOnly
(
file
);
IOUtils
.
setReadOnly
(
file
);
boolean
isReadOnly
=
IOUtils
.
isReadOnly
(
file
);
if
(!
isReadOnly
)
{
fail
(
"File "
+
file
+
" is not read only. Can't test it."
);
}
...
...
h2/src/test/org/h2/test/db/TestOpenClose.java
浏览文件 @
e78bb783
...
...
@@ -12,15 +12,13 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.constant.ErrorCode
;
import
org.h2.store.fs.FileObject
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Restore
;
import
org.h2.util.Task
;
import
org.h2.util.IOUtils
;
import
org.h2.util.Task
;
/**
* Tests opening and closing a database.
...
...
@@ -64,17 +62,17 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
if
(
config
.
memory
||
config
.
reopen
)
{
return
;
}
FileSystem
.
getInstance
(
"split:"
)
.
delete
(
"split:"
+
getBaseDir
()
+
"/openClose2.h2.db"
);
IOUtils
.
delete
(
"split:"
+
getBaseDir
()
+
"/openClose2.h2.db"
);
Connection
conn
;
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:split:18:"
+
getBaseDir
()
+
"/openClose2"
);
conn
.
createStatement
().
execute
(
"create table test(id int, name varchar) as select 1, space(1000000)"
);
conn
.
close
();
FileObject
f
=
FileSystem
.
getInstance
(
getBaseDir
())
.
openFileObject
(
getBaseDir
()
+
"/openClose2.h2.db.1.part"
,
"rw"
);
FileObject
f
=
IOUtils
.
openFileObject
(
getBaseDir
()
+
"/openClose2.h2.db.1.part"
,
"rw"
);
f
.
setFileLength
(
f
.
length
()
*
2
);
f
.
close
();
assertThrows
(
ErrorCode
.
IO_EXCEPTION_2
,
this
).
getConnection
(
"jdbc:h2:split:18:"
+
getBaseDir
()
+
"/openClose2"
);
FileSystem
.
getInstance
(
"split:"
)
.
delete
(
"split:"
+
getBaseDir
()
+
"/openClose2.h2.db"
);
IOUtils
.
delete
(
"split:"
+
getBaseDir
()
+
"/openClose2.h2.db"
);
}
private
void
testCloseDelay
()
throws
Exception
{
...
...
h2/src/test/org/h2/test/db/TestReadOnly.java
浏览文件 @
e78bb783
...
...
@@ -15,8 +15,8 @@ import java.sql.Statement;
import
java.util.ArrayList
;
import
org.h2.constant.ErrorCode
;
import
org.h2.store.FileLister
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
/**
* Test for the read-only database feature.
...
...
@@ -127,10 +127,9 @@ public class TestReadOnly extends TestBase {
}
private
void
setReadOnly
()
{
FileSystem
fs
=
FileSystem
.
getInstance
(
getBaseDir
());
ArrayList
<
String
>
list
=
FileLister
.
getDatabaseFiles
(
getBaseDir
(),
"readonly"
,
true
);
for
(
String
fileName
:
list
)
{
f
s
.
setReadOnly
(
fileName
);
IOUtil
s
.
setReadOnly
(
fileName
);
}
}
...
...
h2/src/test/org/h2/test/unit/TestCompress.java
浏览文件 @
e78bb783
...
...
@@ -20,7 +20,6 @@ import java.util.Random;
import
org.h2.compress.CompressLZF
;
import
org.h2.compress.Compressor
;
import
org.h2.engine.Constants
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.tools.CompressTool
;
import
org.h2.util.IOUtils
;
...
...
@@ -158,7 +157,7 @@ public class TestCompress extends TestBase {
for
(
int
j
=
0
;
j
<
4
;
j
++)
{
long
time
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
InputStream
in
=
FileSystem
.
getInstance
(
"memFS:"
)
.
openFileInputStream
(
"memFS:compress.h2.db"
);
InputStream
in
=
IOUtils
.
openFileInputStream
(
"memFS:compress.h2.db"
);
int
total
=
0
;
while
(
true
)
{
int
len
=
in
.
read
(
buff
);
...
...
@@ -174,7 +173,7 @@ public class TestCompress extends TestBase {
for
(
int
j
=
0
;
j
<
4
;
j
++)
{
ArrayList
<
byte
[]>
comp
=
New
.
arrayList
();
InputStream
in
=
FileSystem
.
getInstance
(
"memFS:"
)
.
openFileInputStream
(
"memFS:compress.h2.db"
);
InputStream
in
=
IOUtils
.
openFileInputStream
(
"memFS:compress.h2.db"
);
while
(
true
)
{
int
len
=
in
.
read
(
buff
);
if
(
len
<
0
)
{
...
...
h2/src/test/org/h2/test/unit/TestFileLockSerialized.java
浏览文件 @
e78bb783
...
...
@@ -17,7 +17,6 @@ import java.util.Arrays;
import
java.util.List
;
import
org.h2.constant.ErrorCode
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
import
org.h2.util.SortedProperties
;
...
...
@@ -605,9 +604,7 @@ public class TestFileLockSerialized extends TestBase {
stat
.
execute
(
"insert into test values(0)"
);
conn
.
close
();
FileSystem
fs
=
FileSystem
.
getInstance
(
getBaseDir
());
List
<
String
>
filesWithoutSerialized
=
Arrays
.
asList
(
fs
.
listFiles
(
getBaseDir
()));
List
<
String
>
filesWithoutSerialized
=
Arrays
.
asList
(
IOUtils
.
listFiles
(
getBaseDir
()));
deleteDb
(
"fileLockSerialized"
);
// with serialized
...
...
@@ -619,7 +616,7 @@ public class TestFileLockSerialized extends TestBase {
stat
.
execute
(
"insert into test values(0)"
);
conn
.
close
();
List
<
String
>
filesWithSerialized
=
Arrays
.
asList
(
f
s
.
listFiles
(
getBaseDir
()));
List
<
String
>
filesWithSerialized
=
Arrays
.
asList
(
IOUtil
s
.
listFiles
(
getBaseDir
()));
if
(
filesWithoutSerialized
.
size
()
!=
filesWithSerialized
.
size
())
{
for
(
int
i
=
0
;
i
<
filesWithoutSerialized
.
size
();
i
++)
{
if
(!
filesWithSerialized
.
contains
(
filesWithoutSerialized
.
get
(
i
)))
{
...
...
h2/src/test/org/h2/test/unit/TestFileSystem.java
浏览文件 @
e78bb783
...
...
@@ -20,7 +20,6 @@ import java.sql.Statement;
import
java.util.Random
;
import
org.h2.dev.fs.FileSystemCrypt
;
import
org.h2.store.fs.FileObject
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.store.fs.FileSystemMemory
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Backup
;
...
...
@@ -55,7 +54,7 @@ public class TestFileSystem extends TestBase {
testDatabaseInJar
();
// set default part size to 1 << 10
String
f
=
"split:10:"
+
getBaseDir
()
+
"/fs"
;
FileSystem
.
getInstance
(
f
)
.
getCanonicalPath
(
f
);
IOUtils
.
getCanonicalPath
(
f
);
testFileSystem
(
getBaseDir
()
+
"/fs"
);
testFileSystem
(
FileSystemMemory
.
PREFIX
);
FileSystemDatabase
fs
=
FileSystemDatabase
.
register
(
"jdbc:h2:mem:fs"
);
...
...
@@ -85,10 +84,8 @@ public class TestFileSystem extends TestBase {
}
private
void
testMemFsDir
()
throws
IOException
{
String
dir
=
"memFS:data/test"
;
FileSystem
fs
=
FileSystem
.
getInstance
(
dir
);
fs
.
openFileOutputStream
(
"memFS:data/test/a.txt"
,
false
).
close
();
String
[]
list
=
fs
.
listFiles
(
"memFS:data/test"
);
IOUtils
.
openFileOutputStream
(
"memFS:data/test/a.txt"
,
false
).
close
();
String
[]
list
=
IOUtils
.
listFiles
(
"memFS:data/test"
);
assertEquals
(
1
,
list
.
length
);
IOUtils
.
deleteRecursive
(
"memFS:"
,
false
);
}
...
...
@@ -173,12 +170,11 @@ public class TestFileSystem extends TestBase {
conn
.
close
();
deleteDb
(
"fsJar"
);
FileSystem
fs
=
FileSystem
.
getInstance
(
"zip:"
+
getBaseDir
()
+
"/fsJar.zip"
);
for
(
String
f
:
fs
.
listFiles
(
"zip:"
+
getBaseDir
()
+
"/fsJar.zip"
))
{
assertTrue
(
fs
.
isAbsolute
(
f
));
assertTrue
(!
fs
.
isDirectory
(
f
));
assertTrue
(
fs
.
length
(
f
)
>
0
);
assertTrue
(
f
.
endsWith
(
fs
.
getFileName
(
f
)));
for
(
String
f
:
IOUtils
.
listFiles
(
"zip:"
+
getBaseDir
()
+
"/fsJar.zip"
))
{
assertTrue
(
IOUtils
.
isAbsolute
(
f
));
assertTrue
(!
IOUtils
.
isDirectory
(
f
));
assertTrue
(
IOUtils
.
length
(
f
)
>
0
);
assertTrue
(
f
.
endsWith
(
IOUtils
.
getFileName
(
f
)));
}
String
urlJar
=
"jdbc:h2:zip:"
+
getBaseDir
()
+
"/fsJar.zip!/fsJar"
;
conn
=
DriverManager
.
getConnection
(
urlJar
,
"sa"
,
"sa"
);
...
...
@@ -199,8 +195,7 @@ public class TestFileSystem extends TestBase {
}
private
void
testUserHome
()
{
FileSystem
fs
=
FileSystem
.
getInstance
(
"~/test"
);
String
fileName
=
fs
.
getCanonicalPath
(
"~/test"
);
String
fileName
=
IOUtils
.
getCanonicalPath
(
"~/test"
);
String
userDir
=
System
.
getProperty
(
"user.home"
);
assertTrue
(
fileName
.
startsWith
(
userDir
));
}
...
...
@@ -212,17 +207,16 @@ public class TestFileSystem extends TestBase {
}
private
void
testSimple
(
String
fsBase
)
throws
Exception
{
FileSystem
fs
=
FileSystem
.
getInstance
(
fsBase
);
long
time
=
System
.
currentTimeMillis
();
for
(
String
s
:
f
s
.
listFiles
(
fsBase
))
{
f
s
.
delete
(
s
);
for
(
String
s
:
IOUtil
s
.
listFiles
(
fsBase
))
{
IOUtil
s
.
delete
(
s
);
}
IOUtils
.
createDirectories
(
fsBase
+
"/test"
);
f
s
.
delete
(
fsBase
+
"/test"
);
f
s
.
delete
(
fsBase
+
"/test2"
);
assertTrue
(
f
s
.
createNewFile
(
fsBase
+
"/test"
));
assertTrue
(
f
s
.
canWrite
(
fsBase
+
"/test"
));
FileObject
fo
=
f
s
.
openFileObject
(
fsBase
+
"/test"
,
"rw"
);
IOUtil
s
.
delete
(
fsBase
+
"/test"
);
IOUtil
s
.
delete
(
fsBase
+
"/test2"
);
assertTrue
(
IOUtil
s
.
createNewFile
(
fsBase
+
"/test"
));
assertTrue
(
IOUtil
s
.
canWrite
(
fsBase
+
"/test"
));
FileObject
fo
=
IOUtil
s
.
openFileObject
(
fsBase
+
"/test"
,
"rw"
);
byte
[]
buffer
=
new
byte
[
10000
];
Random
random
=
new
Random
(
1
);
random
.
nextBytes
(
buffer
);
...
...
@@ -232,36 +226,36 @@ public class TestFileSystem extends TestBase {
assertEquals
(
20000
,
fo
.
getFilePointer
());
assertThrows
(
EOFException
.
class
,
fo
).
readFully
(
buffer
,
0
,
1
);
assertEquals
(
fsBase
+
"/test"
,
fo
.
getName
().
replace
(
'\\'
,
'/'
));
assertEquals
(
"test"
,
f
s
.
getFileName
(
fo
.
getName
()));
assertEquals
(
fsBase
,
f
s
.
getParent
(
fo
.
getName
()).
replace
(
'\\'
,
'/'
));
assertEquals
(
"test"
,
IOUtil
s
.
getFileName
(
fo
.
getName
()));
assertEquals
(
fsBase
,
IOUtil
s
.
getParent
(
fo
.
getName
()).
replace
(
'\\'
,
'/'
));
fo
.
tryLock
();
fo
.
releaseLock
();
assertEquals
(
10000
,
fo
.
length
());
fo
.
close
();
assertEquals
(
10000
,
f
s
.
length
(
fsBase
+
"/test"
));
fo
=
f
s
.
openFileObject
(
fsBase
+
"/test"
,
"r"
);
assertEquals
(
10000
,
IOUtil
s
.
length
(
fsBase
+
"/test"
));
fo
=
IOUtil
s
.
openFileObject
(
fsBase
+
"/test"
,
"r"
);
byte
[]
test
=
new
byte
[
10000
];
fo
.
readFully
(
test
,
0
,
10000
);
assertEquals
(
buffer
,
test
);
assertThrows
(
IOException
.
class
,
fo
).
write
(
test
,
0
,
10
);
assertThrows
(
IOException
.
class
,
fo
).
setFileLength
(
10
);
fo
.
close
();
long
lastMod
=
f
s
.
getLastModified
(
fsBase
+
"/test"
);
long
lastMod
=
IOUtil
s
.
getLastModified
(
fsBase
+
"/test"
);
if
(
lastMod
<
time
-
1999
)
{
// at most 2 seconds difference
assertEquals
(
time
,
lastMod
);
}
assertEquals
(
10000
,
f
s
.
length
(
fsBase
+
"/test"
));
String
[]
list
=
f
s
.
listFiles
(
fsBase
);
assertEquals
(
10000
,
IOUtil
s
.
length
(
fsBase
+
"/test"
));
String
[]
list
=
IOUtil
s
.
listFiles
(
fsBase
);
assertEquals
(
1
,
list
.
length
);
assertTrue
(
list
[
0
].
endsWith
(
"test"
));
IOUtils
.
copy
(
fsBase
+
"/test"
,
fsBase
+
"/test3"
);
f
s
.
rename
(
fsBase
+
"/test3"
,
fsBase
+
"/test2"
);
assertTrue
(!
f
s
.
exists
(
fsBase
+
"/test3"
));
assertTrue
(
f
s
.
exists
(
fsBase
+
"/test2"
));
assertEquals
(
10000
,
f
s
.
length
(
fsBase
+
"/test2"
));
IOUtil
s
.
rename
(
fsBase
+
"/test3"
,
fsBase
+
"/test2"
);
assertTrue
(!
IOUtil
s
.
exists
(
fsBase
+
"/test3"
));
assertTrue
(
IOUtil
s
.
exists
(
fsBase
+
"/test2"
));
assertEquals
(
10000
,
IOUtil
s
.
length
(
fsBase
+
"/test2"
));
byte
[]
buffer2
=
new
byte
[
10000
];
InputStream
in
=
f
s
.
openFileInputStream
(
fsBase
+
"/test2"
);
InputStream
in
=
IOUtil
s
.
openFileInputStream
(
fsBase
+
"/test2"
);
int
pos
=
0
;
while
(
true
)
{
int
l
=
in
.
read
(
buffer2
,
pos
,
Math
.
min
(
10000
-
pos
,
1000
));
...
...
@@ -274,14 +268,14 @@ public class TestFileSystem extends TestBase {
assertEquals
(
10000
,
pos
);
assertEquals
(
buffer
,
buffer2
);
assertTrue
(
f
s
.
tryDelete
(
fsBase
+
"/test2"
));
f
s
.
delete
(
fsBase
+
"/test"
);
assertTrue
(
IOUtil
s
.
tryDelete
(
fsBase
+
"/test2"
));
IOUtil
s
.
delete
(
fsBase
+
"/test"
);
if
(
fsBase
.
indexOf
(
FileSystemMemory
.
PREFIX
)
<
0
&&
fsBase
.
indexOf
(
FileSystemMemory
.
PREFIX_LZF
)
<
0
)
{
IOUtils
.
createDirectories
(
fsBase
+
"/testDir"
);
assertTrue
(
f
s
.
isDirectory
(
fsBase
+
"/testDir"
));
assertTrue
(
IOUtil
s
.
isDirectory
(
fsBase
+
"/testDir"
));
if
(!
fsBase
.
startsWith
(
"jdbc:"
))
{
IOUtils
.
deleteRecursive
(
fsBase
+
"/testDir"
,
false
);
assertTrue
(!
f
s
.
exists
(
fsBase
+
"/testDir"
));
assertTrue
(!
IOUtil
s
.
exists
(
fsBase
+
"/testDir"
));
}
}
}
...
...
@@ -292,14 +286,13 @@ public class TestFileSystem extends TestBase {
private
void
testRandomAccess
(
String
fsBase
,
int
seed
)
throws
Exception
{
StringBuilder
buff
=
new
StringBuilder
();
FileSystem
fs
=
FileSystem
.
getInstance
(
fsBase
);
String
s
=
fs
.
createTempFile
(
fsBase
+
"/tmp"
,
".tmp"
,
false
,
false
);
String
s
=
IOUtils
.
createTempFile
(
fsBase
+
"/tmp"
,
".tmp"
,
false
,
false
);
File
file
=
new
File
(
TestBase
.
BASE_TEST_DIR
+
"/tmp"
);
file
.
getParentFile
().
mkdirs
();
file
.
delete
();
RandomAccessFile
ra
=
new
RandomAccessFile
(
file
,
"rw"
);
f
s
.
delete
(
s
);
FileObject
f
=
f
s
.
openFileObject
(
s
,
"rw"
);
IOUtil
s
.
delete
(
s
);
FileObject
f
=
IOUtil
s
.
openFileObject
(
s
,
"rw"
);
assertThrows
(
EOFException
.
class
,
f
).
readFully
(
new
byte
[
1
],
0
,
1
);
f
.
sync
();
Random
random
=
new
Random
(
seed
);
...
...
@@ -367,7 +360,7 @@ public class TestFileSystem extends TestBase {
f
.
close
();
ra
.
close
();
ra
=
new
RandomAccessFile
(
file
,
"rw"
);
f
=
f
s
.
openFileObject
(
s
,
"rw"
);
f
=
IOUtil
s
.
openFileObject
(
s
,
"rw"
);
assertEquals
(
ra
.
length
(),
f
.
length
());
break
;
}
...
...
@@ -381,22 +374,21 @@ public class TestFileSystem extends TestBase {
f
.
close
();
ra
.
close
();
file
.
delete
();
f
s
.
delete
(
s
);
IOUtil
s
.
delete
(
s
);
}
}
private
void
testTempFile
(
String
fsBase
)
throws
Exception
{
int
len
=
10000
;
FileSystem
fs
=
FileSystem
.
getInstance
(
fsBase
);
String
s
=
fs
.
createTempFile
(
fsBase
+
"/tmp"
,
".tmp"
,
false
,
false
);
OutputStream
out
=
fs
.
openFileOutputStream
(
s
,
false
);
String
s
=
IOUtils
.
createTempFile
(
fsBase
+
"/tmp"
,
".tmp"
,
false
,
false
);
OutputStream
out
=
IOUtils
.
openFileOutputStream
(
s
,
false
);
byte
[]
buffer
=
new
byte
[
len
];
out
.
write
(
buffer
);
out
.
close
();
out
=
f
s
.
openFileOutputStream
(
s
,
true
);
out
=
IOUtil
s
.
openFileOutputStream
(
s
,
true
);
out
.
write
(
1
);
out
.
close
();
InputStream
in
=
f
s
.
openFileInputStream
(
s
);
InputStream
in
=
IOUtil
s
.
openFileInputStream
(
s
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
assertEquals
(
0
,
in
.
read
());
}
...
...
@@ -404,7 +396,7 @@ public class TestFileSystem extends TestBase {
assertEquals
(-
1
,
in
.
read
());
in
.
close
();
out
.
close
();
f
s
.
delete
(
s
);
IOUtil
s
.
delete
(
s
);
}
}
h2/src/test/org/h2/test/unit/TestPageStoreCoverage.java
浏览文件 @
e78bb783
...
...
@@ -13,7 +13,6 @@ import java.sql.Statement;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.store.fs.FileObject
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Restore
;
import
org.h2.util.IOUtils
;
...
...
@@ -230,11 +229,11 @@ public class TestPageStoreCoverage extends TestBase {
stat
.
execute
(
"drop table if exists INFORMATION_SCHEMA.LOB_DATA"
);
stat
.
execute
(
"drop table if exists INFORMATION_SCHEMA.LOB_MAP"
);
conn
.
close
();
FileObject
f
=
FileSystem
.
getInstance
(
fileName
)
.
openFileObject
(
fileName
,
"rw"
);
FileObject
f
=
IOUtils
.
openFileObject
(
fileName
,
"rw"
);
// create a new database
conn
=
getConnection
(
"pageStore"
);
conn
.
close
();
f
=
FileSystem
.
getInstance
(
fileName
)
.
openFileObject
(
fileName
,
"rw"
);
f
=
IOUtils
.
openFileObject
(
fileName
,
"rw"
);
f
.
setFileLength
(
16
);
// create a new database
conn
=
getConnection
(
"pageStore"
);
...
...
h2/src/test/org/h2/test/unit/TestRecovery.java
浏览文件 @
e78bb783
...
...
@@ -15,7 +15,6 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
org.h2.engine.Constants
;
import
org.h2.store.fs.FileObject
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.tools.DeleteDbFiles
;
import
org.h2.tools.Recover
;
...
...
@@ -134,7 +133,7 @@ public class TestRecovery extends TestBase {
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int, name varchar) as select 1, 'Hello World1'"
);
conn
.
close
();
FileObject
f
=
FileSystem
.
getInstance
(
getBaseDir
())
.
openFileObject
(
getBaseDir
()
+
"/recovery.h2.db"
,
"rw"
);
FileObject
f
=
IOUtils
.
openFileObject
(
getBaseDir
()
+
"/recovery.h2.db"
,
"rw"
);
byte
[]
buff
=
new
byte
[
Constants
.
DEFAULT_PAGE_SIZE
];
while
(
f
.
getFilePointer
()
<
f
.
length
())
{
f
.
readFully
(
buff
,
0
,
buff
.
length
);
...
...
h2/src/test/org/h2/test/unit/TestTools.java
浏览文件 @
e78bb783
...
...
@@ -32,7 +32,6 @@ import java.util.Random;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.store.FileLister
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.test.trace.Player
;
import
org.h2.test.utils.AssertThrows
;
...
...
@@ -493,15 +492,14 @@ public class TestTools extends TestBase {
ConvertTraceFile
.
main
(
"-traceFile"
,
getBaseDir
()
+
"/toolsConvertTraceFile.trace.db"
,
"-javaClass"
,
getBaseDir
()
+
"/Test"
,
"-script"
,
getBaseDir
()
+
"/test.sql"
);
FileSystem
fs
=
FileSystem
.
getInstance
(
getBaseDir
());
fs
.
delete
(
getBaseDir
()
+
"/Test.java"
);
IOUtils
.
delete
(
getBaseDir
()
+
"/Test.java"
);
String
trace
=
getBaseDir
()
+
"/toolsConvertTraceFile.trace.db"
;
assertTrue
(
f
s
.
exists
(
trace
));
assertTrue
(
IOUtil
s
.
exists
(
trace
));
String
newTrace
=
getBaseDir
()
+
"/test.trace.db"
;
f
s
.
delete
(
newTrace
);
assertFalse
(
f
s
.
exists
(
newTrace
));
f
s
.
rename
(
trace
,
newTrace
);
IOUtil
s
.
delete
(
newTrace
);
assertFalse
(
IOUtil
s
.
exists
(
newTrace
));
IOUtil
s
.
rename
(
trace
,
newTrace
);
deleteDb
(
"toolsConvertTraceFile"
);
Player
.
main
(
getBaseDir
()
+
"/test.trace.db"
);
testTraceFile
(
url
);
...
...
h2/src/test/org/h2/test/unit/TestTraceSystem.java
浏览文件 @
e78bb783
...
...
@@ -9,7 +9,6 @@ package org.h2.test.unit;
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintStream
;
import
org.h2.message.TraceSystem
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
...
...
@@ -57,7 +56,7 @@ public class TestTraceSystem extends TestBase {
String
readOnlyFile
=
getBaseDir
()
+
"/readOnly.log"
;
IOUtils
.
delete
(
readOnlyFile
);
IOUtils
.
openFileOutputStream
(
readOnlyFile
,
false
).
close
();
FileSystem
.
getInstance
(
getBaseDir
())
.
setReadOnly
(
readOnlyFile
);
IOUtils
.
setReadOnly
(
readOnlyFile
);
TraceSystem
ts
=
new
TraceSystem
(
readOnlyFile
);
ts
.
setLevelFile
(
TraceSystem
.
INFO
);
ts
.
getTrace
(
"test"
).
info
(
"test"
);
...
...
h2/src/tools/org/h2/dev/ftp/server/FtpControl.java
浏览文件 @
e78bb783
...
...
@@ -15,7 +15,6 @@ import java.net.InetAddress;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
org.h2.engine.Constants
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.util.IOUtils
;
import
org.h2.util.StringUtils
;
...
...
@@ -27,7 +26,6 @@ public class FtpControl extends Thread {
private
static
final
String
SERVER_NAME
=
"Small FTP Server"
;
private
FtpServer
server
;
private
FileSystem
fs
;
private
Socket
control
;
private
FtpData
data
;
private
PrintWriter
output
;
...
...
@@ -42,7 +40,6 @@ public class FtpControl extends Thread {
FtpControl
(
Socket
control
,
FtpServer
server
,
boolean
stop
)
{
this
.
server
=
server
;
this
.
fs
=
server
.
getFileSystem
();
this
.
control
=
control
;
this
.
stop
=
stop
;
}
...
...
@@ -149,7 +146,7 @@ public class FtpControl extends Thread {
if
(
"CWD"
.
equals
(
command
))
{
String
path
=
getPath
(
param
);
String
fileName
=
getFileName
(
path
);
if
(
fs
.
exists
(
fileName
)
&&
f
s
.
isDirectory
(
fileName
))
{
if
(
IOUtils
.
exists
(
fileName
)
&&
IOUtil
s
.
isDirectory
(
fileName
))
{
if
(!
path
.
endsWith
(
"/"
))
{
path
+=
"/"
;
}
...
...
@@ -171,7 +168,7 @@ public class FtpControl extends Thread {
case
'D'
:
if
(
"DELE"
.
equals
(
command
))
{
String
fileName
=
getFileName
(
param
);
if
(!
readonly
&&
fs
.
exists
(
fileName
)
&&
!
fs
.
isDirectory
(
fileName
)
&&
f
s
.
tryDelete
(
fileName
))
{
if
(!
readonly
&&
IOUtils
.
exists
(
fileName
)
&&
!
IOUtils
.
isDirectory
(
fileName
)
&&
IOUtil
s
.
tryDelete
(
fileName
))
{
if
(
server
.
getAllowTask
()
&&
fileName
.
endsWith
(
FtpServer
.
TASK_SUFFIX
))
{
server
.
stopTask
(
fileName
);
}
...
...
@@ -197,7 +194,7 @@ public class FtpControl extends Thread {
}
}
else
if
(
"MDTM"
.
equals
(
command
))
{
String
fileName
=
getFileName
(
param
);
if
(
fs
.
exists
(
fileName
)
&&
!
f
s
.
isDirectory
(
fileName
))
{
if
(
IOUtils
.
exists
(
fileName
)
&&
!
IOUtil
s
.
isDirectory
(
fileName
))
{
reply
(
213
,
server
.
formatLastModified
(
fileName
));
}
else
{
reply
(
550
,
"Failed"
);
...
...
@@ -237,7 +234,7 @@ public class FtpControl extends Thread {
case
'R'
:
if
(
"RNFR"
.
equals
(
command
))
{
String
fileName
=
getFileName
(
param
);
if
(
f
s
.
exists
(
fileName
))
{
if
(
IOUtil
s
.
exists
(
fileName
))
{
renameFrom
=
fileName
;
reply
(
350
,
"Ok"
);
}
else
{
...
...
@@ -252,7 +249,7 @@ public class FtpControl extends Thread {
boolean
ok
=
false
;
if
(!
readonly
)
{
try
{
f
s
.
rename
(
fileOld
,
fileNew
);
IOUtil
s
.
rename
(
fileOld
,
fileNew
);
reply
(
250
,
"Ok"
);
ok
=
true
;
}
catch
(
Exception
e
)
{
...
...
@@ -265,10 +262,10 @@ public class FtpControl extends Thread {
}
}
else
if
(
"RETR"
.
equals
(
command
))
{
String
fileName
=
getFileName
(
param
);
if
(
fs
.
exists
(
fileName
)
&&
!
f
s
.
isDirectory
(
fileName
))
{
if
(
IOUtils
.
exists
(
fileName
)
&&
!
IOUtil
s
.
isDirectory
(
fileName
))
{
reply
(
150
,
"Starting transfer"
);
try
{
data
.
send
(
f
s
,
f
ileName
,
restart
);
data
.
send
(
fileName
,
restart
);
reply
(
226
,
"Ok"
);
}
catch
(
IOException
e
)
{
server
.
traceError
(
e
);
...
...
@@ -299,17 +296,17 @@ public class FtpControl extends Thread {
reply
(
500
,
"Not understood"
);
}
else
if
(
"SIZE"
.
equals
(
command
))
{
param
=
getFileName
(
param
);
if
(
fs
.
exists
(
param
)
&&
!
f
s
.
isDirectory
(
param
))
{
reply
(
250
,
String
.
valueOf
(
f
s
.
length
(
param
)));
if
(
IOUtils
.
exists
(
param
)
&&
!
IOUtil
s
.
isDirectory
(
param
))
{
reply
(
250
,
String
.
valueOf
(
IOUtil
s
.
length
(
param
)));
}
else
{
reply
(
500
,
"Failed"
);
}
}
else
if
(
"STOR"
.
equals
(
command
))
{
String
fileName
=
getFileName
(
param
);
if
(!
readonly
&&
!
fs
.
exists
(
fileName
)
||
!
f
s
.
isDirectory
(
fileName
))
{
if
(!
readonly
&&
!
IOUtils
.
exists
(
fileName
)
||
!
IOUtil
s
.
isDirectory
(
fileName
))
{
reply
(
150
,
"Starting transfer"
);
try
{
data
.
receive
(
f
s
,
f
ileName
);
data
.
receive
(
fileName
);
if
(
server
.
getAllowTask
()
&&
param
.
endsWith
(
FtpServer
.
TASK_SUFFIX
))
{
server
.
startTask
(
fileName
);
}
...
...
@@ -370,7 +367,7 @@ public class FtpControl extends Thread {
private
void
processRemoveDir
(
String
param
)
{
String
fileName
=
getFileName
(
param
);
if
(!
readonly
&&
fs
.
exists
(
fileName
)
&&
fs
.
isDirectory
(
fileName
)
&&
f
s
.
tryDelete
(
fileName
))
{
if
(!
readonly
&&
IOUtils
.
exists
(
fileName
)
&&
IOUtils
.
isDirectory
(
fileName
)
&&
IOUtil
s
.
tryDelete
(
fileName
))
{
reply
(
250
,
"Ok"
);
}
else
{
reply
(
500
,
"Failed"
);
...
...
@@ -387,10 +384,10 @@ public class FtpControl extends Thread {
private
void
processList
(
String
param
,
boolean
directories
)
throws
IOException
{
String
directory
=
getFileName
(
param
);
if
(!
f
s
.
exists
(
directory
))
{
if
(!
IOUtil
s
.
exists
(
directory
))
{
reply
(
450
,
"Directory does not exist"
);
return
;
}
else
if
(!
f
s
.
isDirectory
(
directory
))
{
}
else
if
(!
IOUtil
s
.
isDirectory
(
directory
))
{
reply
(
450
,
"Not a directory"
);
return
;
}
...
...
h2/src/tools/org/h2/dev/ftp/server/FtpData.java
浏览文件 @
e78bb783
...
...
@@ -12,7 +12,6 @@ import java.io.OutputStream;
import
java.net.InetAddress
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.util.IOUtils
;
/**
...
...
@@ -91,11 +90,11 @@ public class FtpData extends Thread {
* @param fs the target file system
* @param fileName the target file name
*/
synchronized
void
receive
(
FileSystem
fs
,
String
fileName
)
throws
IOException
{
synchronized
void
receive
(
String
fileName
)
throws
IOException
{
connect
();
try
{
InputStream
in
=
socket
.
getInputStream
();
OutputStream
out
=
f
s
.
openFileOutputStream
(
fileName
,
false
);
OutputStream
out
=
IOUtil
s
.
openFileOutputStream
(
fileName
,
false
);
IOUtils
.
copy
(
in
,
out
);
out
.
close
();
}
finally
{
...
...
@@ -112,11 +111,11 @@ public class FtpData extends Thread {
* @param fileName the source file name
* @param skip the number of bytes to skip
*/
synchronized
void
send
(
FileSystem
fs
,
String
fileName
,
long
skip
)
throws
IOException
{
synchronized
void
send
(
String
fileName
,
long
skip
)
throws
IOException
{
connect
();
try
{
OutputStream
out
=
socket
.
getOutputStream
();
InputStream
in
=
f
s
.
openFileInputStream
(
fileName
);
InputStream
in
=
IOUtil
s
.
openFileInputStream
(
fileName
);
IOUtils
.
skipFully
(
in
,
skip
);
IOUtils
.
copy
(
in
,
out
);
in
.
close
();
...
...
h2/src/tools/org/h2/dev/ftp/server/FtpServer.java
浏览文件 @
e78bb783
...
...
@@ -19,7 +19,6 @@ import java.util.HashMap;
import
java.util.Locale
;
import
java.util.Properties
;
import
org.h2.server.Service
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.tools.Server
;
import
org.h2.util.IOUtils
;
import
org.h2.util.NetUtils
;
...
...
@@ -79,7 +78,6 @@ public class FtpServer extends Tool implements Service {
private
String
readUserName
=
DEFAULT_READ
;
private
HashMap
<
String
,
Process
>
tasks
=
new
HashMap
<
String
,
Process
>();
private
FileSystem
fs
;
private
boolean
trace
;
private
boolean
allowTask
;
...
...
@@ -220,17 +218,17 @@ public class FtpServer extends Tool implements Service {
}
private
void
appendFile
(
StringBuilder
buff
,
String
fileName
)
{
buff
.
append
(
f
s
.
isDirectory
(
fileName
)
?
'd'
:
'-'
);
buff
.
append
(
IOUtil
s
.
isDirectory
(
fileName
)
?
'd'
:
'-'
);
buff
.
append
(
'r'
);
buff
.
append
(
f
s
.
canWrite
(
fileName
)
?
'w'
:
'-'
);
buff
.
append
(
IOUtil
s
.
canWrite
(
fileName
)
?
'w'
:
'-'
);
buff
.
append
(
"------- 1 owner group "
);
String
size
=
String
.
valueOf
(
f
s
.
length
(
fileName
));
String
size
=
String
.
valueOf
(
IOUtil
s
.
length
(
fileName
));
for
(
int
i
=
size
.
length
();
i
<
15
;
i
++)
{
buff
.
append
(
' '
);
}
buff
.
append
(
size
);
buff
.
append
(
' '
);
Date
now
=
new
Date
(),
mod
=
new
Date
(
f
s
.
getLastModified
(
fileName
));
Date
now
=
new
Date
(),
mod
=
new
Date
(
IOUtil
s
.
getLastModified
(
fileName
));
String
date
;
if
(
mod
.
after
(
now
)
||
Math
.
abs
((
now
.
getTime
()
-
mod
.
getTime
())
/
1000
/
60
/
60
/
24
)
>
180
)
{
synchronized
(
dateFormatOld
)
{
...
...
@@ -256,7 +254,7 @@ public class FtpServer extends Tool implements Service {
*/
String
formatLastModified
(
String
fileName
)
{
synchronized
(
dateFormat
)
{
return
dateFormat
.
format
(
new
Date
(
f
s
.
getLastModified
(
fileName
)));
return
dateFormat
.
format
(
new
Date
(
IOUtil
s
.
getLastModified
(
fileName
)));
}
}
...
...
@@ -293,8 +291,8 @@ public class FtpServer extends Tool implements Service {
*/
String
getDirectoryListing
(
String
directory
,
boolean
listDirectories
)
{
StringBuilder
buff
=
new
StringBuilder
();
for
(
String
fileName
:
f
s
.
listFiles
(
directory
))
{
if
(!
fs
.
isDirectory
(
fileName
)
||
(
f
s
.
isDirectory
(
fileName
)
&&
listDirectories
))
{
for
(
String
fileName
:
IOUtil
s
.
listFiles
(
directory
))
{
if
(!
IOUtils
.
isDirectory
(
fileName
)
||
(
IOUtil
s
.
isDirectory
(
fileName
)
&&
listDirectories
))
{
appendFile
(
buff
,
fileName
);
}
}
...
...
@@ -352,8 +350,7 @@ public class FtpServer extends Tool implements Service {
}
public
void
start
()
{
fs
=
FileSystem
.
getInstance
(
root
);
root
=
fs
.
getCanonicalPath
(
root
);
root
=
IOUtils
.
getCanonicalPath
(
root
);
IOUtils
.
createDirectories
(
root
);
serverSocket
=
NetUtils
.
createServerSocket
(
port
,
false
);
port
=
serverSocket
.
getLocalPort
();
...
...
@@ -511,15 +508,6 @@ public class FtpServer extends Tool implements Service {
p
.
destroy
();
}
/**
* Get the file system used by this FTP server.
*
* @return the file system
*/
FileSystem
getFileSystem
()
{
return
fs
;
}
/**
* Set the event listener. Only one listener can be registered.
*
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论