Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
8b48ecdb
提交
8b48ecdb
authored
5月 11, 2014
作者:
noelgrandin@gmail.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FileSystem: improve exception throwing compatibility with JDK
上级
af80d630
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
40 行增加
和
20 行删除
+40
-20
changelog.html
h2/src/docsrc/html/changelog.html
+1
-0
FilePathDisk.java
h2/src/main/org/h2/store/fs/FilePathDisk.java
+7
-0
FilePathMem.java
h2/src/main/org/h2/store/fs/FilePathMem.java
+5
-0
FilePathNio.java
h2/src/main/org/h2/store/fs/FilePathNio.java
+15
-19
FilePathNioMapped.java
h2/src/main/org/h2/store/fs/FilePathNioMapped.java
+5
-0
FilePathNioMem.java
h2/src/main/org/h2/store/fs/FilePathNioMem.java
+5
-0
TestFileSystem.java
h2/src/test/org/h2/test/unit/TestFileSystem.java
+2
-1
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
8b48ecdb
...
...
@@ -23,6 +23,7 @@ Change Log
</li><li>
Follow JDBC specification on Procedures MetaData, use P0 as
return type of procedure.
</li><li>
Issue 531: IDENTITY ignored for added column.
</li><li>
FileSystem: improve exception throwing compatibility with JDK
</li></ul>
<h2>
Version 1.4.178 Beta (2014-05-02)
</h2>
...
...
h2/src/main/org/h2/store/fs/FilePathDisk.java
浏览文件 @
8b48ecdb
...
...
@@ -18,6 +18,7 @@ import java.net.URL;
import
java.nio.ByteBuffer
;
import
java.nio.channels.FileChannel
;
import
java.nio.channels.FileLock
;
import
java.nio.channels.NonWritableChannelException
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -395,10 +396,12 @@ class FileDisk extends FileBase {
private
final
RandomAccessFile
file
;
private
final
String
name
;
private
final
boolean
readOnly
;
FileDisk
(
String
fileName
,
String
mode
)
throws
FileNotFoundException
{
this
.
file
=
new
RandomAccessFile
(
fileName
,
mode
);
this
.
name
=
fileName
;
this
.
readOnly
=
mode
.
equals
(
"r"
);
}
@Override
...
...
@@ -419,6 +422,10 @@ class FileDisk extends FileBase {
@Override
public
FileChannel
truncate
(
long
newLength
)
throws
IOException
{
// compatibility with JDK FileChannel#truncate
if
(
readOnly
)
{
throw
new
NonWritableChannelException
();
}
if
(
newLength
<
file
.
length
())
{
file
.
setLength
(
newLength
);
}
...
...
h2/src/main/org/h2/store/fs/FilePathMem.java
浏览文件 @
8b48ecdb
...
...
@@ -12,6 +12,7 @@ import java.io.OutputStream;
import
java.nio.ByteBuffer
;
import
java.nio.channels.FileChannel
;
import
java.nio.channels.FileLock
;
import
java.nio.channels.NonWritableChannelException
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
...
...
@@ -264,6 +265,10 @@ class FileMem extends FileBase {
@Override
public
FileChannel
truncate
(
long
newLength
)
throws
IOException
{
// compatibility with JDK FileChannel#truncate
if
(
readOnly
)
{
throw
new
NonWritableChannelException
();
}
if
(
newLength
<
size
())
{
data
.
touch
(
readOnly
);
pos
=
Math
.
min
(
pos
,
newLength
);
...
...
h2/src/main/org/h2/store/fs/FilePathNio.java
浏览文件 @
8b48ecdb
...
...
@@ -82,28 +82,24 @@ class FileNio extends FileBase {
@Override
public
FileChannel
truncate
(
long
newLength
)
throws
IOException
{
try
{
long
size
=
channel
.
size
();
if
(
newLength
<
size
)
{
long
pos
=
channel
.
position
();
channel
.
truncate
(
newLength
);
long
newPos
=
channel
.
position
();
if
(
pos
<
newLength
)
{
// position should stay
// in theory, this should not be needed
if
(
newPos
!=
pos
)
{
channel
.
position
(
pos
);
}
}
else
if
(
newPos
>
newLength
)
{
// looks like a bug in this FileChannel implementation, as
// the documentation says the position needs to be changed
channel
.
position
(
newLength
);
long
size
=
channel
.
size
();
if
(
newLength
<
size
)
{
long
pos
=
channel
.
position
();
channel
.
truncate
(
newLength
);
long
newPos
=
channel
.
position
();
if
(
pos
<
newLength
)
{
// position should stay
// in theory, this should not be needed
if
(
newPos
!=
pos
)
{
channel
.
position
(
pos
);
}
}
else
if
(
newPos
>
newLength
)
{
// looks like a bug in this FileChannel implementation, as
// the documentation says the position needs to be changed
channel
.
position
(
newLength
);
}
return
this
;
}
catch
(
NonWritableChannelException
e
)
{
throw
new
IOException
(
"read only"
);
}
return
this
;
}
@Override
...
...
h2/src/main/org/h2/store/fs/FilePathNioMapped.java
浏览文件 @
8b48ecdb
...
...
@@ -16,6 +16,7 @@ import java.nio.ByteBuffer;
import
java.nio.MappedByteBuffer
;
import
java.nio.channels.FileChannel
;
import
java.nio.channels.FileLock
;
import
java.nio.channels.NonWritableChannelException
;
import
org.h2.engine.SysProperties
;
...
...
@@ -203,6 +204,10 @@ class FileNioMapped extends FileBase {
@Override
public
synchronized
FileChannel
truncate
(
long
newLength
)
throws
IOException
{
// compatibility with JDK FileChannel#truncate
if
(
mode
==
MapMode
.
READ_ONLY
)
{
throw
new
NonWritableChannelException
();
}
if
(
newLength
<
size
())
{
setFileLength
(
newLength
);
}
...
...
h2/src/main/org/h2/store/fs/FilePathNioMem.java
浏览文件 @
8b48ecdb
...
...
@@ -12,6 +12,7 @@ import java.io.OutputStream;
import
java.nio.ByteBuffer
;
import
java.nio.channels.FileChannel
;
import
java.nio.channels.FileLock
;
import
java.nio.channels.NonWritableChannelException
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
...
...
@@ -256,6 +257,10 @@ class FileNioMem extends FileBase {
@Override
public
FileChannel
truncate
(
long
newLength
)
throws
IOException
{
// compatibility with JDK FileChannel#truncate
if
(
readOnly
)
{
throw
new
NonWritableChannelException
();
}
if
(
newLength
<
size
())
{
data
.
touch
(
readOnly
);
pos
=
Math
.
min
(
pos
,
newLength
);
...
...
h2/src/test/org/h2/test/unit/TestFileSystem.java
浏览文件 @
8b48ecdb
...
...
@@ -15,6 +15,7 @@ import java.nio.ByteBuffer;
import
java.nio.channels.FileChannel
;
import
java.nio.channels.FileChannel.MapMode
;
import
java.nio.channels.FileLock
;
import
java.nio.channels.NonWritableChannelException
;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
...
...
@@ -549,7 +550,7 @@ public class TestFileSystem extends TestBase {
fc
.
write
(
ByteBuffer
.
wrap
(
test
,
0
,
10
));
}
};
new
AssertThrows
(
IO
Exception
.
class
)
{
new
AssertThrows
(
NonWritableChannel
Exception
.
class
)
{
@Override
public
void
test
()
throws
Exception
{
fc
.
truncate
(
10
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论