Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7ce90b13
提交
7ce90b13
authored
10月 02, 2015
作者:
Thomas Mueller Graf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ArchiveTool: improved log output
上级
d2c4c303
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
64 行增加
和
36 行删除
+64
-36
ArchiveTool.java
h2/src/tools/org/h2/dev/fs/ArchiveTool.java
+64
-36
没有找到文件。
h2/src/tools/org/h2/dev/fs/ArchiveTool.java
浏览文件 @
7ce90b13
...
@@ -54,6 +54,7 @@ public class ArchiveTool {
...
@@ -54,6 +54,7 @@ public class ArchiveTool {
* @param args the command line arguments
* @param args the command line arguments
*/
*/
public
static
void
main
(
String
...
args
)
throws
Exception
{
public
static
void
main
(
String
...
args
)
throws
Exception
{
Log
log
=
new
Log
();
if
(
args
.
length
==
1
)
{
if
(
args
.
length
==
1
)
{
File
f
=
new
File
(
args
[
0
]);
File
f
=
new
File
(
args
[
0
]);
if
(
f
.
exists
())
{
if
(
f
.
exists
())
{
...
@@ -82,16 +83,17 @@ public class ArchiveTool {
...
@@ -82,16 +83,17 @@ public class ArchiveTool {
String
toDir
=
args
[
2
];
String
toDir
=
args
[
2
];
extract
(
fromFile
,
toDir
);
extract
(
fromFile
,
toDir
);
}
else
{
}
else
{
System
.
out
.
println
(
"An archive tool to efficiently compress large directories"
);
log
.
println
(
"An archive tool to efficiently compress large directories"
);
System
.
out
.
println
(
"Command line options:"
);
log
.
println
(
"Command line options:"
);
System
.
out
.
println
(
"<sourceDir>"
);
log
.
println
(
"<sourceDir>"
);
System
.
out
.
println
(
"<compressedFile>"
);
log
.
println
(
"<compressedFile>"
);
System
.
out
.
println
(
"-compress <compressedFile> <sourceDir>"
);
log
.
println
(
"-compress <compressedFile> <sourceDir>"
);
System
.
out
.
println
(
"-extract <compressedFile> <targetDir>"
);
log
.
println
(
"-extract <compressedFile> <targetDir>"
);
}
}
}
}
private
static
void
compress
(
String
fromDir
,
String
toFile
)
throws
IOException
{
private
static
void
compress
(
String
fromDir
,
String
toFile
)
throws
IOException
{
final
Log
log
=
new
Log
();
final
long
start
=
System
.
currentTimeMillis
();
final
long
start
=
System
.
currentTimeMillis
();
final
AtomicBoolean
title
=
new
AtomicBoolean
();
final
AtomicBoolean
title
=
new
AtomicBoolean
();
long
size
=
getSize
(
new
File
(
fromDir
),
new
Runnable
()
{
long
size
=
getSize
(
new
File
(
fromDir
),
new
Runnable
()
{
...
@@ -104,18 +106,18 @@ public class ArchiveTool {
...
@@ -104,18 +106,18 @@ public class ArchiveTool {
long
now
=
System
.
currentTimeMillis
();
long
now
=
System
.
currentTimeMillis
();
if
(
now
-
lastTime
>
3000
)
{
if
(
now
-
lastTime
>
3000
)
{
if
(!
title
.
getAndSet
(
true
))
{
if
(!
title
.
getAndSet
(
true
))
{
System
.
out
.
println
(
"Counting files"
);
log
.
println
(
"Counting files"
);
}
}
System
.
out
.
print
(
count
+
" "
);
log
.
print
(
count
+
" "
);
lastTime
=
now
;
lastTime
=
now
;
}
}
}
}
}
}
});
});
if
(
title
.
get
())
{
if
(
title
.
get
())
{
System
.
out
.
println
();
log
.
println
();
}
}
System
.
out
.
println
(
"Compressing "
+
size
/
MB
+
" MB"
);
log
.
println
(
"Compressing "
+
size
/
MB
+
" MB"
);
InputStream
in
=
getDirectoryInputStream
(
fromDir
);
InputStream
in
=
getDirectoryInputStream
(
fromDir
);
String
temp
=
toFile
+
".temp"
;
String
temp
=
toFile
+
".temp"
;
OutputStream
out
=
OutputStream
out
=
...
@@ -125,21 +127,22 @@ public class ArchiveTool {
...
@@ -125,21 +127,22 @@ public class ArchiveTool {
def
.
setLevel
(
Deflater
.
BEST_SPEED
);
def
.
setLevel
(
Deflater
.
BEST_SPEED
);
out
=
new
BufferedOutputStream
(
out
=
new
BufferedOutputStream
(
new
DeflaterOutputStream
(
out
,
def
),
1024
*
1024
);
new
DeflaterOutputStream
(
out
,
def
),
1024
*
1024
);
sort
(
in
,
out
,
temp
,
size
);
sort
(
log
,
in
,
out
,
temp
,
size
);
in
.
close
();
in
.
close
();
out
.
close
();
out
.
close
();
System
.
out
.
println
();
log
.
println
();
System
.
out
.
println
(
"Compressed to "
+
log
.
println
(
"Compressed to "
+
new
File
(
toFile
).
length
()
/
MB
+
" MB in "
+
new
File
(
toFile
).
length
()
/
MB
+
" MB in "
+
(
System
.
currentTimeMillis
()
-
start
)
/
1000
+
(
System
.
currentTimeMillis
()
-
start
)
/
1000
+
" seconds"
);
" seconds"
);
System
.
out
.
println
();
log
.
println
();
}
}
private
static
void
extract
(
String
fromFile
,
String
toDir
)
throws
IOException
{
private
static
void
extract
(
String
fromFile
,
String
toDir
)
throws
IOException
{
Log
log
=
new
Log
();
long
start
=
System
.
currentTimeMillis
();
long
start
=
System
.
currentTimeMillis
();
long
size
=
new
File
(
fromFile
).
length
();
long
size
=
new
File
(
fromFile
).
length
();
System
.
out
.
println
(
"Extracting "
+
size
/
MB
+
" MB"
);
log
.
println
(
"Extracting "
+
size
/
MB
+
" MB"
);
InputStream
in
=
InputStream
in
=
new
BufferedInputStream
(
new
BufferedInputStream
(
new
FileInputStream
(
fromFile
),
1024
*
1024
);
new
FileInputStream
(
fromFile
),
1024
*
1024
);
...
@@ -147,12 +150,12 @@ public class ArchiveTool {
...
@@ -147,12 +150,12 @@ public class ArchiveTool {
Inflater
inflater
=
new
Inflater
();
Inflater
inflater
=
new
Inflater
();
in
=
new
InflaterInputStream
(
in
,
inflater
,
1024
*
1024
);
in
=
new
InflaterInputStream
(
in
,
inflater
,
1024
*
1024
);
OutputStream
out
=
getDirectoryOutputStream
(
toDir
);
OutputStream
out
=
getDirectoryOutputStream
(
toDir
);
combine
(
in
,
out
,
temp
);
combine
(
log
,
in
,
out
,
temp
);
inflater
.
end
();
inflater
.
end
();
in
.
close
();
in
.
close
();
out
.
close
();
out
.
close
();
System
.
out
.
println
();
log
.
println
();
System
.
out
.
println
(
"Extracted in "
+
log
.
println
(
"Extracted in "
+
(
System
.
currentTimeMillis
()
-
start
)
/
1000
+
(
System
.
currentTimeMillis
()
-
start
)
/
1000
+
" seconds"
);
" seconds"
);
}
}
...
@@ -389,9 +392,8 @@ public class ArchiveTool {
...
@@ -389,9 +392,8 @@ public class ArchiveTool {
};
};
}
}
private
static
void
sort
(
InputStream
in
,
OutputStream
out
,
private
static
void
sort
(
Log
log
,
InputStream
in
,
OutputStream
out
,
String
tempFileName
,
long
size
)
throws
IOException
{
String
tempFileName
,
long
size
)
throws
IOException
{
long
lastTime
=
System
.
currentTimeMillis
();
int
bufferSize
=
32
*
1024
*
1024
;
int
bufferSize
=
32
*
1024
*
1024
;
DataOutputStream
tempOut
=
new
DataOutputStream
(
new
BufferedOutputStream
(
DataOutputStream
tempOut
=
new
DataOutputStream
(
new
BufferedOutputStream
(
new
FileOutputStream
(
tempFileName
),
1024
*
1024
));
new
FileOutputStream
(
tempFileName
),
1024
*
1024
));
...
@@ -411,7 +413,7 @@ public class ArchiveTool {
...
@@ -411,7 +413,7 @@ public class ArchiveTool {
break
;
break
;
}
}
inPos
+=
len
;
inPos
+=
len
;
l
astTime
=
printProgress
(
lastTime
,
0
,
50
,
inPos
,
size
);
l
og
.
printProgress
(
0
,
50
,
inPos
,
size
);
TreeMap
<
Chunk
,
Chunk
>
map
=
new
TreeMap
<
Chunk
,
Chunk
>();
TreeMap
<
Chunk
,
Chunk
>
map
=
new
TreeMap
<
Chunk
,
Chunk
>();
for
(
int
pos
=
0
;
pos
<
len
;)
{
for
(
int
pos
=
0
;
pos
<
len
;)
{
int
[]
key
=
getKey
(
bytes
,
pos
,
len
);
int
[]
key
=
getKey
(
bytes
,
pos
,
len
);
...
@@ -479,7 +481,7 @@ public class ArchiveTool {
...
@@ -479,7 +481,7 @@ public class ArchiveTool {
last
=
c
;
last
=
c
;
}
}
inPos
+=
s
.
readNext
();
inPos
+=
s
.
readNext
();
l
astTime
=
printProgress
(
lastTime
,
50
,
100
,
inPos
,
size
);
l
og
.
printProgress
(
50
,
100
,
inPos
,
size
);
if
(
s
.
current
!=
null
)
{
if
(
s
.
current
!=
null
)
{
segmentIn
.
add
(
s
);
segmentIn
.
add
(
s
);
}
}
...
@@ -575,9 +577,8 @@ public class ArchiveTool {
...
@@ -575,9 +577,8 @@ public class ArchiveTool {
return
hash
;
return
hash
;
}
}
private
static
void
combine
(
InputStream
in
,
OutputStream
out
,
private
static
void
combine
(
Log
log
,
InputStream
in
,
OutputStream
out
,
String
tempFileName
)
throws
IOException
{
String
tempFileName
)
throws
IOException
{
long
lastTime
=
System
.
currentTimeMillis
();
int
bufferSize
=
16
*
1024
*
1024
;
int
bufferSize
=
16
*
1024
*
1024
;
DataOutputStream
tempOut
=
DataOutputStream
tempOut
=
new
DataOutputStream
(
new
DataOutputStream
(
...
@@ -614,7 +615,7 @@ public class ArchiveTool {
...
@@ -614,7 +615,7 @@ public class ArchiveTool {
}
}
int
length
=
c
.
value
.
length
;
int
length
=
c
.
value
.
length
;
inPos
+=
length
;
inPos
+=
length
;
l
astTime
=
printProgress
(
lastTime
,
0
,
50
,
inPos
,
size
);
l
og
.
printProgress
(
0
,
50
,
inPos
,
size
);
segmentSize
+=
length
;
segmentSize
+=
length
;
for
(
long
x
:
c
.
idList
)
{
for
(
long
x
:
c
.
idList
)
{
map
.
put
(
x
,
c
.
value
);
map
.
put
(
x
,
c
.
value
);
...
@@ -657,7 +658,7 @@ public class ArchiveTool {
...
@@ -657,7 +658,7 @@ public class ArchiveTool {
Chunk
c
=
s
.
current
;
Chunk
c
=
s
.
current
;
dataOut
.
write
(
c
.
value
);
dataOut
.
write
(
c
.
value
);
inPos
+=
s
.
readNext
();
inPos
+=
s
.
readNext
();
l
astTime
=
printProgress
(
lastTime
,
50
,
100
,
inPos
,
size
);
l
og
.
printProgress
(
50
,
100
,
inPos
,
size
);
if
(
s
.
current
!=
null
)
{
if
(
s
.
current
!=
null
)
{
segmentIn
.
add
(
s
);
segmentIn
.
add
(
s
);
}
}
...
@@ -812,6 +813,43 @@ public class ArchiveTool {
...
@@ -812,6 +813,43 @@ public class ArchiveTool {
}
}
}
}
/**
* A logger, including context.
*/
static
class
Log
{
private
long
lastTime
;
private
int
pos
;
void
println
()
{
System
.
out
.
println
();
}
void
print
(
String
msg
)
{
System
.
out
.
print
(
msg
);
}
void
println
(
String
msg
)
{
System
.
out
.
println
(
msg
);
}
void
printProgress
(
int
low
,
int
high
,
long
current
,
long
total
)
{
long
now
=
System
.
currentTimeMillis
();
if
(
now
-
lastTime
>
3000
)
{
String
msg
=
(
low
+
(
high
-
low
)
*
current
/
total
)
+
"% "
;
if
(
pos
>
80
)
{
System
.
out
.
println
();
pos
=
0
;
}
System
.
out
.
print
(
msg
);
pos
+=
msg
.
length
();
lastTime
=
now
;
}
}
}
/**
/**
* Write a variable size long value.
* Write a variable size long value.
*
*
...
@@ -861,14 +899,4 @@ public class ArchiveTool {
...
@@ -861,14 +899,4 @@ public class ArchiveTool {
return
x
;
return
x
;
}
}
private
static
long
printProgress
(
long
lastTime
,
int
low
,
int
high
,
long
current
,
long
total
)
{
long
now
=
System
.
currentTimeMillis
();
if
(
now
-
lastTime
>
3000
)
{
System
.
out
.
print
((
low
+
(
high
-
low
)
*
current
/
total
)
+
"% "
);
lastTime
=
now
;
}
return
lastTime
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论