当前位置: 首页>>代码示例>>Java>>正文


Java FileUtils.size方法代码示例

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


在下文中一共展示了FileUtils.size方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: open

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Open the file and read the header.
 */
public synchronized void open() {
    try {
        metaRootPageId.put(META_TABLE_ID, PAGE_ID_META_ROOT);
        if (FileUtils.exists(fileName)) {
            long length = FileUtils.size(fileName);
            if (length < MIN_PAGE_COUNT * PAGE_SIZE_MIN) {
                if (database.isReadOnly()) {
                    throw DbException.get(
                            ErrorCode.FILE_CORRUPTED_1, fileName + " length: " + length);
                }
                // the database was not fully created
                openNew();
            } else {
                openExisting();
            }
        } else {
            openNew();
        }
    } catch (DbException e) {
        close();
        throw e;
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:27,代码来源:PageStore.java

示例2: testReuseDiskSpace

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testReuseDiskSpace() throws Exception {
    FileUtils.deleteRecursive(getBaseDir(), true);
    String dbName = "mvstore;MV_STORE=TRUE";
    Connection conn;
    Statement stat;
    long maxSize = 0;
    for (int i = 0; i < 20; i++) {
        conn = getConnection(dbName);
        Database db = (Database) ((JdbcConnection) conn).
                getSession().getDataHandler();
        db.getMvStore().getStore().setRetentionTime(0);
        stat = conn.createStatement();
        stat.execute("create table test(id int primary key, data varchar)");
        stat.execute("insert into test select x, space(1000) " +
                "from system_range(1, 1000)");
        stat.execute("drop table test");
        conn.close();
        long size = FileUtils.size(getBaseDir() + "/mvstore"
                + Constants.SUFFIX_MV_FILE);
        if (i < 10) {
            maxSize = (int) (Math.max(size, maxSize) * 1.1);
        } else if (size > maxSize) {
            fail(i + " size: " + size + " max: " + maxSize);
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:27,代码来源:TestMVTableEngine.java

示例3: testReuseSpace

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testReuseSpace() {
    String fileName = getBaseDir() + "/testReuseSpace.h3";
    FileUtils.delete(fileName);
    long initialLength = 0;
    for (int j = 0; j < 20; j++) {
        MVStore s = openStore(fileName);
        s.setRetentionTime(0);
        MVMap<Integer, String> m = s.openMap("data");
        for (int i = 0; i < 10; i++) {
            m.put(i, "Hello");
        }
        s.commit();
        for (int i = 0; i < 10; i++) {
            assertEquals("Hello", m.get(i));
            assertEquals("Hello", m.remove(i));
        }
        s.close();
        long len = FileUtils.size(fileName);
        if (initialLength == 0) {
            initialLength = len;
        } else {
            assertTrue("len: " + len + " initial: " + initialLength + " j: " + j,
                    len <= initialLength * 2);
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:27,代码来源:TestMVStore.java

示例4: setKeystore

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private static void setKeystore() throws IOException {
    Properties p = System.getProperties();
    if (p.getProperty(KEYSTORE_KEY) == null) {
        String fileName = KEYSTORE;
        byte[] data = getKeyStoreBytes(getKeyStore(
                KEYSTORE_PASSWORD), KEYSTORE_PASSWORD);
        boolean needWrite = true;
        if (FileUtils.exists(fileName) && FileUtils.size(fileName) == data.length) {
            // don't need to overwrite the file if it did not change
            InputStream fin = FileUtils.newInputStream(fileName);
            byte[] now = IOUtils.readBytesAndClose(fin, 0);
            if (now != null && Arrays.equals(data, now)) {
                needWrite = false;
            }
        }
        if (needWrite) {
            try {
                OutputStream out = FileUtils.newOutputStream(fileName, false);
                out.write(data);
                out.close();
            } catch (Exception e) {
                throw DbException.convertToIOException(e);
            }
        }
        String absolutePath = FileUtils.toRealPath(fileName);
        System.setProperty(KEYSTORE_KEY, absolutePath);
    }
    if (p.getProperty(KEYSTORE_PASSWORD_KEY) == null) {
        System.setProperty(KEYSTORE_PASSWORD_KEY, KEYSTORE_PASSWORD);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:32,代码来源:CipherFactory.java

示例5: writeFile

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private synchronized void writeFile(String s, Throwable t) {
    try {
        if (checkSize++ >= CHECK_SIZE_EACH_WRITES) {
            checkSize = 0;
            closeWriter();
            if (maxFileSize > 0 && FileUtils.size(fileName) > maxFileSize) {
                String old = fileName + ".old";
                FileUtils.delete(old);
                FileUtils.move(fileName, old);
            }
        }
        if (!openWriter()) {
            return;
        }
        printWriter.println(s);
        if (t != null) {
            if (levelFile == ERROR && t instanceof JdbcSQLException) {
                JdbcSQLException se = (JdbcSQLException) t;
                int code = se.getErrorCode();
                if (ErrorCode.isCommon(code)) {
                    printWriter.println(t.toString());
                } else {
                    t.printStackTrace(printWriter);
                }
            } else {
                t.printStackTrace(printWriter);
            }
        }
        printWriter.flush();
        if (closed) {
            closeWriter();
        }
    } catch (Exception e) {
        logWritingError(e);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:37,代码来源:TraceSystem.java

示例6: log

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
@Override
public void log(int op, String fileName, byte[] data, long x) {
    if (op != Recorder.WRITE && op != Recorder.TRUNCATE) {
        return;
    }
    if (!fileName.endsWith(Constants.SUFFIX_PAGE_FILE) &&
            !fileName.endsWith(Constants.SUFFIX_MV_FILE)) {
        return;
    }
    writeCount++;
    if ((writeCount % testEvery) != 0) {
        return;
    }
    if (FileUtils.size(fileName) > maxFileSize) {
        // System.out.println(fileName + " " + IOUtils.length(fileName));
        return;
    }
    if (testing) {
        // avoid deadlocks
        return;
    }
    testing = true;
    PrintWriter out = null;
    try {
        out = new PrintWriter(
                new OutputStreamWriter(
                FileUtils.newOutputStream(fileName + ".log", true)));
        testDatabase(fileName, out);
    } catch (IOException e) {
        throw DbException.convertIOException(e, null);
    } finally {
        IOUtils.closeSilently(out);
        testing = false;
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:36,代码来源:RecoverTester.java

示例7: addFiles

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private static long addFiles(String dir, ArrayList<String> list) {
    long size = 0;
    for (String s : FileUtils.newDirectoryStream(dir)) {
        if (FileUtils.isDirectory(s)) {
            size += addFiles(s, list);
        } else {
            size += FileUtils.size(s);
        }
        list.add(s);
    }
    return size;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:13,代码来源:ArchiveToolStore.java

示例8: testDeleteGlobalTempTableWhenClosing

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testDeleteGlobalTempTableWhenClosing() throws SQLException {
    if (config.memory) {
        return;
    }
    if (config.mvStore) {
        return;
    }
    deleteDb("tempTables");
    Connection conn = getConnection("tempTables");
    Statement stat = conn.createStatement();
    stat.execute("create global temporary table test(id int, data varchar)");
    stat.execute("insert into test " +
                "select x, space(1000) from system_range(1, 1000)");
    stat.execute("shutdown compact");
    try {
        conn.close();
    } catch (SQLException e) {
        // expected
    }
    String dbName = getBaseDir() + "/tempTables" + Constants.SUFFIX_PAGE_FILE;
    long before = FileUtils.size(dbName);
    assertTrue(before > 0);
    conn = getConnection("tempTables");
    conn.close();
    long after = FileUtils.size(dbName);
    assertEquals(after, before);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:28,代码来源:TestTempTables.java

示例9: test

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
@Override
public void test() throws SQLException {
    if (config.memory) {
        return;
    }
    deleteDb("spaceReuse");
    long max = 0, now = 0, min = Long.MAX_VALUE;
    for (int i = 0; i < 20; i++) {
        Connection conn = getConnection("spaceReuse");
        Statement stat = conn.createStatement();
        stat.execute("set retention_time 0");
        stat.execute("create table if not exists t(i int)");
        stat.execute("insert into t select x from system_range(1, 500)");
        conn.close();
        conn = getConnection("spaceReuse");
        conn.createStatement().execute("delete from t");
        conn.close();
        String fileName = getBaseDir() + "/spaceReuse";
        if (Constants.VERSION_MINOR >= 4) {
            fileName += Constants.SUFFIX_MV_FILE;
        } else {
            fileName += Constants.SUFFIX_PAGE_FILE;
        }
        now = FileUtils.size(fileName);
        assertTrue(now > 0);
        if (i < 10) {
            max = Math.max(max, now);
        } else {
            min = Math.min(min, now);
        }
    }
    assertTrue("min: " + min + " max: " + max, min <= max);
    deleteDb("spaceReuse");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:35,代码来源:TestSpaceReuse.java

示例10: testCompressed

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testCompressed() {
    String fileName = getBaseDir() + "/testCompressed.h3";
    long lastSize = 0;
    for (int level = 0; level <= 2; level++) {
        FileUtils.delete(fileName);
        MVStore.Builder builder = new MVStore.Builder().fileName(fileName);
        if (level == 1) {
            builder.compress();
        } else if (level == 2) {
            builder.compressHigh();
        }
        MVStore s = builder.open();
        MVMap<String, String> map = s.openMap("data");
        String data = new String(new char[1000]).replace((char) 0, 'x');
        for (int i = 0; i < 400; i++) {
            map.put(data + i, data);
        }
        s.close();
        long size = FileUtils.size(fileName);
        if (level > 0) {
            assertTrue(size < lastSize);
        }
        lastSize = size;
        s = new MVStore.Builder().fileName(fileName).open();
        map = s.openMap("data");
        for (int i = 0; i < 400; i++) {
            assertEquals(data, map.get(data + i));
        }
        s.close();
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:32,代码来源:TestMVStore.java

示例11: testTruncateFile

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testTruncateFile() {
    String fileName = getBaseDir() + "/testTruncate.h3";
    FileUtils.delete(fileName);
    MVStore s;
    MVMap<Integer, String> m;
    s = openStore(fileName);
    m = s.openMap("data");
    String data = new String(new char[10000]).replace((char) 0, 'x');
    for (int i = 1; i < 10; i++) {
        m.put(i, data);
        s.commit();
    }
    s.close();
    long len = FileUtils.size(fileName);
    s = openStore(fileName);
    s.setRetentionTime(0);
    // remove 75%
    m = s.openMap("data");
    for (int i = 0; i < 10; i++) {
        if (i % 4 != 0) {
            m.remove(i);
        }
    }
    s.commit();
    assertTrue(s.compact(100, 50 * 1024));
    s.close();
    long len2 = FileUtils.size(fileName);
    assertTrue("len2: " + len2 + " len: " + len, len2 < len);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:30,代码来源:TestMVStore.java

示例12: testCompact

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testCompact() {
    String fileName = getBaseDir() + "/testCompact.h3";
    FileUtils.createDirectories(getBaseDir());
    FileUtils.delete(fileName);
    // store with a very small page size, to make sure
    // there are many leaf pages
    MVStore s = new MVStore.Builder().
            pageSplitSize(1000).
            fileName(fileName).autoCommitDisabled().open();
    MVMap<Integer, String> map = s.openMap("data");
    for (int i = 0; i < 10; i++) {
        map.put(i, "Hello World " + i * 10);
        if (i % 3 == 0) {
            s.commit();
        }
    }
    for (int i = 0; i < 20; i++) {
        map = s.openMap("data" + i);
        for (int j = 0; j < i * i; j++) {
            map.put(j, "Hello World " + j * 10);
        }
        s.commit();
    }
    MVRTreeMap<String> rTreeMap = s.openMap("rtree", new MVRTreeMap.Builder<String>());
    Random r = new Random(1);
    for (int i = 0; i < 10; i++) {
        float x = r.nextFloat();
        float y = r.nextFloat();
        float width = r.nextFloat() / 10;
        float height = r.nextFloat() / 10;
        SpatialKey k = new SpatialKey(i, x, x + width, y, y + height);
        rTreeMap.put(k, "Hello World " + i * 10);
        if (i % 3 == 0) {
            s.commit();
        }
    }
    s.close();

    MVStoreTool.compact(fileName, fileName + ".new", false);
    MVStoreTool.compact(fileName, fileName + ".new.compress", true);
    MVStore s1 = new MVStore.Builder().
            fileName(fileName).readOnly().open();
    MVStore s2 = new MVStore.Builder().
            fileName(fileName + ".new").readOnly().open();
    MVStore s3 = new MVStore.Builder().
            fileName(fileName + ".new.compress").readOnly().open();
    assertEquals(s1, s2);
    assertEquals(s1, s3);
    s1.close();
    s2.close();
    s3.close();
    long size1 = FileUtils.size(fileName);
    long size2 = FileUtils.size(fileName + ".new");
    long size3 = FileUtils.size(fileName + ".new.compress");
    assertTrue("size1: " + size1 + " size2: " + size2 + " size3: " + size3,
            size2 < size1 && size3 < size2);
    MVStoreTool.compact(fileName, false);
    assertEquals(size2, FileUtils.size(fileName));
    MVStoreTool.compact(fileName, true);
    assertEquals(size3, FileUtils.size(fileName));
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:62,代码来源:TestMVStoreTool.java

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

示例14: testShrinkDatabaseFile

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testShrinkDatabaseFile() throws Exception {
    FileUtils.deleteRecursive(getBaseDir(), true);
    String dbName = "mvstore" +
            ";MV_STORE=TRUE";
    Connection conn;
    Statement stat;
    long maxSize = 0;
    // by default, the database does not shrink for 45 seconds
    int retentionTime = 45000;
    for (int i = 0; i < 20; i++) {
        // the first 10 times, keep the default retention time
        // then switch to 0, at which point the database file
        // should stop to grow
        conn = getConnection(dbName);
        stat = conn.createStatement();
        if (i == 10) {
            stat.execute("set retention_time 0");
            retentionTime = 0;
        }
        ResultSet rs = stat.executeQuery(
                "select value from information_schema.settings " +
                "where name='RETENTION_TIME'");
        assertTrue(rs.next());
        assertEquals(retentionTime, rs.getInt(1));
        stat.execute("create table test(id int primary key, data varchar)");
        stat.execute("insert into test select x, space(100) " +
                "from system_range(1, 1000)");
        // this table is kept
        if (i < 10) {
            stat.execute("create table test" + i +
                    "(id int primary key, data varchar) " +
                    "as select x, space(10) from system_range(1, 100)");
        }
        // force writing the chunk
        stat.execute("checkpoint");
        // drop the table - but the chunk is still used
        stat.execute("drop table test");
        stat.execute("checkpoint");
        stat.execute("shutdown immediately");
        try {
            conn.close();
        } catch (Exception e) {
            // ignore
        }
        String fileName = getBaseDir() + "/mvstore"
                + Constants.SUFFIX_MV_FILE;
        long size = FileUtils.size(fileName);
        if (i < 10) {
            maxSize = (int) (Math.max(size, maxSize) * 1.2);
        } else if (size > maxSize) {
            fail(i + " size: " + size + " max: " + maxSize);
        }
    }
    long sizeOld = FileUtils.size(getBaseDir() + "/mvstore"
            + Constants.SUFFIX_MV_FILE);
    conn = getConnection(dbName);
    stat = conn.createStatement();
    stat.execute("shutdown compact");
    conn.close();
    long sizeNew = FileUtils.size(getBaseDir() + "/mvstore"
            + Constants.SUFFIX_MV_FILE);
    assertTrue("new: " + sizeNew + " old: " + sizeOld, sizeNew < sizeOld);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:64,代码来源:TestMVTableEngine.java


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