提交 56b943f8 authored 作者: Thomas Mueller's avatar Thomas Mueller

An archive tool that uses chunk sorting and compression

上级 299c26f5
...@@ -64,7 +64,7 @@ public class ArchiveToolStore { ...@@ -64,7 +64,7 @@ public class ArchiveToolStore {
System.out.println("-extract <file> <targetDir>"); System.out.println("-extract <file> <targetDir>");
} }
} }
private void compress(String sourceDir) throws Exception { private void compress(String sourceDir) throws Exception {
start(); start();
long tempSize = 8 * 1024 * 1024; long tempSize = 8 * 1024 * 1024;
...@@ -275,7 +275,7 @@ public class ArchiveToolStore { ...@@ -275,7 +275,7 @@ public class ArchiveToolStore {
System.out.println("Compressed to " + System.out.println("Compressed to " +
FileUtils.size(fileName) / MB + " MB"); FileUtils.size(fileName) / MB + " MB");
printDone(); printDone();
} }
private void start() { private void start() {
this.start = System.currentTimeMillis(); this.start = System.currentTimeMillis();
...@@ -328,14 +328,14 @@ public class ArchiveToolStore { ...@@ -328,14 +328,14 @@ public class ArchiveToolStore {
break; break;
} }
} }
storeTemp = new MVStore.Builder(). storeTemp = new MVStore.Builder().
fileName(tempFileName). fileName(tempFileName).
autoCommitDisabled(). autoCommitDisabled().
open(); open();
MVMap<Integer, String> fileNames = storeTemp.openMap("fileNames"); MVMap<Integer, String> fileNames = storeTemp.openMap("fileNames");
MVMap<String, int[]> filesTemp = storeTemp.openMap("files"); MVMap<String, int[]> filesTemp = storeTemp.openMap("files");
int fileId = 0; int fileId = 0;
for (Entry<String, int[]> e : files.entrySet()) { for (Entry<String, int[]> e : files.entrySet()) {
...@@ -344,7 +344,7 @@ public class ArchiveToolStore { ...@@ -344,7 +344,7 @@ public class ArchiveToolStore {
totalSize += e.getValue().length / 4; totalSize += e.getValue().length / 4;
} }
storeTemp.commit(); storeTemp.commit();
files = filesTemp; files = filesTemp;
long currentSize = 0; long currentSize = 0;
int chunkSize = 0; int chunkSize = 0;
...@@ -379,7 +379,7 @@ public class ArchiveToolStore { ...@@ -379,7 +379,7 @@ public class ArchiveToolStore {
} }
} }
fileId++; fileId++;
} }
storeTemp.commit(); storeTemp.commit();
} }
...@@ -450,7 +450,7 @@ public class ArchiveToolStore { ...@@ -450,7 +450,7 @@ public class ArchiveToolStore {
} }
currentSize++; currentSize++;
printProgress(50, 100, currentSize, totalSize); printProgress(50, 100, currentSize, totalSize);
} }
for (Entry<String, int[]> e : files.entrySet()) { for (Entry<String, int[]> e : files.entrySet()) {
String f = targetDir + "/" + e.getKey(); String f = targetDir + "/" + e.getKey();
int[] keys = e.getValue(); int[] keys = e.getValue();
...@@ -464,19 +464,19 @@ public class ArchiveToolStore { ...@@ -464,19 +464,19 @@ public class ArchiveToolStore {
} }
new FileOutputStream(f).close(); new FileOutputStream(f).close();
} }
} }
if (file != null) { if (file != null) {
file.close(); file.close();
} }
store.close(); store.close();
storeTemp.close(); storeTemp.close();
FileUtils.delete(tempFileName); FileUtils.delete(tempFileName);
System.out.println(); System.out.println();
printDone(); printDone();
} }
private int getChunkLength(byte[] data, int start, int maxPos) { private int getChunkLength(byte[] data, int start, int maxPos) {
int minLen = 4 * 1024; int minLen = 4 * 1024;
int mask = 4 * 1024 - 1; int mask = 4 * 1024 - 1;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论