Example usage for org.apache.commons.vfs2 FileObject getChildren

List of usage examples for org.apache.commons.vfs2 FileObject getChildren

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileObject getChildren.

Prototype

FileObject[] getChildren() throws FileSystemException;

Source Link

Document

Lists the children of this file.

Usage

From source file:tain.kr.test.vfs.v01.TestVfs2FilehandleService.java

@Test
public void testCaching() throws Exception {

    String path = TestVfs2FilehandleService.class.getResource("").getPath();
    if (flag)//w w  w  .  ja  v  a  2s  . c  om
        System.out.printf("[%s]\n", path);

    String testFolder = path + "/testfolder";
    FileSystemManager manager = VFS.getManager();

    FileObject scratchFolder = manager.resolveFile(testFolder);

    // testfolder    
    scratchFolder.delete(Selectors.EXCLUDE_SELF);

    FileObject file = manager.resolveFile(path + "/testfolder/dummy.txt");
    file.createFile();

    //  Manager 
    DefaultFileSystemManager fs = new DefaultFileSystemManager();
    fs.setFilesCache(manager.getFilesCache());

    // zip, jar, tgz, tar, tbz2, file
    if (!fs.hasProvider("file")) {
        fs.addProvider("file", new DefaultLocalFileProvider());
    }

    fs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
    fs.init();

    //   
    FileObject foBase2 = fs.resolveFile(testFolder);
    if (flag)
        System.out.printf("## scratchFolder.getName().getPath() : %s\n", scratchFolder.getName().getPath());

    FileObject cachedFolder = foBase2.resolveFile(scratchFolder.getName().getPath());

    //   
    FileObject[] fos = cachedFolder.getChildren();
    assertFalse(contains(fos, "file1.txt"));

    // 
    scratchFolder.resolveFile("file1.txt").createFile();

    //  
    // BUT cachedFolder    
    fos = cachedFolder.getChildren();
    assertFalse(contains(fos, "file1.txt"));

    // 
    cachedFolder.refresh();
    //  
    fos = cachedFolder.getChildren();
    assertTrue(contains(fos, "file1.txt"));
}