本文整理汇总了Java中org.h2.store.fs.FileUtils.open方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.open方法的具体用法?Java FileUtils.open怎么用?Java FileUtils.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.store.fs.FileUtils
的用法示例。
在下文中一共展示了FileUtils.open方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FileStore
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
* Create a new file using the given settings.
*
* @param handler the callback object
* @param name the file name
* @param mode the access mode ("r", "rw", "rws", "rwd")
*/
protected FileStore(DataHandler handler, String name, String mode) {
this.handler = handler;
this.name = name;
try {
boolean exists = FileUtils.exists(name);
if (exists && !FileUtils.canWrite(name)) {
mode = "r";
} else {
FileUtils.createDirectories(FileUtils.getParent(name));
}
file = FileUtils.open(name, mode);
if (exists) {
fileLength = file.size();
}
} catch (IOException e) {
throw DbException.convertIOException(
e, "name: " + name + " mode: " + mode);
}
this.mode = mode;
}
示例2: testIncompleteCreate
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testIncompleteCreate() throws Exception {
deleteDb("pageStoreCoverage");
Connection conn;
String fileName = getBaseDir() + "/pageStore" + Constants.SUFFIX_PAGE_FILE;
conn = getConnection("pageStoreCoverage");
Statement stat = conn.createStatement();
stat.execute("drop table if exists INFORMATION_SCHEMA.LOB_DATA");
stat.execute("drop table if exists INFORMATION_SCHEMA.LOB_MAP");
conn.close();
FileChannel f = FileUtils.open(fileName, "rw");
// create a new database
conn = getConnection("pageStoreCoverage");
conn.close();
f = FileUtils.open(fileName, "rw");
f.truncate(16);
// create a new database
conn = getConnection("pageStoreCoverage");
conn.close();
deleteDb("pageStoreCoverage");
}
示例3: openFile
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
* Re-open the file. The file pointer will be reset to the previous
* location.
*/
public void openFile() throws IOException {
if (file == null) {
file = FileUtils.open(name, mode);
file.position(filePos);
}
}
示例4: testCorrupt
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testCorrupt() throws Exception {
if (config.mvStore) {
// not needed for MV_STORE=TRUE
return;
}
DeleteDbFiles.execute(getBaseDir(), "recovery", true);
Connection conn = getConnection("recovery");
Statement stat = conn.createStatement();
stat.execute("create table test(id int, name varchar) as " +
"select 1, 'Hello World1'");
conn.close();
FileChannel f = FileUtils.open(getBaseDir() + "/recovery.h2.db", "rw");
byte[] buff = new byte[Constants.DEFAULT_PAGE_SIZE];
while (f.position() < f.size()) {
FileUtils.readFully(f, ByteBuffer.wrap(buff));
if (new String(buff).contains("Hello World1")) {
buff[buff.length - 1]++;
f.position(f.position() - buff.length);
f.write(ByteBuffer.wrap(buff));
}
}
f.close();
Recover.main("-dir", getBaseDir(), "-db", "recovery");
String script = IOUtils.readStringAndClose(
new InputStreamReader(
FileUtils.newInputStream(getBaseDir() + "/recovery.h2.sql")), -1);
assertContains(script, "checksum mismatch");
assertContains(script, "dump:");
assertContains(script, "Hello World2");
}
示例5: testSimpleExpandTruncateSize
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testSimpleExpandTruncateSize() throws Exception {
String f = "memFS:" + getBaseDir() + "/fs/test.data";
FileUtils.createDirectories("memFS:" + getBaseDir() + "/fs");
FileChannel c = FileUtils.open(f, "rw");
c.position(4000);
c.write(ByteBuffer.wrap(new byte[1]));
FileLock lock = c.tryLock();
c.truncate(0);
if (lock != null) {
lock.release();
}
c.close();
FileUtils.deleteRecursive("memFS:", false);
}
示例6: testReadOnly
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testReadOnly(final String f) throws IOException {
new AssertThrows(IOException.class) {
@Override
public void test() throws IOException {
FileUtils.newOutputStream(f, false);
}};
new AssertThrows(DbException.class) {
@Override
public void test() {
FileUtils.move(f, f);
}};
new AssertThrows(DbException.class) {
@Override
public void test() {
FileUtils.move(f, f);
}};
new AssertThrows(IOException.class) {
@Override
public void test() throws IOException {
FileUtils.createTempFile(f, ".tmp", false, false);
}};
final FileChannel channel = FileUtils.open(f, "r");
new AssertThrows(IOException.class) {
@Override
public void test() throws IOException {
channel.write(ByteBuffer.allocate(1));
}};
new AssertThrows(IOException.class) {
@Override
public void test() throws IOException {
channel.truncate(0);
}};
assertTrue(null == channel.tryLock());
channel.force(false);
channel.close();
}
示例7: testErrorMessageWrongSplit
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testErrorMessageWrongSplit() throws Exception {
if (config.memory || config.reopen) {
return;
}
String fn = getBaseDir() + "/openClose2";
if (config.mvStore) {
fn += Constants.SUFFIX_MV_FILE;
} else {
fn += Constants.SUFFIX_PAGE_FILE;
}
FileUtils.delete("split:" + fn);
Connection conn;
String url = "jdbc:h2:split:18:" + getBaseDir() + "/openClose2";
url = getURL(url, true);
conn = DriverManager.getConnection(url);
conn.createStatement().execute("create table test(id int, name varchar) " +
"as select 1, space(1000000)");
conn.close();
FileChannel c = FileUtils.open(fn+".1.part", "rw");
c.position(c.size() * 2 - 1);
c.write(ByteBuffer.wrap(new byte[1]));
c.close();
if (config.mvStore) {
assertThrows(ErrorCode.IO_EXCEPTION_1, this).getConnection(url);
} else {
assertThrows(ErrorCode.IO_EXCEPTION_2, this).getConnection(url);
}
FileUtils.delete("split:" + fn);
}
示例8: testUnsupportedFeatures
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private static void testUnsupportedFeatures(String fsBase) throws IOException {
final String fileName = fsBase + "/testFile";
if (FileUtils.exists(fileName)) {
FileUtils.delete(fileName);
}
if (FileUtils.createFile(fileName)) {
final FileChannel channel = FileUtils.open(fileName, "rw");
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.map(MapMode.PRIVATE, 0, channel.size());
}};
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.read(new ByteBuffer[]{ByteBuffer.allocate(10)}, 0, 0);
}};
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.write(new ByteBuffer[]{ByteBuffer.allocate(10)}, 0, 0);
}};
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.transferFrom(channel, 0, 0);
}};
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.transferTo(0, 0, channel);
}};
new AssertThrows(UnsupportedOperationException.class) {
@Override
public void test() throws IOException {
channel.lock();
}};
channel.close();
FileUtils.delete(fileName);
}
}
示例9: testAppendOnly
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testAppendOnly() throws Exception {
deleteDb("testAppendOnly");
Connection conn = getConnection(
"testAppendOnly");
Statement stat = conn.createStatement();
stat.execute("set retention_time 0");
for (int i = 0; i < 10; i++) {
stat.execute("create table dummy" + i +
" as select x, space(100) from system_range(1, 1000)");
stat.execute("checkpoint");
}
stat.execute("create table test as select x from system_range(1, 1000)");
conn.close();
String fileName = getBaseDir() + "/testAppendOnly" + Constants.SUFFIX_MV_FILE;
long fileSize = FileUtils.size(fileName);
conn = getConnection(
"testAppendOnly;reuse_space=false");
stat = conn.createStatement();
stat.execute("set retention_time 0");
for (int i = 0; i < 10; i++) {
stat.execute("drop table dummy" + i);
stat.execute("checkpoint");
}
stat.execute("alter table test alter column x rename to y");
stat.execute("select y from test where 1 = 0");
stat.execute("create table test2 as select x from system_range(1, 1000)");
conn.close();
FileChannel fc = FileUtils.open(fileName, "rw");
// undo all changes
fc.truncate(fileSize);
conn = getConnection(
"testAppendOnly");
stat = conn.createStatement();
stat.execute("select * from dummy0 where 1 = 0");
stat.execute("select * from dummy9 where 1 = 0");
stat.execute("select x from test where 1 = 0");
conn.close();
}