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


Java FileUtils.newDirectoryStream方法代码示例

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


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

示例1: deleteOldTempFiles

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void deleteOldTempFiles() {
    String path = FileUtils.getParent(databaseName);
    for (String name : FileUtils.newDirectoryStream(path)) {
        if (name.endsWith(Constants.SUFFIX_TEMP_FILE) &&
                name.startsWith(databaseName)) {
            // can't always delete the files, they may still be open
            FileUtils.tryDelete(name);
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:11,代码来源:Database.java

示例2: getDatabaseFiles

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Get the list of database files.
 *
 * @param dir the directory (must be normalized)
 * @param db the database name (null for all databases)
 * @param all if true, files such as the lock, trace, and lob
 *            files are included. If false, only data, index, log,
 *            and lob files are returned
 * @return the list of files
 */
public static ArrayList<String> getDatabaseFiles(String dir, String db,
        boolean all) {
    ArrayList<String> files = New.arrayList();
    // for Windows, File.getCanonicalPath("...b.") returns just "...b"
    String start = db == null ? null : (FileUtils.toRealPath(dir + "/" + db) + ".");
    for (String f : FileUtils.newDirectoryStream(dir)) {
        boolean ok = false;
        if (f.endsWith(Constants.SUFFIX_LOBS_DIRECTORY)) {
            if (start == null || f.startsWith(start)) {
                files.addAll(getDatabaseFiles(f, null, all));
                ok = true;
            }
        } else if (f.endsWith(Constants.SUFFIX_LOB_FILE)) {
            ok = true;
        } else if (f.endsWith(Constants.SUFFIX_PAGE_FILE)) {
            ok = true;
        } else if (f.endsWith(Constants.SUFFIX_MV_FILE)) {
            ok = true;
        } else if (all) {
            if (f.endsWith(Constants.SUFFIX_LOCK_FILE)) {
                ok = true;
            } else if (f.endsWith(Constants.SUFFIX_TEMP_FILE)) {
                ok = true;
            } else if (f.endsWith(Constants.SUFFIX_TRACE_FILE)) {
                ok = true;
            }
        }
        if (ok) {
            if (db == null || f.startsWith(start)) {
                String fileName = f;
                files.add(fileName);
            }
        }
    }
    return files;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:47,代码来源:FileLister.java

示例3: getDirectoryListing

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Get the directory listing for this directory.
 *
 * @param directory the directory to list
 * @param listDirectories if sub-directories should be listed
 * @return the list
 */
String getDirectoryListing(String directory, boolean listDirectories) {
    StringBuilder buff = new StringBuilder();
    for (String fileName : FileUtils.newDirectoryStream(directory)) {
        if (!FileUtils.isDirectory(fileName)
                || (FileUtils.isDirectory(fileName) && listDirectories)) {
            appendFile(buff, fileName);
        }
    }
    return buff.toString();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:18,代码来源:FtpServer.java

示例4: addFilesRecursive

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void addFilesRecursive(String f, ArrayList<String> target) {
    if (FileUtils.isDirectory(f)) {
        for (String c : FileUtils.newDirectoryStream(f)) {
            addFilesRecursive(c, target);
        }
    } else {
        target.add(getFile(f));
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:10,代码来源:FileShell.java

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

示例6: testDeleteAndDropTableWithLobs

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testDeleteAndDropTableWithLobs(boolean useDrop)
        throws SQLException {
    deleteDb("cases");
    Connection conn = getConnection("cases");
    Statement stat = conn.createStatement();
    stat.execute("CREATE TABLE TEST(id int, content BLOB)");
    stat.execute("set MAX_LENGTH_INPLACE_LOB 1");

    PreparedStatement prepared = conn.prepareStatement(
            "INSERT INTO TEST VALUES(?, ?)");
    byte[] blobContent = "BLOB_CONTENT".getBytes();
    prepared.setInt(1, 1);
    prepared.setBytes(2, blobContent);
    prepared.execute();

    if (useDrop) {
        stat.execute("DROP TABLE TEST");
    } else {
        stat.execute("DELETE FROM TEST");
    }

    conn.close();

    List<String> list = FileUtils.newDirectoryStream(getBaseDir() +
            "/cases.lobs.db");
    assertEquals("Lob file was not deleted: " + list, 0, list.size());
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:28,代码来源:TestCases.java

示例7: testTempFilesDeleted

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testTempFilesDeleted(boolean stream) throws Exception {
    FileUtils.deleteRecursive(TEMP_DIR, true);
    FileUtils.createDirectories(TEMP_DIR);
    List<String> list = FileUtils.newDirectoryStream(TEMP_DIR);
    assertEquals("Unexpected temp file: " + list, 0, list.size());
    deleteDb("lob");
    Connection conn = getConnection("lob");
    Statement stat;
    stat = conn.createStatement();
    stat.execute("create table test(id int primary key, name text)");
    PreparedStatement prep = conn.prepareStatement(
            "insert into test values(2, ?)");
    if (stream) {
        String large = new String(new char[1024 * 1024 * 2]).replace((char) 0, 'x');
        prep.setCharacterStream(1, new StringReader(large), -1);
        large = null;
        prep.execute();
    } else {
        stat.execute("insert into test values(1, space(100000))");
    }
    /*
    list = FileUtils.newDirectoryStream(TEMP_DIR);
    assertEquals("Unexpected temp file: " + list, 0, list.size());
    */
    ResultSet rs;
    rs = stat.executeQuery("select * from test");
    while (rs.next()) {
        rs.getCharacterStream("name").close();
    }
    prep.close();
    conn.close();
    list = FileUtils.newDirectoryStream(TEMP_DIR);
    assertEquals("Unexpected temp file: " + list, 0, list.size());
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:35,代码来源:TestLob.java

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

示例9: testLeftLogFiles

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testLeftLogFiles() throws Exception {
    deleteDb("fileLockSerialized");

    // without serialized
    String url;
    url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized";
    Connection conn = getConnection(url);
    Statement stat = conn.createStatement();
    stat.execute("create table test(id int)");
    stat.execute("insert into test values(0)");
    conn.close();

    List<String> filesWithoutSerialized = FileUtils
            .newDirectoryStream(getBaseDir());
    deleteDb("fileLockSerialized");

    // with serialized
    url = "jdbc:h2:" + getBaseDir() +
            "/fileLockSerialized;FILE_LOCK=SERIALIZED";
    conn = getConnection(url);
    stat = conn.createStatement();
    stat.execute("create table test(id int)");
    Thread.sleep(500);
    stat.execute("insert into test values(0)");
    conn.close();

    List<String> filesWithSerialized = FileUtils
            .newDirectoryStream(getBaseDir());
    if (filesWithoutSerialized.size() != filesWithSerialized.size()) {
        for (int i = 0; i < filesWithoutSerialized.size(); i++) {
            if (!filesWithSerialized
                    .contains(filesWithoutSerialized.get(i))) {
                System.out
                        .println("File left from 'without serialized' mode: " +
                                filesWithoutSerialized.get(i));
            }
        }
        for (int i = 0; i < filesWithSerialized.size(); i++) {
            if (!filesWithoutSerialized
                    .contains(filesWithSerialized.get(i))) {
                System.out
                        .println("File left from 'with serialized' mode: " +
                                filesWithSerialized.get(i));
            }
        }
        fail("With serialized it must create the same files than without serialized");
    }
    deleteDb("fileLockSerialized");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:50,代码来源:TestFileLockSerialized.java

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


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