提交 9d4901f7 authored 作者: Thomas Mueller's avatar Thomas Mueller

Fix tests

上级 bec4a7d9
......@@ -212,33 +212,41 @@ public class ChangeFileEncryption extends Tool {
return;
}
FileChannel fileIn = FilePath.get(fileName).open("r");
if (decryptKey != null) {
fileIn = new FilePathEncrypt.FileEncrypt(fileName, decryptKey, fileIn);
}
InputStream inStream = new FileChannelInputStream(fileIn, true);
FileChannel fileOut = null;
String temp = directory + "/temp.db";
FileUtils.delete(temp);
FileChannel fileOut = FilePath.get(temp).open("rw");
if (encryptKey != null) {
fileOut = new FilePathEncrypt.FileEncrypt(temp, encryptKey, fileOut);
}
OutputStream outStream = new FileChannelOutputStream(fileOut, true);
byte[] buffer = new byte[4 * 1024];
long remaining = fileIn.size();
long total = remaining;
long time = System.currentTimeMillis();
while (remaining > 0) {
if (System.currentTimeMillis() - time > 1000) {
out.println(fileName + ": " + (100 - 100 * remaining / total) + "%");
time = System.currentTimeMillis();
try {
if (decryptKey != null) {
fileIn = new FilePathEncrypt.FileEncrypt(fileName, decryptKey, fileIn);
}
InputStream inStream = new FileChannelInputStream(fileIn, true);
FileUtils.delete(temp);
fileOut = FilePath.get(temp).open("rw");
if (encryptKey != null) {
fileOut = new FilePathEncrypt.FileEncrypt(temp, encryptKey, fileOut);
}
OutputStream outStream = new FileChannelOutputStream(fileOut, true);
byte[] buffer = new byte[4 * 1024];
long remaining = fileIn.size();
long total = remaining;
long time = System.currentTimeMillis();
while (remaining > 0) {
if (System.currentTimeMillis() - time > 1000) {
out.println(fileName + ": " + (100 - 100 * remaining / total) + "%");
time = System.currentTimeMillis();
}
int len = (int) Math.min(buffer.length, remaining);
len = inStream.read(buffer, 0, len);
outStream.write(buffer, 0, len);
remaining -= len;
}
inStream.close();
outStream.close();
} finally {
fileIn.close();
if (fileOut != null) {
fileOut.close();
}
int len = (int) Math.min(buffer.length, remaining);
len = inStream.read(buffer, 0, len);
outStream.write(buffer, 0, len);
remaining -= len;
}
inStream.close();
outStream.close();
FileUtils.delete(fileName);
FileUtils.moveTo(temp, fileName);
}
......
......@@ -502,16 +502,19 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
}
private void stopAll() {
if (web != null && web.isRunning(false)) {
web.stop();
Server s = web;
if (s != null && s.isRunning(false)) {
s.stop();
web = null;
}
if (tcp != null && tcp.isRunning(false)) {
tcp.stop();
s = tcp;
if (s != null && s.isRunning(false)) {
s.stop();
tcp = null;
}
if (pg != null && pg.isRunning(false)) {
pg.stop();
s = pg;
if (s != null && s.isRunning(false)) {
s.stop();
pg = null;
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论