Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
bc763b82
Unverified
提交
bc763b82
authored
7 年前
作者:
Noel Grandin
提交者:
GitHub
7 年前
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #861 from igor-suhorukov/master
Avoid resource leak
上级
e0619d3a
40a8383f
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
147 行增加
和
157 行删除
+147
-157
BackupCommand.java
h2/src/main/org/h2/command/dml/BackupCommand.java
+30
-30
Backup.java
h2/src/main/org/h2/tools/Backup.java
+38
-38
ChangeFileEncryption.java
h2/src/main/org/h2/tools/ChangeFileEncryption.java
+26
-32
Restore.java
h2/src/main/org/h2/tools/Restore.java
+31
-31
Profiler.java
h2/src/main/org/h2/util/Profiler.java
+13
-17
SortedProperties.java
h2/src/main/org/h2/util/SortedProperties.java
+9
-9
没有找到文件。
h2/src/main/org/h2/command/dml/BackupCommand.java
浏览文件 @
bc763b82
...
@@ -64,40 +64,40 @@ public class BackupCommand extends Prepared {
...
@@ -64,40 +64,40 @@ public class BackupCommand extends Prepared {
}
}
String
name
=
db
.
getName
();
String
name
=
db
.
getName
();
name
=
FileUtils
.
getName
(
name
);
name
=
FileUtils
.
getName
(
name
);
OutputStream
zip
=
FileUtils
.
newOutputStream
(
fileName
,
false
);
try
(
OutputStream
zip
=
FileUtils
.
newOutputStream
(
fileName
,
false
))
{
ZipOutputStream
out
=
new
ZipOutputStream
(
zip
);
ZipOutputStream
out
=
new
ZipOutputStream
(
zip
);
db
.
flush
();
db
.
flush
();
if
(
db
.
getPageStore
()
!=
null
)
{
if
(
db
.
getPageStore
()
!=
null
)
{
String
fn
=
db
.
getName
()
+
Constants
.
SUFFIX_PAGE_FILE
;
String
fn
=
db
.
getName
()
+
Constants
.
SUFFIX_PAGE_FILE
;
backupPageStore
(
out
,
fn
,
db
.
getPageStore
());
backupPageStore
(
out
,
fn
,
db
.
getPageStore
());
}
}
// synchronize on the database, to avoid concurrent temp file
// synchronize on the database, to avoid concurrent temp file
// creation / deletion / backup
// creation / deletion / backup
String
base
=
FileUtils
.
getParent
(
db
.
getName
());
String
base
=
FileUtils
.
getParent
(
db
.
getName
());
synchronized
(
db
.
getLobSyncObject
())
{
synchronized
(
db
.
getLobSyncObject
())
{
String
prefix
=
db
.
getDatabasePath
();
String
prefix
=
db
.
getDatabasePath
();
String
dir
=
FileUtils
.
getParent
(
prefix
);
String
dir
=
FileUtils
.
getParent
(
prefix
);
dir
=
FileLister
.
getDir
(
dir
);
dir
=
FileLister
.
getDir
(
dir
);
ArrayList
<
String
>
fileList
=
FileLister
.
getDatabaseFiles
(
dir
,
name
,
true
);
ArrayList
<
String
>
fileList
=
FileLister
.
getDatabaseFiles
(
dir
,
name
,
true
);
for
(
String
n
:
fileList
)
{
for
(
String
n
:
fileList
)
{
if
(
n
.
endsWith
(
Constants
.
SUFFIX_LOB_FILE
))
{
if
(
n
.
endsWith
(
Constants
.
SUFFIX_LOB_FILE
))
{
backupFile
(
out
,
base
,
n
);
backupFile
(
out
,
base
,
n
);
}
}
if
(
n
.
endsWith
(
Constants
.
SUFFIX_MV_FILE
)
&&
mvStore
!=
null
)
{
if
(
n
.
endsWith
(
Constants
.
SUFFIX_MV_FILE
)
&&
mvStore
!=
null
)
{
MVStore
s
=
mvStore
.
getStore
();
MVStore
s
=
mvStore
.
getStore
();
boolean
before
=
s
.
getReuseSpace
();
boolean
before
=
s
.
getReuseSpace
();
s
.
setReuseSpace
(
false
);
s
.
setReuseSpace
(
false
);
try
{
try
{
InputStream
in
=
mvStore
.
getInputStream
();
InputStream
in
=
mvStore
.
getInputStream
();
backupFile
(
out
,
base
,
n
,
in
);
backupFile
(
out
,
base
,
n
,
in
);
}
finally
{
}
finally
{
s
.
setReuseSpace
(
before
);
s
.
setReuseSpace
(
before
);
}
}
}
}
}
}
}
out
.
close
();
}
}
out
.
close
();
zip
.
close
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
DbException
.
convertIOException
(
e
,
fileName
);
throw
DbException
.
convertIOException
(
e
,
fileName
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/Backup.java
浏览文件 @
bc763b82
...
@@ -128,47 +128,47 @@ public class Backup extends Tool {
...
@@ -128,47 +128,47 @@ public class Backup extends Tool {
OutputStream
fileOut
=
null
;
OutputStream
fileOut
=
null
;
try
{
try
{
fileOut
=
FileUtils
.
newOutputStream
(
zipFileName
,
false
);
fileOut
=
FileUtils
.
newOutputStream
(
zipFileName
,
false
);
ZipOutputStream
zipOut
=
new
ZipOutputStream
(
fileOut
);
try
(
ZipOutputStream
zipOut
=
new
ZipOutputStream
(
fileOut
))
{
String
base
=
""
;
String
base
=
""
;
for
(
String
fileName
:
list
)
{
for
(
String
fileName
:
list
)
{
if
(
allFiles
||
if
(
allFiles
||
fileName
.
endsWith
(
Constants
.
SUFFIX_PAGE_FILE
)
||
fileName
.
endsWith
(
Constants
.
SUFFIX_PAGE_FILE
)
||
fileName
.
endsWith
(
Constants
.
SUFFIX_MV_FILE
))
{
fileName
.
endsWith
(
Constants
.
SUFFIX_MV_FILE
))
{
base
=
FileUtils
.
getParent
(
fileName
);
base
=
FileUtils
.
getParent
(
fileName
);
break
;
break
;
}
}
}
}
for
(
String
fileName
:
list
)
{
for
(
String
fileName
:
list
)
{
String
f
=
FileUtils
.
toRealPath
(
fileName
);
String
f
=
FileUtils
.
toRealPath
(
fileName
);
if
(!
f
.
startsWith
(
base
))
{
if
(!
f
.
startsWith
(
base
))
{
DbException
.
throwInternalError
(
f
+
" does not start with "
+
base
);
DbException
.
throwInternalError
(
f
+
" does not start with "
+
base
);
}
}
if
(
f
.
endsWith
(
zipFileName
))
{
if
(
f
.
endsWith
(
zipFileName
))
{
continue
;
continue
;
}
}
if
(
FileUtils
.
isDirectory
(
fileName
))
{
if
(
FileUtils
.
isDirectory
(
fileName
))
{
continue
;
continue
;
}
}
f
=
f
.
substring
(
base
.
length
());
f
=
f
.
substring
(
base
.
length
()
);
f
=
BackupCommand
.
correctFileName
(
f
);
f
=
BackupCommand
.
correctFileName
(
f
);
ZipEntry
entry
=
new
ZipEntry
(
f
);
ZipEntry
entry
=
new
ZipEntry
(
f
);
zipOut
.
putNextEntry
(
entry
);
zipOut
.
putNextEntry
(
entry
)
;
InputStream
in
=
null
;
InputStream
in
=
null
;
try
{
try
{
in
=
FileUtils
.
newInputStream
(
fileName
);
in
=
FileUtils
.
newInputStream
(
fileName
);
IOUtils
.
copyAndCloseInput
(
in
,
zipOut
);
IOUtils
.
copyAndCloseInput
(
in
,
zipOut
);
}
catch
(
FileNotFoundException
e
)
{
}
catch
(
FileNotFoundException
e
)
{
// the file could have been deleted in the meantime
// the file could have been deleted in the meantime
// ignore this (in this case an empty file is created)
// ignore this (in this case an empty file is created)
}
finally
{
}
finally
{
IOUtils
.
closeSilently
(
in
);
IOUtils
.
closeSilently
(
in
);
}
}
zipOut
.
closeEntry
();
zipOut
.
closeEntry
();
if
(!
quiet
)
{
if
(!
quiet
)
{
out
.
println
(
"Processed: "
+
fileName
);
out
.
println
(
"Processed: "
+
fileName
);
}
}
}
}
}
zipOut
.
close
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
DbException
.
convertIOException
(
e
,
zipFileName
);
throw
DbException
.
convertIOException
(
e
,
zipFileName
);
}
finally
{
}
finally
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/ChangeFileEncryption.java
浏览文件 @
bc763b82
...
@@ -220,46 +220,40 @@ public class ChangeFileEncryption extends Tool {
...
@@ -220,46 +220,40 @@ public class ChangeFileEncryption extends Tool {
if
(
FileUtils
.
isDirectory
(
fileName
))
{
if
(
FileUtils
.
isDirectory
(
fileName
))
{
return
;
return
;
}
}
FileChannel
fileIn
=
FilePath
.
get
(
fileName
).
open
(
"r"
);
FileChannel
fileOut
=
null
;
String
temp
=
directory
+
"/temp.db"
;
String
temp
=
directory
+
"/temp.db"
;
try
{
try
(
FileChannel
fileIn
=
getFileChannel
(
fileName
,
"r"
,
decryptKey
)){
if
(
decryptKey
!=
null
)
{
try
(
InputStream
inStream
=
new
FileChannelInputStream
(
fileIn
,
true
))
{
fileIn
=
new
FilePathEncrypt
.
FileEncrypt
(
fileName
,
decryptKey
,
fileIn
);
FileUtils
.
delete
(
temp
);
}
try
(
OutputStream
outStream
=
new
FileChannelOutputStream
(
getFileChannel
(
temp
,
"rw"
,
encryptKey
),
true
))
{
InputStream
inStream
=
new
FileChannelInputStream
(
fileIn
,
true
);
byte
[]
buffer
=
new
byte
[
4
*
1024
];
FileUtils
.
delete
(
temp
);
long
remaining
=
fileIn
.
size
();
fileOut
=
FilePath
.
get
(
temp
).
open
(
"rw"
);
long
total
=
remaining
;
if
(
encryptKey
!=
null
)
{
long
time
=
System
.
nanoTime
();
fileOut
=
new
FilePathEncrypt
.
FileEncrypt
(
temp
,
encryptKey
,
fileOut
);
while
(
remaining
>
0
)
{
}
if
(!
quiet
&&
System
.
nanoTime
()
-
time
>
TimeUnit
.
SECONDS
.
toNanos
(
1
))
{
OutputStream
outStream
=
new
FileChannelOutputStream
(
fileOut
,
true
);
out
.
println
(
fileName
+
": "
+
(
100
-
100
*
remaining
/
total
)
+
"%"
);
byte
[]
buffer
=
new
byte
[
4
*
1024
];
time
=
System
.
nanoTime
();
long
remaining
=
fileIn
.
size
();
}
long
total
=
remaining
;
int
len
=
(
int
)
Math
.
min
(
buffer
.
length
,
remaining
);
long
time
=
System
.
nanoTime
();
len
=
inStream
.
read
(
buffer
,
0
,
len
);
while
(
remaining
>
0
)
{
outStream
.
write
(
buffer
,
0
,
len
);
if
(!
quiet
&&
System
.
nanoTime
()
-
time
>
TimeUnit
.
SECONDS
.
toNanos
(
1
))
{
remaining
-=
len
;
out
.
println
(
fileName
+
": "
+
(
100
-
100
*
remaining
/
total
)
+
"%"
);
}
time
=
System
.
nanoTime
();
}
}
int
len
=
(
int
)
Math
.
min
(
buffer
.
length
,
remaining
);
len
=
inStream
.
read
(
buffer
,
0
,
len
);
outStream
.
write
(
buffer
,
0
,
len
);
remaining
-=
len
;
}
inStream
.
close
();
outStream
.
close
();
}
finally
{
fileIn
.
close
();
if
(
fileOut
!=
null
)
{
fileOut
.
close
();
}
}
}
}
FileUtils
.
delete
(
fileName
);
FileUtils
.
delete
(
fileName
);
FileUtils
.
move
(
temp
,
fileName
);
FileUtils
.
move
(
temp
,
fileName
);
}
}
private
FileChannel
getFileChannel
(
String
fileName
,
String
r
,
byte
[]
decryptKey
)
throws
IOException
{
FileChannel
fileIn
=
FilePath
.
get
(
fileName
).
open
(
r
);
if
(
decryptKey
!=
null
)
{
fileIn
=
new
FilePathEncrypt
.
FileEncrypt
(
fileName
,
decryptKey
,
fileIn
);
}
return
fileIn
;
}
private
void
copy
(
String
fileName
,
FileStore
in
,
byte
[]
key
,
boolean
quiet
)
{
private
void
copy
(
String
fileName
,
FileStore
in
,
byte
[]
key
,
boolean
quiet
)
{
if
(
FileUtils
.
isDirectory
(
fileName
))
{
if
(
FileUtils
.
isDirectory
(
fileName
))
{
return
;
return
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/Restore.java
浏览文件 @
bc763b82
...
@@ -155,41 +155,41 @@ public class Restore extends Tool {
...
@@ -155,41 +155,41 @@ public class Restore extends Tool {
originalDbLen
=
originalDbName
.
length
();
originalDbLen
=
originalDbName
.
length
();
}
}
in
=
FileUtils
.
newInputStream
(
zipFileName
);
in
=
FileUtils
.
newInputStream
(
zipFileName
);
ZipInputStream
zipIn
=
new
ZipInputStream
(
in
);
try
(
ZipInputStream
zipIn
=
new
ZipInputStream
(
in
))
{
while
(
true
)
{
while
(
true
)
{
ZipEntry
entry
=
zipIn
.
getNextEntry
();
ZipEntry
entry
=
zipIn
.
getNextEntry
();
if
(
entry
==
null
)
{
if
(
entry
==
null
)
{
break
;
break
;
}
}
String
fileName
=
entry
.
getName
();
String
fileName
=
entry
.
getName
();
// restoring windows backups on linux and vice versa
// restoring windows backups on linux and vice versa
fileName
=
fileName
.
replace
(
'\\'
,
SysProperties
.
FILE_SEPARATOR
.
charAt
(
0
));
fileName
=
fileName
.
replace
(
'\\'
,
SysProperties
.
FILE_SEPARATOR
.
charAt
(
0
));
fileName
=
fileName
.
replace
(
'/'
,
SysProperties
.
FILE_SEPARATOR
.
charAt
(
0
));
fileName
=
fileName
.
replace
(
'/'
,
SysProperties
.
FILE_SEPARATOR
.
charAt
(
0
));
if
(
fileName
.
startsWith
(
SysProperties
.
FILE_SEPARATOR
))
{
if
(
fileName
.
startsWith
(
SysProperties
.
FILE_SEPARATOR
))
{
fileName
=
fileName
.
substring
(
1
);
fileName
=
fileName
.
substring
(
1
);
}
boolean
copy
=
false
;
if
(
db
==
null
)
{
copy
=
true
;
}
else
if
(
fileName
.
startsWith
(
originalDbName
+
"."
))
{
fileName
=
db
+
fileName
.
substring
(
originalDbLen
);
copy
=
true
;
}
if
(
copy
)
{
OutputStream
o
=
null
;
try
{
o
=
FileUtils
.
newOutputStream
(
directory
+
SysProperties
.
FILE_SEPARATOR
+
fileName
,
false
);
IOUtils
.
copy
(
zipIn
,
o
);
o
.
close
();
}
finally
{
IOUtils
.
closeSilently
(
o
);
}
}
boolean
copy
=
false
;
if
(
db
==
null
)
{
copy
=
true
;
}
else
if
(
fileName
.
startsWith
(
originalDbName
+
"."
))
{
fileName
=
db
+
fileName
.
substring
(
originalDbLen
);
copy
=
true
;
}
if
(
copy
)
{
OutputStream
o
=
null
;
try
{
o
=
FileUtils
.
newOutputStream
(
directory
+
SysProperties
.
FILE_SEPARATOR
+
fileName
,
false
);
IOUtils
.
copy
(
zipIn
,
o
);
o
.
close
();
}
finally
{
IOUtils
.
closeSilently
(
o
);
}
}
zipIn
.
closeEntry
();
}
}
zipIn
.
closeEntry
();
zipIn
.
closeEntry
();
}
}
zipIn
.
closeEntry
();
zipIn
.
close
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
DbException
.
convertIOException
(
e
,
zipFileName
);
throw
DbException
.
convertIOException
(
e
,
zipFileName
);
}
finally
{
}
finally
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/Profiler.java
浏览文件 @
bc763b82
...
@@ -167,25 +167,21 @@ public class Profiler implements Runnable {
...
@@ -167,25 +167,21 @@ public class Profiler implements Runnable {
continue
;
continue
;
}
}
String
file
=
arg
;
String
file
=
arg
;
Reader
reader
;
try
(
Reader
reader
=
new
InputStreamReader
(
new
FileInputStream
(
file
),
"CP1252"
))
{
LineNumberReader
r
;
LineNumberReader
r
=
new
LineNumberReader
(
reader
);
reader
=
new
InputStreamReader
(
while
(
true
)
{
new
FileInputStream
(
file
),
"CP1252"
);
String
line
=
r
.
readLine
();
r
=
new
LineNumberReader
(
reader
);
if
(
line
==
null
)
{
while
(
true
)
{
break
;
String
line
=
r
.
readLine
();
}
else
if
(
line
.
startsWith
(
"Full thread dump"
))
{
if
(
line
==
null
)
{
threadDumps
++;
break
;
}
}
else
if
(
line
.
startsWith
(
"Full thread dump"
))
{
threadDumps
++;
}
}
}
}
reader
.
close
();
try
(
Reader
reader
=
new
InputStreamReader
(
new
FileInputStream
(
file
),
"CP1252"
))
{
reader
=
new
InputStreamReader
(
LineNumberReader
r
=
new
LineNumberReader
(
reader
);
new
FileInputStream
(
file
),
"CP1252"
);
processList
(
readStackTrace
(
r
));
r
=
new
LineNumberReader
(
reader
);
}
processList
(
readStackTrace
(
r
));
reader
.
close
();
}
}
System
.
out
.
println
(
getTopTraces
(
5
));
System
.
out
.
println
(
getTopTraces
(
5
));
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/SortedProperties.java
浏览文件 @
bc763b82
...
@@ -112,17 +112,17 @@ public class SortedProperties extends Properties {
...
@@ -112,17 +112,17 @@ public class SortedProperties extends Properties {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
IOException
(
e
.
toString
(),
e
);
throw
new
IOException
(
e
.
toString
(),
e
);
}
}
PrintWriter
writer
=
new
PrintWriter
(
new
BufferedWriter
(
w
));
try
(
PrintWriter
writer
=
new
PrintWriter
(
new
BufferedWriter
(
w
)))
{
while
(
true
)
{
while
(
true
)
{
String
line
=
r
.
readLine
();
String
line
=
r
.
readLine
();
if
(
line
==
null
)
{
if
(
line
==
null
)
{
break
;
break
;
}
}
if
(!
line
.
startsWith
(
"#"
))
{
if
(!
line
.
startsWith
(
"#"
))
{
writer
.
print
(
line
+
"\n"
);
writer
.
print
(
line
+
"\n"
);
}
}
}
}
}
writer
.
close
();
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论