Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
8d803f02
提交
8d803f02
authored
10 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improved output and speed for large (>10 GB) directories.
上级
87be3ddb
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
70 行增加
和
37 行删除
+70
-37
ArchiveTool.java
h2/src/tools/org/h2/dev/fs/ArchiveTool.java
+70
-37
没有找到文件。
h2/src/tools/org/h2/dev/fs/ArchiveTool.java
浏览文件 @
8d803f02
...
...
@@ -20,9 +20,10 @@ import java.io.InputStream;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.LinkedList
;
import
java.util.TreeMap
;
import
java.util.TreeSet
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.zip.Deflater
;
import
java.util.zip.DeflaterOutputStream
;
import
java.util.zip.InflaterInputStream
;
...
...
@@ -67,8 +68,29 @@ public class ArchiveTool {
}
private
static
void
compress
(
String
fromDir
,
String
toFile
)
throws
IOException
{
long
start
=
System
.
currentTimeMillis
();
long
size
=
getSize
(
new
File
(
fromDir
));
final
long
start
=
System
.
currentTimeMillis
();
final
AtomicBoolean
title
=
new
AtomicBoolean
();
long
size
=
getSize
(
new
File
(
fromDir
),
new
Runnable
()
{
int
count
;
long
lastTime
=
start
;
@Override
public
void
run
()
{
count
++;
if
(
count
%
1000
==
0
)
{
long
now
=
System
.
currentTimeMillis
();
if
(
now
-
lastTime
>
3000
)
{
if
(!
title
.
getAndSet
(
true
))
{
System
.
out
.
println
(
"Counting files"
);
}
System
.
out
.
print
(
count
+
" "
);
lastTime
=
now
;
}
}
}
});
if
(
title
.
get
())
{
System
.
out
.
println
();
}
System
.
out
.
println
(
"Compressing "
+
size
/
MB
+
" MB"
);
InputStream
in
=
getDirectoryInputStream
(
fromDir
);
String
temp
=
toFile
+
".temp"
;
...
...
@@ -109,19 +131,20 @@ public class ArchiveTool {
" seconds"
);
}
private
static
long
getSize
(
File
f
)
{
private
static
long
getSize
(
File
f
,
Runnable
r
)
{
// assume a metadata entry is 40 bytes
long
size
=
40
;
if
(
f
.
isDirectory
())
{
File
[]
list
=
f
.
listFiles
();
if
(
list
!=
null
)
{
for
(
File
c
:
list
)
{
size
+=
getSize
(
c
);
size
+=
getSize
(
c
,
r
);
}
}
}
else
{
size
+=
f
.
length
();
}
r
.
run
();
return
size
;
}
...
...
@@ -391,11 +414,11 @@ public class ArchiveTool {
tempOut
.
close
();
size
=
outPos
;
inPos
=
0
;
ArrayList
<
ChunkStream
>
segmentIn
=
new
ArrayLis
t
<
ChunkStream
>();
TreeSet
<
ChunkStream
>
segmentIn
=
new
TreeSe
t
<
ChunkStream
>();
for
(
int
i
=
0
;
i
<
segmentStart
.
size
();
i
++)
{
in
=
new
FileInputStream
(
tempFileName
);
in
.
skip
(
segmentStart
.
get
(
i
));
ChunkStream
s
=
new
ChunkStream
();
ChunkStream
s
=
new
ChunkStream
(
i
);
s
.
readKey
=
true
;
s
.
in
=
new
DataInputStream
(
new
BufferedInputStream
(
in
));
inPos
+=
s
.
readNext
();
...
...
@@ -413,8 +436,8 @@ public class ArchiveTool {
// chunk: pos* 0 data
while
(
segmentIn
.
size
()
>
0
)
{
C
ollections
.
sort
(
segmentIn
);
ChunkStream
s
=
segmentIn
.
get
(
0
);
C
hunkStream
s
=
segmentIn
.
first
(
);
segmentIn
.
remove
(
s
);
Chunk
c
=
s
.
current
;
if
(
last
==
null
)
{
last
=
c
;
...
...
@@ -428,8 +451,8 @@ public class ArchiveTool {
}
inPos
+=
s
.
readNext
();
lastTime
=
printProgress
(
lastTime
,
50
,
100
,
inPos
,
size
);
if
(
s
.
current
=
=
null
)
{
segmentIn
.
remove
(
0
);
if
(
s
.
current
!
=
null
)
{
segmentIn
.
add
(
s
);
}
}
if
(
last
!=
null
)
{
...
...
@@ -585,11 +608,11 @@ public class ArchiveTool {
tempOut
.
close
();
size
=
outPos
;
inPos
=
0
;
ArrayList
<
ChunkStream
>
segmentIn
=
new
ArrayLis
t
<
ChunkStream
>();
TreeSet
<
ChunkStream
>
segmentIn
=
new
TreeSe
t
<
ChunkStream
>();
for
(
int
i
=
0
;
i
<
segmentStart
.
size
();
i
++)
{
FileInputStream
f
=
new
FileInputStream
(
tempFileName
);
f
.
skip
(
segmentStart
.
get
(
i
));
ChunkStream
s
=
new
ChunkStream
();
ChunkStream
s
=
new
ChunkStream
(
i
);
s
.
in
=
new
DataInputStream
(
new
BufferedInputStream
(
f
));
inPos
+=
s
.
readNext
();
if
(
s
.
current
!=
null
)
{
...
...
@@ -598,14 +621,14 @@ public class ArchiveTool {
}
DataOutputStream
dataOut
=
new
DataOutputStream
(
out
);
while
(
segmentIn
.
size
()
>
0
)
{
C
ollections
.
sort
(
segmentIn
);
ChunkStream
s
=
segmentIn
.
get
(
0
);
C
hunkStream
s
=
segmentIn
.
first
(
);
segmentIn
.
remove
(
s
);
Chunk
c
=
s
.
current
;
dataOut
.
write
(
c
.
value
);
inPos
+=
s
.
readNext
();
lastTime
=
printProgress
(
lastTime
,
50
,
100
,
inPos
,
size
);
if
(
s
.
current
=
=
null
)
{
segmentIn
.
remove
(
0
);
if
(
s
.
current
!
=
null
)
{
segmentIn
.
add
(
s
);
}
}
new
File
(
tempFileName
).
delete
();
...
...
@@ -616,10 +639,15 @@ public class ArchiveTool {
* A stream of chunks.
*/
static
class
ChunkStream
implements
Comparable
<
ChunkStream
>
{
final
int
id
;
Chunk
current
;
DataInputStream
in
;
boolean
readKey
;
ChunkStream
(
int
id
)
{
this
.
id
=
id
;
}
/**
* Read the next chunk.
*
...
...
@@ -635,7 +663,11 @@ public class ArchiveTool {
@Override
public
int
compareTo
(
ChunkStream
o
)
{
return
current
.
compareTo
(
o
.
current
);
int
comp
=
current
.
compareTo
(
o
.
current
);
if
(
comp
!=
0
)
{
return
comp
;
}
return
Integer
.
signum
(
id
-
o
.
id
);
}
}
...
...
@@ -700,7 +732,7 @@ public class ArchiveTool {
}
len
+=
writeVarLong
(
out
,
0
);
if
(
writeKey
)
{
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
for
(
int
i
=
0
;
i
<
sortKey
.
length
;
i
++)
{
out
.
writeInt
(
sortKey
[
i
]);
len
+=
4
;
}
...
...
@@ -722,6 +754,7 @@ public class ArchiveTool {
}
else
if
(
a
>
b
)
{
return
1
;
}
return
0
;
}
for
(
int
i
=
0
;
i
<
sortKey
.
length
;
i
++)
{
if
(
sortKey
[
i
]
<
o
.
sortKey
[
i
])
{
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论