Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
820b1655
提交
820b1655
authored
9月 12, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Archive tool: use less memory and larger buffers
上级
09382278
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
24 行增加
和
18 行删除
+24
-18
ArchiveTool.java
h2/src/tools/org/h2/dev/fs/ArchiveTool.java
+24
-18
没有找到文件。
h2/src/tools/org/h2/dev/fs/ArchiveTool.java
浏览文件 @
820b1655
...
...
@@ -20,12 +20,12 @@ import java.io.InputStream;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
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.Inflater
;
import
java.util.zip.InflaterInputStream
;
/**
...
...
@@ -120,11 +120,11 @@ public class ArchiveTool {
String
temp
=
toFile
+
".temp"
;
OutputStream
out
=
new
BufferedOutputStream
(
new
FileOutputStream
(
toFile
),
32
*
1024
);
new
FileOutputStream
(
toFile
),
1024
*
1024
);
Deflater
def
=
new
Deflater
();
def
.
setLevel
(
Deflater
.
BEST_SPEED
);
out
=
new
BufferedOutputStream
(
new
DeflaterOutputStream
(
out
,
def
));
new
DeflaterOutputStream
(
out
,
def
)
,
1024
*
1024
);
sort
(
in
,
out
,
temp
,
size
);
in
.
close
();
out
.
close
();
...
...
@@ -142,11 +142,13 @@ public class ArchiveTool {
System
.
out
.
println
(
"Extracting "
+
size
/
MB
+
" MB"
);
InputStream
in
=
new
BufferedInputStream
(
new
FileInputStream
(
fromFile
));
new
FileInputStream
(
fromFile
)
,
1024
*
1024
);
String
temp
=
fromFile
+
".temp"
;
in
=
new
InflaterInputStream
(
in
);
Inflater
inflater
=
new
Inflater
();
in
=
new
InflaterInputStream
(
in
,
inflater
,
1024
*
1024
);
OutputStream
out
=
getDirectoryOutputStream
(
toDir
);
combine
(
in
,
out
,
temp
);
inflater
.
end
();
in
.
close
();
out
.
close
();
System
.
out
.
println
();
...
...
@@ -182,7 +184,7 @@ public class ArchiveTool {
return
new
InputStream
()
{
private
final
String
baseDir
;
private
final
LinkedList
<
String
>
files
=
new
Linked
List
<
String
>();
private
final
ArrayList
<
String
>
files
=
new
Array
List
<
String
>();
private
String
current
;
private
ByteArrayInputStream
meta
;
private
DataInputStream
fileIn
;
...
...
@@ -196,16 +198,15 @@ public class ArchiveTool {
private
void
addDirectory
(
File
f
)
{
File
[]
list
=
f
.
listFiles
();
// breadth-first traversal
// first all files, then all directories
if
(
list
!=
null
)
{
// first all directories, then all files
for
(
File
c
:
list
)
{
if
(
c
.
is
File
())
{
if
(
c
.
is
Directory
())
{
files
.
add
(
c
.
getAbsolutePath
());
}
}
for
(
File
c
:
list
)
{
if
(
c
.
is
Directory
())
{
if
(
c
.
is
File
())
{
files
.
add
(
c
.
getAbsolutePath
());
}
}
...
...
@@ -246,8 +247,9 @@ public class ArchiveTool {
// EOF
return
-
1
;
}
// fetch the next file or directory
current
=
files
.
remove
();
// breadth-first traversal
// first all files, then all directories
current
=
files
.
remove
(
files
.
size
()
-
1
);
File
f
=
new
File
(
current
);
if
(
f
.
isDirectory
())
{
addDirectory
(
f
);
...
...
@@ -263,7 +265,7 @@ public class ArchiveTool {
remaining
=
f
.
length
();
writeVarLong
(
out
,
remaining
);
fileIn
=
new
DataInputStream
(
new
BufferedInputStream
(
new
FileInputStream
(
current
)));
new
FileInputStream
(
current
)
,
1024
*
1024
));
}
if
(!
current
.
startsWith
(
baseDir
))
{
throw
new
IOException
(
"File "
+
current
+
" does not start with "
+
baseDir
);
...
...
@@ -372,7 +374,7 @@ public class ArchiveTool {
new
File
(
name
).
createNewFile
();
remaining
=
4
;
}
else
{
fileOut
=
new
BufferedOutputStream
(
new
FileOutputStream
(
name
));
fileOut
=
new
BufferedOutputStream
(
new
FileOutputStream
(
name
)
,
1024
*
1024
);
}
}
else
{
file
.
mkdirs
();
...
...
@@ -391,7 +393,7 @@ public class ArchiveTool {
long
lastTime
=
System
.
currentTimeMillis
();
int
bufferSize
=
16
*
1024
*
1024
;
DataOutputStream
tempOut
=
new
DataOutputStream
(
new
BufferedOutputStream
(
new
FileOutputStream
(
tempFileName
)));
new
FileOutputStream
(
tempFileName
)
,
1024
*
1024
));
byte
[]
bytes
=
new
byte
[
bufferSize
];
ArrayList
<
Long
>
segmentStart
=
new
ArrayList
<
Long
>();
long
inPos
=
0
;
...
...
@@ -439,12 +441,14 @@ public class ArchiveTool {
size
=
outPos
;
inPos
=
0
;
TreeSet
<
ChunkStream
>
segmentIn
=
new
TreeSet
<
ChunkStream
>();
int
bufferTotal
=
64
*
1024
*
1024
;
int
bufferPerStream
=
bufferTotal
/
segmentStart
.
size
();
for
(
int
i
=
0
;
i
<
segmentStart
.
size
();
i
++)
{
in
=
new
FileInputStream
(
tempFileName
);
in
.
skip
(
segmentStart
.
get
(
i
));
ChunkStream
s
=
new
ChunkStream
(
i
);
s
.
readKey
=
true
;
s
.
in
=
new
DataInputStream
(
new
BufferedInputStream
(
in
));
s
.
in
=
new
DataInputStream
(
new
BufferedInputStream
(
in
,
bufferPerStream
));
inPos
+=
s
.
readNext
();
if
(
s
.
current
!=
null
)
{
segmentIn
.
add
(
s
);
...
...
@@ -577,7 +581,7 @@ public class ArchiveTool {
DataOutputStream
tempOut
=
new
DataOutputStream
(
new
BufferedOutputStream
(
new
FileOutputStream
(
tempFileName
)));
new
FileOutputStream
(
tempFileName
)
,
1024
*
1024
));
// File: header length chunk* 0
// chunk: pos* 0 data
...
...
@@ -633,11 +637,13 @@ public class ArchiveTool {
size
=
outPos
;
inPos
=
0
;
TreeSet
<
ChunkStream
>
segmentIn
=
new
TreeSet
<
ChunkStream
>();
int
bufferTotal
=
64
*
1024
*
1024
;
int
bufferPerStream
=
bufferTotal
/
segmentStart
.
size
();
for
(
int
i
=
0
;
i
<
segmentStart
.
size
();
i
++)
{
FileInputStream
f
=
new
FileInputStream
(
tempFileName
);
f
.
skip
(
segmentStart
.
get
(
i
));
ChunkStream
s
=
new
ChunkStream
(
i
);
s
.
in
=
new
DataInputStream
(
new
BufferedInputStream
(
f
));
s
.
in
=
new
DataInputStream
(
new
BufferedInputStream
(
f
,
bufferPerStream
));
inPos
+=
s
.
readNext
();
if
(
s
.
current
!=
null
)
{
segmentIn
.
add
(
s
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论