Package org.apache.commons.vfs

Examples of org.apache.commons.vfs.FileObject


    /**
     * deletes a single file
     */
    public void testDeleteFile() throws Exception
    {
        final FileObject scratchFolder = createScratchFolder();

        final FileObject file = scratchFolder.resolveFile("dir1/a.txt");

        assertTrue(file.delete());
    }
View Full Code Here


    /**
     * Deletes a non existent file
     */
    public void testDeleteNonExistantFile() throws Exception
    {
        final FileObject scratchFolder = createScratchFolder();

        final FileObject file = scratchFolder.resolveFile("dir1/aa.txt");

        assertFalse(file.delete());
    }
View Full Code Here

    /**
     * deletes files
     */
    public void testDeleteAllFiles() throws Exception
    {
        final FileObject scratchFolder = createScratchFolder();

        assertEquals(scratchFolder.delete(new FileTypeSelector(FileType.FILE)), 2);
    }
View Full Code Here

    /**
     * deletes a.txt
     */
    public void testDeleteOneFiles() throws Exception
    {
        final FileObject scratchFolder = createScratchFolder();

        assertEquals(scratchFolder.delete(new FileNameSelector("a.txt")), 1);
    }
View Full Code Here

     * Tests getting the last modified time of a file.
     */
    public void testGetLastModified() throws Exception
    {
        // Try a file.
        final FileObject file = getReadFolder().resolveFile("file1.txt");
        file.getContent().getLastModifiedTime();

        // TODO - switch this on
        // Try a folder
        //final FileObject folder = getReadFolder().resolveFile( "dir1" );
        //folder.getContent().getLastModifiedTime();
View Full Code Here

        final long now = System.currentTimeMillis();

        if (getReadFolder().getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FILE))
        {
            // Try a file
            final FileObject file = getReadFolder().resolveFile("file1.txt");
            file.getContent().setLastModifiedTime(now);
            try
            {
                assertEquals(now, file.getContent().getLastModifiedTime(), file.getFileSystem().getLastModTimeAccuracy());
            }
            catch (AssertionFailedError e)
            {
                // on linux ext3 the above check is not necessarily true
                if (file.getFileSystem().getLastModTimeAccuracy() < 1000L)
                {
                    assertEquals(now, file.getContent().getLastModifiedTime(), 1000L);
                }
                else
                {
                    throw e;
                }
            }
        }

        if (getReadFolder().getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FOLDER))
        {
            // Try a folder
            final FileObject folder = getReadFolder().resolveFile("dir1");
            folder.getContent().setLastModifiedTime(now);
            try
            {
                assertEquals(now, folder.getContent().getLastModifiedTime(), folder.getFileSystem().getLastModTimeAccuracy());
            }
            catch (AssertionFailedError e)
            {
                // on linux ext3 the above check is not necessarily true
                if (folder.getFileSystem().getLastModTimeAccuracy() < 1000L)
                {
                    assertEquals(now, folder.getContent().getLastModifiedTime(), 1000L);
                }
                else
                {
                    throw e;
                }
View Full Code Here

    public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
    {
        // Locate the base Tar file
        final String tarFilePath = AbstractVfsTestCase.getTestResource("nested.tgz").getAbsolutePath();
        String uri = "tgz:" + tarFilePath + "!/test.tgz";
        final FileObject tarFile = manager.resolveFile(uri);

        // Now build the nested file system
        final FileObject nestedFS = manager.createFileSystem(tarFile);
        return nestedFS.resolveFile("/");
    }
View Full Code Here

    {
        // Build base dir
        getManager().setBaseFile(getReadFolder());

        // Locate the base dir
        FileObject file = getManager().resolveFile(".");
        assertSame("file object", getReadFolder(), file);

        // Locate a child
        file = getManager().resolveFile("some-child");
        assertSame("file object", getReadFolder(), file.getParent());

        // Locate a descendent
        file = getManager().resolveFile("some-folder/some-file");
        assertSame("file object", getReadFolder(), file.getParent().getParent());

        // Locate parent
        file = getManager().resolveFile("..");
        assertSame("file object", getReadFolder().getParent(), file);
View Full Code Here

        // Build base dir
        getManager().setBaseFile(getReadFolder());
        final String path = getReadFolder().getName().getPath();

        // §1 Encode "some file"
        FileObject file = getManager().resolveFile("%73%6f%6d%65%20%66%69%6c%65");
        assertEquals(path + "/some file", file.getName().getPathDecoded());

        // §2 Encode "."
        file = getManager().resolveFile("%2e");
        // 18-6-2005 imario@apache.org: no need to keep the "current directory"
        // assertEquals(path + "/.", file.getName().getPathDecoded());
        assertEquals(path, file.getName().getPathDecoded());

        // §3 Encode '%'
        file = getManager().resolveFile("a%25");
        assertEquals(path + "/a%", file.getName().getPathDecoded());

        // §4 Encode /
        file = getManager().resolveFile("dir%2fchild");
        assertEquals(path + "/dir/child", file.getName().getPathDecoded());

        // §5 Encode \
        file = getManager().resolveFile("dir%5cchild");
        // 18-6-2005 imario@apache.org: all file separators normalized to "/"
        // decided to do this to get the same behaviour as in §4 on windows
        // platforms
        // assertEquals(path + "/dir\\child", file.getName().getPathDecoded());
        assertEquals(path + "/dir/child", file.getName().getPathDecoded());

        // §6 Use "%" literal
        try
        {
            getManager().resolveFile("%");
View Full Code Here

    public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
    {
        // Locate the base Tar file
        final String tarFilePath = AbstractVfsTestCase.getTestResource("nested.tbz2").getAbsolutePath();
        String uri = "tbz2:" + tarFilePath + "!/test.tbz2";
        final FileObject tarFile = manager.resolveFile(uri);

        // Now build the nested file system
        final FileObject nestedFS = manager.createFileSystem(tarFile);
        return nestedFS.resolveFile("/");
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.vfs.FileObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.