Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c7289919
提交
c7289919
authored
9 年前
作者:
Thomas Mueller Graf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ArchiveTool: configurable compression level
上级
8a6b058b
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
43 行增加
和
4 行删除
+43
-4
ArchiveTool.java
h2/src/tools/org/h2/dev/fs/ArchiveTool.java
+43
-4
没有找到文件。
h2/src/tools/org/h2/dev/fs/ArchiveTool.java
浏览文件 @
c7289919
...
...
@@ -18,6 +18,8 @@ import java.io.FileOutputStream;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.FileChannel
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Iterator
;
...
...
@@ -57,13 +59,14 @@ public class ArchiveTool {
*/
public
static
void
main
(
String
...
args
)
throws
Exception
{
Log
log
=
new
Log
();
int
level
=
Integer
.
getInteger
(
"level"
,
Deflater
.
BEST_SPEED
);
if
(
args
.
length
==
1
)
{
File
f
=
new
File
(
args
[
0
]);
if
(
f
.
exists
())
{
if
(
f
.
isDirectory
())
{
String
fromDir
=
f
.
getAbsolutePath
();
String
toFile
=
fromDir
+
".at"
;
compress
(
fromDir
,
toFile
);
compress
(
fromDir
,
toFile
,
level
);
return
;
}
String
fromFile
=
f
.
getAbsolutePath
();
...
...
@@ -79,7 +82,7 @@ public class ArchiveTool {
if
(
"-compress"
.
equals
(
arg
))
{
String
toFile
=
args
[
1
];
String
fromDir
=
args
[
2
];
compress
(
fromDir
,
toFile
);
compress
(
fromDir
,
toFile
,
level
);
}
else
if
(
"-extract"
.
equals
(
arg
))
{
String
fromFile
=
args
[
1
];
String
toDir
=
args
[
2
];
...
...
@@ -94,7 +97,7 @@ public class ArchiveTool {
}
}
private
static
void
compress
(
String
fromDir
,
String
toFile
)
throws
IOException
{
private
static
void
compress
(
String
fromDir
,
String
toFile
,
int
level
)
throws
IOException
{
final
Log
log
=
new
Log
();
final
long
start
=
System
.
currentTimeMillis
();
final
AtomicBoolean
title
=
new
AtomicBoolean
();
...
...
@@ -126,7 +129,7 @@ public class ArchiveTool {
new
BufferedOutputStream
(
new
FileOutputStream
(
toFile
),
1024
*
1024
);
Deflater
def
=
new
Deflater
();
def
.
setLevel
(
Deflater
.
BEST_SPEED
);
def
.
setLevel
(
level
);
out
=
new
BufferedOutputStream
(
new
DeflaterOutputStream
(
out
,
def
),
1024
*
1024
);
sort
(
log
,
in
,
out
,
temp
,
size
);
...
...
@@ -535,7 +538,10 @@ public class ArchiveTool {
long
inPos
=
0
;
int
bufferTotal
=
64
*
1024
*
1024
;
int
bufferPerStream
=
bufferTotal
/
segmentStart
.
size
();
// FileChannel fc = new RandomAccessFile(tempFileName, "r").getChannel();
for
(
int
i
=
0
;
i
<
segmentStart
.
size
();
i
++)
{
// long end = i < segmentStart.size() - 1 ? segmentStart.get(i+1) : fc.size();
// InputStream in = new SharedInputStream(fc, segmentStart.get(i), end);
InputStream
in
=
new
FileInputStream
(
tempFileName
);
in
.
skip
(
segmentStart
.
get
(
i
));
ChunkStream
s
=
new
ChunkStream
(
i
);
...
...
@@ -1056,4 +1062,37 @@ public class ArchiveTool {
return
x
;
}
static
class
SharedInputStream
extends
InputStream
{
private
final
FileChannel
channel
;
private
final
long
endPosition
;
private
long
position
;
SharedInputStream
(
FileChannel
channel
,
long
position
,
long
endPosition
)
{
this
.
channel
=
channel
;
this
.
position
=
position
;
this
.
endPosition
=
endPosition
;
}
@Override
public
int
read
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
int
read
(
byte
[]
b
,
int
off
,
int
len
)
throws
IOException
{
if
(
len
==
0
)
{
return
0
;
}
len
=
(
int
)
Math
.
min
(
len
,
endPosition
-
position
);
if
(
len
<=
0
)
{
return
-
1
;
}
ByteBuffer
buff
=
ByteBuffer
.
wrap
(
b
,
off
,
len
);
len
=
channel
.
read
(
buff
,
position
);
position
+=
len
;
return
len
;
}
}
}
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论