本文整理汇总了Java中org.h2.store.fs.FileUtils.setReadOnly方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.setReadOnly方法的具体用法?Java FileUtils.setReadOnly怎么用?Java FileUtils.setReadOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.store.fs.FileUtils
的用法示例。
在下文中一共展示了FileUtils.setReadOnly方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReadOnly
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testReadOnly() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore;MV_STORE=TRUE";
Connection conn;
Statement stat;
conn = getConnection(dbName);
stat = conn.createStatement();
stat.execute("create table test(id int)");
conn.close();
FileUtils.setReadOnly(getBaseDir() + "/mvstore" +
Constants.SUFFIX_MV_FILE);
conn = getConnection(dbName);
Database db = (Database) ((JdbcConnection) conn).getSession()
.getDataHandler();
assertTrue(db.getMvStore().getStore().getFileStore().isReadOnly());
conn.close();
FileUtils.deleteRecursive(getBaseDir(), true);
}
示例2: testReadOnly
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testReadOnly() throws Exception {
String readOnlyFile = getBaseDir() + "/readOnly.log";
FileUtils.delete(readOnlyFile);
FileUtils.newOutputStream(readOnlyFile, false).close();
FileUtils.setReadOnly(readOnlyFile);
TraceSystem ts = new TraceSystem(readOnlyFile);
ts.setLevelFile(TraceSystem.INFO);
ts.getTrace("test").info("test");
FileUtils.delete(readOnlyFile);
ts.close();
}
示例3: testSetReadOnly
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testSetReadOnly(String fsBase) {
String fileName = fsBase + "/testFile";
if (FileUtils.exists(fileName)) {
FileUtils.delete(fileName);
}
if (FileUtils.createFile(fileName)) {
FileUtils.setReadOnly(fileName);
assertFalse(FileUtils.canWrite(fileName));
FileUtils.delete(fileName);
}
}
示例4: setReadOnly
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void setReadOnly() {
ArrayList<String> list = FileLister.getDatabaseFiles(
getBaseDir(), "readonlyFiles", true);
for (String fileName : list) {
FileUtils.setReadOnly(fileName);
}
}
示例5: testDatabaseInJar
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testDatabaseInJar() throws Exception {
if (getBaseDir().indexOf(':') > 0) {
return;
}
if (config.networked) {
return;
}
org.h2.Driver.load();
String url = "jdbc:h2:" + getBaseDir() + "/fsJar";
Connection conn = getConnection(url, "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, " +
"name varchar, b blob, c clob)");
stat.execute("insert into test values(1, 'Hello', " +
"SECURE_RAND(2000), space(2000))");
ResultSet rs;
rs = stat.executeQuery("select * from test");
rs.next();
byte[] b1 = rs.getBytes(3);
String s1 = rs.getString(4);
conn.close();
conn = getConnection(url, "sa", "sa");
stat = conn.createStatement();
stat.execute("backup to '" + getBaseDir() + "/fsJar.zip'");
conn.close();
deleteDb("fsJar");
for (String f : FileUtils.newDirectoryStream(
"zip:" + getBaseDir() + "/fsJar.zip")) {
assertFalse(FileUtils.isAbsolute(f));
assertTrue(!FileUtils.isDirectory(f));
assertTrue(FileUtils.size(f) > 0);
assertTrue(f.endsWith(FileUtils.getName(f)));
assertEquals(0, FileUtils.lastModified(f));
FileUtils.setReadOnly(f);
assertFalse(FileUtils.canWrite(f));
InputStream in = FileUtils.newInputStream(f);
int len = 0;
while (in.read() >= 0) {
len++;
}
assertEquals(len, FileUtils.size(f));
testReadOnly(f);
}
String urlJar = "jdbc:h2:zip:" + getBaseDir() + "/fsJar.zip!/fsJar";
conn = getConnection(urlJar, "sa", "sa");
stat = conn.createStatement();
rs = stat.executeQuery("select * from test");
rs.next();
assertEquals(1, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
byte[] b2 = rs.getBytes(3);
String s2 = rs.getString(4);
assertEquals(2000, b2.length);
assertEquals(2000, s2.length());
assertEquals(b1, b2);
assertEquals(s1, s2);
assertFalse(rs.next());
conn.close();
FileUtils.delete(getBaseDir() + "/fsJar.zip");
}
示例6: testLinkedTableInReadOnlyDb
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testLinkedTableInReadOnlyDb() throws SQLException {
if (config.memory || config.networked || config.googleAppEngine) {
return;
}
deleteDb("testLinkedTableInReadOnlyDb");
org.h2.Driver.load();
Connection memConn = DriverManager.getConnection(
"jdbc:h2:mem:one", "sa", "sa");
Statement memStat = memConn.createStatement();
memStat.execute("CREATE TABLE TEST(ID VARCHAR)");
String url1 = getURL("testLinkedTableInReadOnlyDb", true);
Connection conn = DriverManager.getConnection(url1, "sa1", "abc abc");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY)");
conn.close();
for (String file : FileUtils.newDirectoryStream(getBaseDir())) {
String name = FileUtils.getName(file);
if ((name.startsWith("testLinkedTableInReadOnlyDb")) &&
(!name.endsWith(".trace.db"))) {
FileUtils.setReadOnly(file);
boolean isReadOnly = !FileUtils.canWrite(file);
if (!isReadOnly) {
fail("File " + file + " is not read only. Can't test it.");
}
}
}
// Now it's read only
conn = DriverManager.getConnection(url1, "sa1", "abc abc");
stat = conn.createStatement();
stat.execute("CREATE LOCAL TEMPORARY LINKED TABLE T" +
"(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')");
// This is valid because it's a linked table
stat.execute("INSERT INTO T VALUES('abc')");
conn.close();
memConn.close();
deleteDb("testLinkedTableInReadOnlyDb");
}
示例7: testNewerWriteVersion
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testNewerWriteVersion() throws Exception {
String fileName = getBaseDir() + "/testNewerWriteVersion.h3";
FileUtils.delete(fileName);
MVStore s = new MVStore.Builder().
encryptionKey("007".toCharArray()).
fileName(fileName).
open();
s.setRetentionTime(Integer.MAX_VALUE);
Map<String, Object> header = s.getStoreHeader();
assertEquals("1", header.get("format").toString());
header.put("formatRead", "1");
header.put("format", "2");
MVMap<Integer, String> m = s.openMap("data");
// this is to ensure the file header is overwritten
// the header is written at least every 20 commits
for (int i = 0; i < 30; i++) {
m.put(0, "Hello World " + i);
s.commit();
if (i > 5) {
s.setRetentionTime(0);
}
}
m.put(0, "Hello World");
s.close();
try {
s = new MVStore.Builder().
encryptionKey("007".toCharArray()).
fileName(fileName).
open();
header = s.getStoreHeader();
fail(header.toString());
} catch (IllegalStateException e) {
assertEquals(DataUtils.ERROR_UNSUPPORTED_FORMAT,
DataUtils.getErrorCode(e.getMessage()));
}
s = new MVStore.Builder().
encryptionKey("007".toCharArray()).
readOnly().
fileName(fileName).
open();
assertTrue(s.getFileStore().isReadOnly());
m = s.openMap("data");
assertEquals("Hello World", m.get(0));
s.close();
FileUtils.setReadOnly(fileName);
s = new MVStore.Builder().
encryptionKey("007".toCharArray()).
fileName(fileName).
open();
assertTrue(s.getFileStore().isReadOnly());
m = s.openMap("data");
assertEquals("Hello World", m.get(0));
s.close();
}
示例8: testEncryptedFile
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testEncryptedFile() {
String fileName = getBaseDir() + "/testEncryptedFile.h3";
FileUtils.delete(fileName);
MVStore s;
MVMap<Integer, String> m;
char[] passwordChars = "007".toCharArray();
s = new MVStore.Builder().
fileName(fileName).
encryptionKey(passwordChars).
open();
assertEquals(0, passwordChars[0]);
assertEquals(0, passwordChars[1]);
assertEquals(0, passwordChars[2]);
assertTrue(FileUtils.exists(fileName));
m = s.openMap("test");
m.put(1, "Hello");
assertEquals("Hello", m.get(1));
s.close();
passwordChars = "008".toCharArray();
try {
s = new MVStore.Builder().
fileName(fileName).
encryptionKey(passwordChars).open();
fail();
} catch (IllegalStateException e) {
assertEquals(DataUtils.ERROR_FILE_CORRUPT,
DataUtils.getErrorCode(e.getMessage()));
}
assertEquals(0, passwordChars[0]);
assertEquals(0, passwordChars[1]);
assertEquals(0, passwordChars[2]);
passwordChars = "007".toCharArray();
s = new MVStore.Builder().
fileName(fileName).
encryptionKey(passwordChars).open();
assertEquals(0, passwordChars[0]);
assertEquals(0, passwordChars[1]);
assertEquals(0, passwordChars[2]);
m = s.openMap("test");
assertEquals("Hello", m.get(1));
s.close();
FileUtils.setReadOnly(fileName);
passwordChars = "007".toCharArray();
s = new MVStore.Builder().
fileName(fileName).
encryptionKey(passwordChars).open();
assertTrue(s.getFileStore().isReadOnly());
s.close();
FileUtils.delete(fileName);
assertFalse(FileUtils.exists(fileName));
}