本文整理汇总了Java中org.h2.store.fs.FileUtils类的典型用法代码示例。如果您正苦于以下问题:Java FileUtils类的具体用法?Java FileUtils怎么用?Java FileUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileUtils类属于org.h2.store.fs包,在下文中一共展示了FileUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCipher
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
private void testCipher() throws Exception {
deleteDb("upgrade");
// Create old db
Utils.callStaticMethod("org.h2.upgrade.v1_1.Driver.load");
Connection conn = DriverManager.getConnection("jdbc:h2v1_1:" +
getBaseDir() + "/upgrade;PAGE_STORE=FALSE;" +
"CIPHER=AES", "abc", "abc abc");
Statement stat = conn.createStatement();
stat.execute("create table test(id int)");
conn.close();
assertTrue(FileUtils.exists(getBaseDir() + "/upgrade.data.db"));
// Connect to old DB with upgrade
conn = DriverManager.getConnection("jdbc:h2:" +
getBaseDir() + "/upgrade;CIPHER=AES", "abc", "abc abc");
stat = conn.createStatement();
stat.executeQuery("select * from test");
conn.close();
assertTrue(FileUtils.exists(getBaseDir() + "/upgrade.h2.db"));
deleteDb("upgrade");
}
示例2: compact
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
/**
* Copy all live pages from the source store to the target store.
*
* @param sourceFileName the name of the source store
* @param targetFileName the name of the target store
* @param compress whether to compress the data
*/
public static void compact(String sourceFileName, String targetFileName, boolean compress) {
MVStore source = new MVStore.Builder().
fileName(sourceFileName).
readOnly().
open();
FileUtils.delete(targetFileName);
MVStore.Builder b = new MVStore.Builder().
fileName(targetFileName);
if (compress) {
b.compress();
}
MVStore target = b.open();
compact(source, target);
target.close();
source.close();
}
示例3: test
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
@Override
public void test() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
FileUtils.createDirectories(getBaseDir());
FileUtils.deleteRecursive("memFS:", false);
testInterruptReopen();
testConcurrentSaveCompact();
testConcurrentDataType();
testConcurrentAutoCommitAndChange();
testConcurrentReplaceAndRead();
testConcurrentChangeAndCompact();
testConcurrentChangeAndGetVersion();
testConcurrentFree();
testConcurrentStoreAndRemoveMap();
testConcurrentStoreAndClose();
testConcurrentOnlineBackup();
testConcurrentMap();
testConcurrentIterate();
testConcurrentWrite();
testConcurrentRead();
}
示例4: testCompactFully
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
private void testCompactFully() throws Exception {
String fileName = getBaseDir() + "/testCompactFully.h3";
FileUtils.delete(fileName);
MVStore s = new MVStore.Builder().
fileName(fileName).
autoCommitDisabled().
open();
MVMap<Integer, String> m;
for (int i = 0; i < 100; i++) {
m = s.openMap("data" + i);
m.put(0, "Hello World");
s.commit();
}
for (int i = 0; i < 100; i += 2) {
m = s.openMap("data" + i);
s.removeMap(m);
s.commit();
}
long sizeOld = s.getFileStore().size();
s.compactMoveChunks();
long sizeNew = s.getFileStore().size();
assertTrue("old: " + sizeOld + " new: " + sizeNew, sizeNew < sizeOld);
s.close();
}
示例5: openFile
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
@Override
public FileStore openFile(String name, String mode, boolean mustExist) {
if (mustExist && !FileUtils.exists(name)) {
throw DbException.get(ErrorCode.FILE_NOT_FOUND_1, name);
}
FileStore store;
if (cipher == null) {
store = FileStore.open(this, name, mode);
} else {
store = FileStore.open(this, name, mode, cipher, fileEncryptionKey, 0);
}
store.setCheckedWriting(false);
try {
store.init();
} catch (DbException e) {
store.closeSilently();
throw e;
}
return store;
}
示例6: getFileNamePrefix
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
private static String getFileNamePrefix(String path, int objectId) {
String name;
int f = objectId % SysProperties.LOB_FILES_PER_DIRECTORY;
if (f > 0) {
name = SysProperties.FILE_SEPARATOR + objectId;
} else {
name = "";
}
objectId /= SysProperties.LOB_FILES_PER_DIRECTORY;
while (objectId > 0) {
f = objectId % SysProperties.LOB_FILES_PER_DIRECTORY;
name = SysProperties.FILE_SEPARATOR + f +
Constants.SUFFIX_LOBS_DIRECTORY + name;
objectId /= SysProperties.LOB_FILES_PER_DIRECTORY;
}
name = FileUtils.toRealPath(path +
Constants.SUFFIX_LOBS_DIRECTORY + name);
return name;
}
示例7: getFileList
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
private static String[] getFileList(DataHandler h, String dir) {
SmallLRUCache<String, String[]> cache = h.getLobFileListCache();
String[] list;
if (cache == null) {
list = FileUtils.newDirectoryStream(dir).toArray(new String[0]);
} else {
synchronized (cache) {
list = cache.get(dir);
if (list == null) {
list = FileUtils.newDirectoryStream(dir).toArray(new String[0]);
cache.put(dir, list);
}
}
}
return list;
}
示例8: run
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
@Override
public void run() {
while (!stopNow) {
try {
SortedProperties sp = new SortedProperties();
if (file.exists()) {
InputStream in = FileUtils.newInputStream(file.getName());
sp.load(in);
translation.putAll(sp);
} else {
OutputStream out = FileUtils.newOutputStream(file.getName(), false);
sp.putAll(translation);
sp.store(out, "Translation");
}
Thread.sleep(1000);
} catch (Exception e) {
traceError(e);
}
}
}
示例9: testReuseSpace
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
private void testReuseSpace() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases");
Statement stat = conn.createStatement();
int tableCount = getSize(2, 5);
for (int i = 0; i < tableCount; i++) {
stat.execute("create table t" + i + "(data varchar)");
}
Random random = new Random(1);
int len = getSize(50, 500);
for (int i = 0; i < len; i++) {
String table = "t" + random.nextInt(tableCount);
String sql;
if (random.nextBoolean()) {
sql = "insert into " + table + " values(space(100000))";
} else {
sql = "delete from " + table;
}
stat.execute(sql);
stat.execute("script to '" + getBaseDir() + "/test.sql'");
}
conn.close();
FileUtils.delete(getBaseDir() + "/test.sql");
}
示例10: testEmptyFieldDelimiter
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
private void testEmptyFieldDelimiter() throws Exception {
String fileName = getBaseDir() + "/test.csv";
FileUtils.delete(fileName);
Connection conn = getConnection("csv");
Statement stat = conn.createStatement();
stat.execute("call csvwrite('" + fileName
+ "', 'select 1 id, ''Hello'' name', null, '|', '', null, null, chr(10))");
InputStreamReader reader = new InputStreamReader(
FileUtils.newInputStream(fileName));
String text = IOUtils.readStringAndClose(reader, -1).trim();
text = StringUtils.replaceAll(text, "\n", " ");
assertEquals("ID|NAME 1|Hello", text);
ResultSet rs = stat.executeQuery("select * from csvread('" +
fileName + "', null, null, '|', '')");
ResultSetMetaData meta = rs.getMetaData();
assertEquals(2, meta.getColumnCount());
assertEquals("ID", meta.getColumnLabel(1));
assertEquals("NAME", meta.getColumnLabel(2));
assertTrue(rs.next());
assertEquals("1", rs.getString(1));
assertEquals("Hello", rs.getString(2));
assertFalse(rs.next());
conn.close();
FileUtils.delete(fileName);
}
示例11: verify
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
private void verify() {
MVStore s;
MVMap<Integer, byte[]> m;
FileUtils.delete(fileName);
s = new MVStore.Builder().
fileName(fileName).open();
m = s.openMap("data");
for (int i = 0; i < 100; i++) {
byte[] x = m.get(i);
if (x == null) {
break;
}
assertEquals(i * 100, x.length);
}
s.close();
}
示例12: testLarge
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
private void testLarge() throws IOException {
String fileName = getBaseDir() + "/testVeryLarge.h3";
FileUtils.delete(fileName);
final MVStore s = new MVStore.Builder().
fileName(fileName).
open();
MVMap<Long, byte[]> map = s.openMap("data");
final AtomicInteger count = new AtomicInteger();
StreamStore streamStore = new StreamStore(map) {
@Override
protected void onStore(int len) {
count.incrementAndGet();
s.commit();
}
};
long size = 1 * 1024 * 1024;
streamStore.put(new RandomStream(size, 0));
s.close();
assertEquals(4, count.get());
}
示例13: initRead
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
private void initRead() throws IOException {
if (input == null) {
try {
InputStream in = FileUtils.newInputStream(fileName);
in = new BufferedInputStream(in, Constants.IO_BUFFER_SIZE);
input = new InputStreamReader(in, characterSet);
} catch (IOException e) {
close();
throw e;
}
}
if (!input.markSupported()) {
input = new BufferedReader(input);
}
input.mark(1);
int bom = input.read();
if (bom != 0xfeff) {
// Microsoft Excel compatibility
// ignore pseudo-BOM
input.reset();
}
inputBuffer = new char[Constants.IO_BUFFER_SIZE * 2];
if (columnNames == null) {
readHeader();
}
}
示例14: testBackup
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
private void testBackup() throws SQLException {
if (config.memory) {
return;
}
deleteDb("openClose");
String url = getURL("openClose", true);
org.h2.Driver.load();
Connection conn = DriverManager.getConnection(url, "sa", "abc def");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(C CLOB)");
stat.execute("INSERT INTO TEST VALUES(SPACE(10000))");
stat.execute("BACKUP TO '" + getBaseDir() + "/test.zip'");
conn.close();
deleteDb("openClose");
Restore.execute(getBaseDir() + "/test.zip", getBaseDir(), null);
conn = DriverManager.getConnection(url, "sa", "abc def");
stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
rs.next();
assertEquals(10000, rs.getString(1).length());
assertFalse(rs.next());
conn.close();
FileUtils.delete(getBaseDir() + "/test.zip");
}
示例15: testSeparateKey
import org.h2.store.fs.FileUtils; //导入依赖的package包/类
private void testSeparateKey() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
Connection conn;
Statement stat;
String url = "mvstore;MV_STORE=TRUE";
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("create table a(id int)");
stat.execute("insert into a values(1)");
stat.execute("insert into a values(1)");
stat.execute("create table test(id int not null) as select 100");
stat.execute("create primary key on test(id)");
ResultSet rs = stat.executeQuery("select * from test where id = 100");
assertTrue(rs.next());
conn.close();
conn = getConnection(url);
stat = conn.createStatement();
rs = stat.executeQuery("select * from test where id = 100");
assertTrue(rs.next());
conn.close();
}