提交 f696f8a0 authored 作者: Thomas Mueller's avatar Thomas Mueller

MVTableEngine: support online backup on Windows

上级 35cbaa1f
...@@ -231,7 +231,7 @@ public class MVTableEngine implements TableEngine { ...@@ -231,7 +231,7 @@ public class MVTableEngine implements TableEngine {
} }
public InputStream getInputStream() { public InputStream getInputStream() {
return new FileChannelInputStream(store.getFile()); return new FileChannelInputStream(store.getFile(), false);
} }
} }
......
...@@ -17,15 +17,18 @@ import java.nio.channels.FileChannel; ...@@ -17,15 +17,18 @@ import java.nio.channels.FileChannel;
public class FileChannelInputStream extends InputStream { public class FileChannelInputStream extends InputStream {
private final FileChannel channel; private final FileChannel channel;
private final boolean closeChannel;
private final byte[] buffer = { 0 }; private final byte[] buffer = { 0 };
/** /**
* Create a new file object input stream from the file channel. * Create a new file object input stream from the file channel.
* *
* @param channel the file channel * @param channel the file channel
* @param closeChannel whether closing the stream should close the channel
*/ */
public FileChannelInputStream(FileChannel channel) { public FileChannelInputStream(FileChannel channel, boolean closeChannel) {
this.channel = channel; this.channel = channel;
this.closeChannel = closeChannel;
} }
@Override @Override
...@@ -53,7 +56,9 @@ public class FileChannelInputStream extends InputStream { ...@@ -53,7 +56,9 @@ public class FileChannelInputStream extends InputStream {
@Override @Override
public void close() throws IOException { public void close() throws IOException {
channel.close(); if (closeChannel) {
channel.close();
}
} }
} }
...@@ -77,7 +77,7 @@ public class FilePathCrypt extends FilePathWrapper { ...@@ -77,7 +77,7 @@ public class FilePathCrypt extends FilePathWrapper {
@Override @Override
public InputStream newInputStream() throws IOException { public InputStream newInputStream() throws IOException {
return new FileChannelInputStream(open("r")); return new FileChannelInputStream(open("r"), true);
} }
/** /**
......
...@@ -162,7 +162,7 @@ public class FilePathMem extends FilePath { ...@@ -162,7 +162,7 @@ public class FilePathMem extends FilePath {
public InputStream newInputStream() { public InputStream newInputStream() {
FileMemData obj = getMemoryFile(); FileMemData obj = getMemoryFile();
FileMem m = new FileMem(obj, true); FileMem m = new FileMem(obj, true);
return new FileChannelInputStream(m); return new FileChannelInputStream(m, true);
} }
@Override @Override
......
...@@ -162,7 +162,7 @@ public class FilePathNioMem extends FilePath { ...@@ -162,7 +162,7 @@ public class FilePathNioMem extends FilePath {
public InputStream newInputStream() { public InputStream newInputStream() {
FileNioMemData obj = getMemoryFile(); FileNioMemData obj = getMemoryFile();
FileNioMem m = new FileNioMem(obj, true); FileNioMem m = new FileNioMem(obj, true);
return new FileChannelInputStream(m); return new FileChannelInputStream(m, true);
} }
@Override @Override
......
...@@ -171,7 +171,7 @@ public class FilePathZip extends FilePath { ...@@ -171,7 +171,7 @@ public class FilePathZip extends FilePath {
@Override @Override
public InputStream newInputStream() throws IOException { public InputStream newInputStream() throws IOException {
return new FileChannelInputStream(open("r")); return new FileChannelInputStream(open("r"), true);
} }
@Override @Override
......
...@@ -245,7 +245,7 @@ public class FilePathZip2 extends FilePath { ...@@ -245,7 +245,7 @@ public class FilePathZip2 extends FilePath {
@Override @Override
public InputStream newInputStream() throws IOException { public InputStream newInputStream() throws IOException {
return new FileChannelInputStream(open("r")); return new FileChannelInputStream(open("r"), true);
} }
@Override @Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论