• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FileUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.h2.store.fs.FileUtils的典型用法代码示例。如果您正苦于以下问题:Java FileUtils类的具体用法?Java FileUtils怎么用?Java FileUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FileUtils类属于org.h2.store.fs包,在下文中一共展示了FileUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:TestUpgrade.java


示例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();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:MVStoreTool.java


示例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();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:TestConcurrent.java


示例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();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:25,代码来源:TestMVStore.java


示例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;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:21,代码来源:SessionRemote.java


示例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;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:20,代码来源:ValueLob.java


示例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;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:17,代码来源:ValueLob.java


示例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);
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:21,代码来源:WebServer.java


示例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");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:25,代码来源:TestCases.java


示例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);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:26,代码来源:TestCsv.java


示例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();
    }
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:19,代码来源:TestKillProcessWhileWriting.java


示例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());
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:21,代码来源:TestStreamStore.java


示例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();
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:27,代码来源:Csv.java


示例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");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:25,代码来源:TestOpenClose.java


示例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();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:26,代码来源:TestMVTableEngine.java


示例16: testErrorUpgrading

import org.h2.store.fs.FileUtils; //导入依赖的package包/类
private void testErrorUpgrading() throws Exception {
    deleteDb("upgrade");
    OutputStream out;
    out = FileUtils.newOutputStream(getBaseDir() + "/upgrade.data.db", false);
    out.write(new byte[10000]);
    out.close();
    out = FileUtils.newOutputStream(getBaseDir() + "/upgrade.index.db", false);
    out.write(new byte[10000]);
    out.close();
    assertThrows(ErrorCode.FILE_VERSION_ERROR_1, this).
            getConnection("upgrade");

    assertTrue(FileUtils.exists(getBaseDir() + "/upgrade.data.db"));
    assertTrue(FileUtils.exists(getBaseDir() + "/upgrade.index.db"));
    deleteDb("upgrade");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:17,代码来源:TestUpgrade.java


示例17: testTimeout

import org.h2.store.fs.FileUtils; //导入依赖的package包/类
private void testTimeout() throws Exception {
    FileUtils.deleteRecursive(getBaseDir(), true);
    Connection conn;
    Connection conn2;
    Statement stat;
    Statement stat2;
    String url = "mvstore;MV_STORE=TRUE;MVCC=TRUE";
    url = getURL(url, true);
    conn = getConnection(url);
    stat = conn.createStatement();
    stat.execute("create table test(id identity, name varchar)");
    conn2 = getConnection(url);
    stat2 = conn2.createStatement();
    conn.setAutoCommit(false);
    conn2.setAutoCommit(false);
    stat.execute("insert into test values(1, 'Hello')");
    assertThrows(ErrorCode.LOCK_TIMEOUT_1, stat2).
            execute("insert into test values(1, 'Hello')");
    conn2.close();
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:22,代码来源:TestMVTableEngine.java


示例18: 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;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:28,代码来源:FileStore.java


示例19: write

import org.h2.store.fs.FileUtils; //导入依赖的package包/类
/**
 * Write a number of bytes.
 *
 * @param b the source buffer
 * @param off the offset
 * @param len the number of bytes to write
 */
public void write(byte[] b, int off, int len) {
    if (SysProperties.CHECK && (len < 0 ||
            len % Constants.FILE_BLOCK_SIZE != 0)) {
        DbException.throwInternalError(
                "unaligned write " + name + " len " + len);
    }
    checkWritingAllowed();
    checkPowerOff();
    try {
        FileUtils.writeFully(file, ByteBuffer.wrap(b, off, len));
    } catch (IOException e) {
        closeFileSilently();
        throw DbException.convertIOException(e, name);
    }
    filePos += len;
    fileLength = Math.max(filePos, fileLength);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:25,代码来源:FileStore.java


示例20: setLength

import org.h2.store.fs.FileUtils; //导入依赖的package包/类
/**
 * Set the length of the file. This will expand or shrink the file.
 *
 * @param newLength the new file size
 */
public void setLength(long newLength) {
    if (SysProperties.CHECK && newLength % Constants.FILE_BLOCK_SIZE != 0) {
        DbException.throwInternalError(
                "unaligned setLength " + name + " pos " + newLength);
    }
    checkPowerOff();
    checkWritingAllowed();
    try {
        if (newLength > fileLength) {
            long pos = filePos;
            file.position(newLength - 1);
            FileUtils.writeFully(file, ByteBuffer.wrap(new byte[1]));
            file.position(pos);
        } else {
            file.truncate(newLength);
        }
        fileLength = newLength;
    } catch (IOException e) {
        closeFileSilently();
        throw DbException.convertIOException(e, name);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:28,代码来源:FileStore.java



注:本文中的org.h2.store.fs.FileUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InviteEvent类代码示例发布时间:2022-05-22
下一篇:
Java DbException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap