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


Java FileUtils.move方法代码示例

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


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

示例1: testMoveTo

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private static void testMoveTo(String fsBase) {
    final String fileName = fsBase + "/testFile";
    final String fileName2 = fsBase + "/testFile2";
    if (FileUtils.exists(fileName)) {
        FileUtils.delete(fileName);
    }
    if (FileUtils.createFile(fileName)) {
        FileUtils.move(fileName, fileName2);
        FileUtils.createFile(fileName);
        new AssertThrows(DbException.class) {
            @Override
            public void test() {
                FileUtils.move(fileName2, fileName);
        }};
        FileUtils.delete(fileName);
        FileUtils.delete(fileName2);
        new AssertThrows(DbException.class) {
            @Override
            public void test() {
                FileUtils.move(fileName, fileName2);
        }};
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:TestFileSystem.java

示例2: compact

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Compress the store by creating a new file and copying the live pages
 * there. Temporarily, a file with the suffix ".tempFile" is created. This
 * file is then renamed, replacing the original file, if possible. If not,
 * the new file is renamed to ".newFile", then the old file is removed, and
 * the new file is renamed. This might be interrupted, so it's better to
 * compactCleanUp before opening a store, in case this method was used.
 *
 * @param fileName the file name
 * @param compress whether to compress the data
 */
public static void compact(String fileName, boolean compress) {
    String tempName = fileName + Constants.SUFFIX_MV_STORE_TEMP_FILE;
    FileUtils.delete(tempName);
    compact(fileName, tempName, compress);
    try {
        FileUtils.moveAtomicReplace(tempName, fileName);
    } catch (DbException e) {
        String newName = fileName + Constants.SUFFIX_MV_STORE_NEW_FILE;
        FileUtils.delete(newName);
        FileUtils.move(tempName, newName);
        FileUtils.delete(fileName);
        FileUtils.move(newName, fileName);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:26,代码来源:MVStoreTool.java

示例3: compactCleanUp

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Clean up if needed, in a case a compact operation was interrupted due to
 * killing the process or a power failure. This will delete temporary files
 * (if any), and in case atomic file replacements were not used, rename the
 * new file.
 *
 * @param fileName the file name
 */
public static void compactCleanUp(String fileName) {
    String tempName = fileName + Constants.SUFFIX_MV_STORE_TEMP_FILE;
    if (FileUtils.exists(tempName)) {
        FileUtils.delete(tempName);
    }
    String newName = fileName + Constants.SUFFIX_MV_STORE_NEW_FILE;
    if (FileUtils.exists(newName)) {
        if (FileUtils.exists(fileName)) {
            FileUtils.delete(newName);
        } else {
            FileUtils.move(newName, fileName);
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:MVStoreTool.java

示例4: 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

示例5: copy

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void copy(String fileName, FileStore in, byte[] key) {
    if (FileUtils.isDirectory(fileName)) {
        return;
    }
    String temp = directory + "/temp.db";
    FileUtils.delete(temp);
    FileStore fileOut;
    if (key == null) {
        fileOut = FileStore.open(null, temp, "rw");
    } else {
        fileOut = FileStore.open(null, temp, "rw", cipherType, key);
    }
    fileOut.init();
    byte[] buffer = new byte[4 * 1024];
    long remaining = in.length() - FileStore.HEADER_LENGTH;
    long total = remaining;
    in.seek(FileStore.HEADER_LENGTH);
    fileOut.seek(FileStore.HEADER_LENGTH);
    long time = System.currentTimeMillis();
    while (remaining > 0) {
        if (System.currentTimeMillis() - time > 1000) {
            out.println(fileName + ": " + (100 - 100 * remaining / total) + "%");
            time = System.currentTimeMillis();
        }
        int len = (int) Math.min(buffer.length, remaining);
        in.readFully(buffer, 0, len);
        fileOut.write(buffer, 0, len);
        remaining -= len;
    }
    in.close();
    fileOut.close();
    FileUtils.delete(fileName);
    FileUtils.move(temp, fileName);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:35,代码来源:ChangeFileEncryption.java

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

示例7: renameFile

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private static synchronized void renameFile(DataHandler handler,
        String oldName, String newName) {
    synchronized (handler.getLobSyncObject()) {
        FileUtils.move(oldName, newName);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:7,代码来源:ValueLob.java

示例8: testConvertTraceFile

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testConvertTraceFile() throws Exception {
    deleteDb("toolsConvertTraceFile");
    org.h2.Driver.load();
    String url = "jdbc:h2:" + getBaseDir() + "/toolsConvertTraceFile";
    url = getURL(url, true);
    Connection conn = getConnection(url + ";TRACE_LEVEL_FILE=3", "sa", "sa");
    Statement stat = conn.createStatement();
    stat.execute(
            "create table test(id int primary key, name varchar, amount decimal)");
    PreparedStatement prep = conn.prepareStatement(
            "insert into test values(?, ?, ?)");
    prep.setInt(1, 1);
    prep.setString(2, "Hello \\'Joe\n\\'");
    prep.setBigDecimal(3, new BigDecimal("10.20"));
    prep.executeUpdate();
    stat.execute("create table test2(id int primary key,\n" +
            "a real, b double, c bigint,\n" +
            "d smallint, e boolean, f binary, g date, h time, i timestamp)",
            Statement.NO_GENERATED_KEYS);
    prep = conn.prepareStatement(
            "insert into test2 values(1, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
    prep.setFloat(1, Float.MIN_VALUE);
    prep.setDouble(2, Double.MIN_VALUE);
    prep.setLong(3, Long.MIN_VALUE);
    prep.setShort(4, Short.MIN_VALUE);
    prep.setBoolean(5, false);
    prep.setBytes(6, new byte[] { (byte) 10, (byte) 20 });
    prep.setDate(7, java.sql.Date.valueOf("2007-12-31"));
    prep.setTime(8, java.sql.Time.valueOf("23:59:59"));
    prep.setTimestamp(9, java.sql.Timestamp.valueOf("2007-12-31 23:59:59"));
    prep.executeUpdate();
    conn.close();

    ConvertTraceFile.main("-traceFile", getBaseDir() +
            "/toolsConvertTraceFile.trace.db", "-javaClass", getBaseDir() +
            "/Test", "-script", getBaseDir() + "/test.sql");
    FileUtils.delete(getBaseDir() + "/Test.java");

    String trace = getBaseDir() + "/toolsConvertTraceFile.trace.db";
    assertTrue(FileUtils.exists(trace));
    String newTrace = getBaseDir() + "/test.trace.db";
    FileUtils.delete(newTrace);
    assertFalse(FileUtils.exists(newTrace));
    FileUtils.move(trace, newTrace);
    deleteDb("toolsConvertTraceFile");
    Player.main(getBaseDir() + "/test.trace.db");
    testTraceFile(url);

    deleteDb("toolsConvertTraceFile");
    RunScript.main("-url", url, "-user", "sa", "-script", getBaseDir() +
            "/test.sql");
    testTraceFile(url);

    deleteDb("toolsConvertTraceFile");
    FileUtils.delete(getBaseDir() + "/toolsConvertTraceFile.h2.sql");
    FileUtils.delete(getBaseDir() + "/test.sql");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:58,代码来源:TestTools.java


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