use of org.h2.store.fs.FileChannelInputStream in project h2database by h2database.
the class ChangeFileEncryption method copy.
private void copy(String fileName, boolean quiet) throws IOException {
if (FileUtils.isDirectory(fileName)) {
return;
}
String temp = directory + "/temp.db";
try (FileChannel fileIn = getFileChannel(fileName, "r", decryptKey)) {
try (InputStream inStream = new FileChannelInputStream(fileIn, true)) {
FileUtils.delete(temp);
try (OutputStream outStream = new FileChannelOutputStream(getFileChannel(temp, "rw", encryptKey), true)) {
byte[] buffer = new byte[4 * 1024];
long remaining = fileIn.size();
long total = remaining;
long time = System.nanoTime();
while (remaining > 0) {
if (!quiet && System.nanoTime() - time > TimeUnit.SECONDS.toNanos(1)) {
out.println(fileName + ": " + (100 - 100 * remaining / total) + "%");
time = System.nanoTime();
}
int len = (int) Math.min(buffer.length, remaining);
len = inStream.read(buffer, 0, len);
outStream.write(buffer, 0, len);
remaining -= len;
}
}
}
}
FileUtils.delete(fileName);
FileUtils.move(temp, fileName);
}
use of org.h2.store.fs.FileChannelInputStream in project h2database by h2database.
the class TestConcurrent method copyFileSlowly.
private static void copyFileSlowly(FileChannel file, long length, OutputStream out) throws Exception {
file.position(0);
InputStream in = new BufferedInputStream(new FileChannelInputStream(file, false));
for (int j = 0; j < length; j++) {
int x = in.read();
if (x < 0) {
break;
}
out.write(x);
}
in.close();
}
Aggregations