Unverified 提交 4bd13a57 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #728 from katzyn/FakeFileChannel

Fix for issue #725: FilePathMem.tryLock() fails since Java 9
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.store.fs;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
/**
* Fake file channel to use by in-memory and ZIP file systems.
*/
public class FakeFileChannel extends FileChannel {
@Override
protected void implCloseChannel() throws IOException {
throw new IOException();
}
@Override
public FileLock lock(long position, long size, boolean shared) throws IOException {
throw new IOException();
}
@Override
public MappedByteBuffer map(MapMode mode, long position, long size) throws IOException {
throw new IOException();
}
@Override
public long position() throws IOException {
throw new IOException();
}
@Override
public FileChannel position(long newPosition) throws IOException {
throw new IOException();
}
@Override
public int read(ByteBuffer dst) throws IOException {
throw new IOException();
}
@Override
public int read(ByteBuffer dst, long position) throws IOException {
throw new IOException();
}
@Override
public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
throw new IOException();
}
@Override
public long size() throws IOException {
throw new IOException();
}
@Override
public long transferFrom(ReadableByteChannel src, long position, long count) throws IOException {
throw new IOException();
}
@Override
public long transferTo(long position, long count, WritableByteChannel target) throws IOException {
throw new IOException();
}
@Override
public FileChannel truncate(long size) throws IOException {
throw new IOException();
}
@Override
public FileLock tryLock(long position, long size, boolean shared) throws IOException {
throw new IOException();
}
@Override
public int write(ByteBuffer src) throws IOException {
throw new IOException();
}
@Override
public int write(ByteBuffer src, long position) throws IOException {
throw new IOException();
}
@Override
public long write(ByteBuffer[] srcs, int offset, int len) throws IOException {
throw new IOException();
}
@Override
public void force(boolean metaData) throws IOException {
throw new IOException();
}
}
\ No newline at end of file
...@@ -392,8 +392,7 @@ class FileMem extends FileBase { ...@@ -392,8 +392,7 @@ class FileMem extends FileBase {
} }
} }
// cast to FileChannel to avoid JDK 1.7 ambiguity FileLock lock = new FileLock(new FakeFileChannel(), position, size, shared) {
FileLock lock = new FileLock((FileChannel) null, position, size, shared) {
@Override @Override
public boolean isValid() { public boolean isValid() {
......
...@@ -386,8 +386,7 @@ class FileNioMem extends FileBase { ...@@ -386,8 +386,7 @@ class FileNioMem extends FileBase {
} }
} }
// cast to FileChannel to avoid JDK 1.7 ambiguity FileLock lock = new FileLock(new FakeFileChannel(), position, size, shared) {
FileLock lock = new FileLock((FileChannel) null, position, size, shared) {
@Override @Override
public boolean isValid() { public boolean isValid() {
......
...@@ -354,8 +354,7 @@ class FileZip extends FileBase { ...@@ -354,8 +354,7 @@ class FileZip extends FileBase {
public synchronized FileLock tryLock(long position, long size, public synchronized FileLock tryLock(long position, long size,
boolean shared) throws IOException { boolean shared) throws IOException {
if (shared) { if (shared) {
// cast to FileChannel to avoid JDK 1.7 ambiguity return new FileLock(new FakeFileChannel(), position, size, shared) {
return new FileLock((FileChannel) null, position, size, shared) {
@Override @Override
public boolean isValid() { public boolean isValid() {
......
...@@ -17,6 +17,7 @@ import java.util.zip.ZipEntry; ...@@ -17,6 +17,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.store.fs.FakeFileChannel;
import org.h2.store.fs.FileBase; import org.h2.store.fs.FileBase;
import org.h2.store.fs.FileChannelInputStream; import org.h2.store.fs.FileChannelInputStream;
import org.h2.store.fs.FilePath; import org.h2.store.fs.FilePath;
...@@ -426,9 +427,7 @@ class FileZip2 extends FileBase { ...@@ -426,9 +427,7 @@ class FileZip2 extends FileBase {
public synchronized FileLock tryLock(long position, long size, public synchronized FileLock tryLock(long position, long size,
boolean shared) throws IOException { boolean shared) throws IOException {
if (shared) { if (shared) {
return new FileLock(new FakeFileChannel(), position, size, shared) {
// cast to FileChannel to avoid JDK 1.7 ambiguity
return new FileLock((FileChannel) null, position, size, shared) {
@Override @Override
public boolean isValid() { public boolean isValid() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论