Package org.apache.commons.vfs2

Examples of org.apache.commons.vfs2.FileSystemOptions


    /**
     * deletes the complete structure
     */
    public void testDeleteFiles() throws Exception
    {
        final FileObject scratchFolder = createScratchFolder();

        assertEquals(scratchFolder.delete(Selectors.EXCLUDE_SELF), 4);
    }
View Full Code Here


    /**
     * 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

    {
        // 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

    /**
     * Read a file
     */
    public void testRandomRead() throws Exception
    {
        FileObject file = null;
        try
        {
            file = getReadFolder().resolveFile("file1.txt");
            RandomAccessContent ra = file.getContent().getRandomAccessContent(RandomAccessMode.READ);

            // read first byte
            byte c = ra.readByte();
            assertEquals(c, TEST_DATA.charAt(0));
            assertEquals("fp", ra.getFilePointer(), 1);

            // start at pos 4
            ra.seek(3);
            c = ra.readByte();
            assertEquals(c, TEST_DATA.charAt(3));
            assertEquals("fp", ra.getFilePointer(), 4);

            c = ra.readByte();
            assertEquals(c, TEST_DATA.charAt(4));
            assertEquals("fp", ra.getFilePointer(), 5);

            // restart at pos 4
            ra.seek(3);
            c = ra.readByte();
            assertEquals(c, TEST_DATA.charAt(3));
            assertEquals("fp", ra.getFilePointer(), 4);

            c = ra.readByte();
            assertEquals(c, TEST_DATA.charAt(4));
            assertEquals("fp", ra.getFilePointer(), 5);

            // advance to pos 11
            ra.seek(10);
            c = ra.readByte();
            assertEquals(c, TEST_DATA.charAt(10));
            assertEquals("fp", ra.getFilePointer(), 11);

            c = ra.readByte();
            assertEquals(c, TEST_DATA.charAt(11));
            assertEquals("fp", ra.getFilePointer(), 12);
        }
        finally
        {
            if (file != null)
            {
                file.close();
            }
        }
    }
View Full Code Here

        if (caps != null)
        {
            for (int i = 0; i < caps.length; i++)
            {
                final Capability cap = caps[i];
                FileSystem fs = readFolder.getFileSystem();
                if (!fs.hasCapability(cap))
                {
//                    String name = fs.getClass().getName();
//                    int index = name.lastIndexOf('.');
//                    String fsName = (index > 0) ? name.substring(index + 1) : name;
//                    System.out.println("skipping " + getName() + " because " +
View Full Code Here

        final FileObject baseFile = createScratchFolder();

        FileObject child = baseFile.resolveFile("newfile.txt");
        assertTrue(!child.exists());

        FileSystem fs = baseFile.getFileSystem();
        TestListener listener = new TestListener(child);
        fs.addListener(child, listener);

        // Create as a folder
        listener.addCreateEvent();
        child.createFolder();
        listener.assertFinished();

        // Create the folder again.  Should not get an event.
        child.createFolder();

        // Delete
        listener.addDeleteEvent();
        child.delete();
        listener.assertFinished();

        // Delete again.  Should not get an event
        child.delete();

        // Create as a file
        listener.addCreateEvent();
        child.createFile();
        listener.assertFinished();

        // Create the file again.  Should not get an event
        child.createFile();

        listener.addDeleteEvent();
        child.delete();

        // Create as a file, by writing to it.
        listener.addCreateEvent();
        child.getContent().getOutputStream().close();
        listener.assertFinished();

        // Recreate the file by writing to it
        child.getContent().getOutputStream().close();

        // Copy another file over the top
        final FileObject otherChild = baseFile.resolveFile("folder1");
        otherChild.createFolder();
        listener.addDeleteEvent();
        listener.addCreateEvent();
        child.copyFrom(otherChild, Selectors.SELECT_SELF);
        listener.assertFinished();

        fs.removeListener(child, listener);
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.vfs2.FileSystemOptions

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.