提交 6fc65dc4 authored 作者: Noel Grandin's avatar Noel Grandin

no need to allocate instances of FakeFileChannel

上级 e549c90c
......@@ -17,6 +17,14 @@ import java.nio.channels.WritableByteChannel;
* Fake file channel to use by in-memory and ZIP file systems.
*/
public class FakeFileChannel extends FileChannel {
/**
* No need to allocate these, they have no state
*/
public static final FakeFileChannel INSTANCE = new FakeFileChannel();
private FakeFileChannel() {}
@Override
protected void implCloseChannel() throws IOException {
throw new IOException();
......
......@@ -19,7 +19,6 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicReference;
import org.h2.api.ErrorCode;
import org.h2.compress.CompressLZF;
import org.h2.message.DbException;
......@@ -390,7 +389,7 @@ class FileMem extends FileBase {
}
}
return new FileLock(new FakeFileChannel(), position, size, shared) {
return new FileLock(FakeFileChannel.INSTANCE, position, size, shared) {
@Override
public boolean isValid() {
......
......@@ -19,7 +19,6 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.h2.api.ErrorCode;
import org.h2.compress.CompressLZF;
import org.h2.message.DbException;
......@@ -385,7 +384,7 @@ class FileNioMem extends FileBase {
}
}
return new FileLock(new FakeFileChannel(), position, size, shared) {
return new FileLock(FakeFileChannel.INSTANCE, position, size, shared) {
@Override
public boolean isValid() {
......
......@@ -16,7 +16,6 @@ import java.util.ArrayList;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.h2.message.DbException;
import org.h2.util.IOUtils;
......@@ -354,7 +353,7 @@ class FileZip extends FileBase {
public synchronized FileLock tryLock(long position, long size,
boolean shared) throws IOException {
if (shared) {
return new FileLock(new FakeFileChannel(), position, size, shared) {
return new FileLock(FakeFileChannel.INSTANCE, position, size, shared) {
@Override
public boolean isValid() {
......
......@@ -15,7 +15,6 @@ import java.nio.channels.FileLock;
import java.util.ArrayList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.h2.engine.Constants;
import org.h2.message.DbException;
import org.h2.store.fs.FakeFileChannel;
......@@ -427,7 +426,7 @@ class FileZip2 extends FileBase {
public synchronized FileLock tryLock(long position, long size,
boolean shared) throws IOException {
if (shared) {
return new FileLock(new FakeFileChannel(), position, size, shared) {
return new FileLock(FakeFileChannel.INSTANCE, position, size, shared) {
@Override
public boolean isValid() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论