Package org.jnode.command.util

Examples of org.jnode.command.util.AbstractDirectoryWalker$FileObject


     */
    public void testUnknownContent() throws Exception
    {

        // Try getting the content of an unknown file
        FileObject unknownFile = getReadFolder().resolveFile("unknown-file");
        FileContent content = unknownFile.getContent();
        try
        {
            content.getInputStream();
            fail();
        }
View Full Code Here


    /**
     * Tests concurrent reads on a file.
     */
    public void testConcurrentRead() throws Exception
    {
        final FileObject file = getReadFolder().resolveFile("file1.txt");
        assertTrue(file.exists());

        // Start reading from the file
        final InputStream instr = file.getContent().getInputStream();
        try
        {
            // Start reading again
            file.getContent().getInputStream().close();
        }
        finally
        {
            instr.close();
        }
View Full Code Here

    /**
     * Tests concurrent reads on different files works.
     */
    public void testConcurrentReadFiles() throws Exception
    {
        final FileObject file = getReadFolder().resolveFile("file1.txt");
        assertTrue(file.exists());
        final FileObject emptyFile = getReadFolder().resolveFile("empty.txt");
        assertTrue(emptyFile.exists());

        // Start reading from the file
        final InputStream instr = file.getContent().getInputStream();
        try
        {
View Full Code Here

     * Tests that content and file objects are usable after being closed.
     */
    public void testReuse() throws Exception
    {
        // Get the test file
        FileObject file = getReadFolder().resolveFile("file1.txt");
        assertEquals(FileType.FILE, file.getType());

        // Get the file content
        assertSameContent(FILE1_CONTENT, file);

        // Read the content again
        assertSameContent(FILE1_CONTENT, file);

        // Close the content + file
        file.getContent().close();
        file.close();

        // Read the content again
        assertSameContent(FILE1_CONTENT, file);
    }
View Full Code Here

     * Tests that input streams are cleaned up on file close.
     */
    public void testInstrCleanup() throws Exception
    {
        // Get the test file
        FileObject file = getReadFolder().resolveFile("file1.txt");
        assertEquals(FileType.FILE, file.getType());

        // Open some input streams
        final InputStream instr1 = file.getContent().getInputStream();
        assertTrue(instr1.read() == FILE1_CONTENT.charAt(0));
        final InputStream instr2 = file.getContent().getInputStream();
        assertTrue(instr2.read() == FILE1_CONTENT.charAt(0));

        // Close the file
        file.close();

        // Check
        assertTrue(instr1.read() == -1);
        assertTrue(instr2.read() == -1);
    }
View Full Code Here

        // Locate the default manager
        final FileSystemManager manager = VFS.getManager();

        // Lookup a test jar file
        final File jarFile = getTestResource("test.jar");
        FileObject file = manager.toFileObject(jarFile);
        assertNotNull(file);
        assertTrue(file.exists());
        assertSame(FileType.FILE, file.getType());

        // Expand it
        file = manager.createFileSystem(file);
        assertNotNull(file);
        assertTrue(file.exists());
        assertSame(FileType.FOLDER, file.getType());
    }
View Full Code Here

     * Determines if a file or folder should be selected.
     */
    public boolean includeFile(final FileSelectInfo fileInfo)
        throws FileSystemException
    {
        final FileObject file = fileInfo.getFile();
        if (file == currentFolder)
        {
            // Pop current folder
            assertEquals(0, children.size());
            currentFolder = currentFolder.getParent();
            currentFolderInfo = currentFolderInfo.getParent();
            children = stack.remove(0);
        }

        final String baseName = file.getName().getBaseName();

        final FileInfo childInfo = getChild(baseName);
        assertSame(childInfo.type, file.getType());

        final boolean isChild = children.remove(baseName);
        assertTrue(isChild);

        files.add(file);
View Full Code Here

     */
    public boolean traverseDescendents(final FileSelectInfo fileInfo)
        throws FileSystemException
    {
        // Check that the given file is a folder
        final FileObject folder = fileInfo.getFile();
        assertSame(FileType.FOLDER, folder.getType());

        // Locate the info for the folder
        final String baseName = folder.getName().getBaseName();
        if (currentFolder == null)
        {
            assertEquals(rootFile.baseName, baseName);
            currentFolderInfo = rootFile;
        }
        else
        {
            assertSame(currentFolder, folder.getParent());

            // Locate the info for the child, and make sure it is folder
            currentFolderInfo = getChild(baseName);
            assertSame(FileType.FOLDER, currentFolderInfo.type);
        }
View Full Code Here

    /**
     *
     */
    public void testVersioning() throws Exception
    {
        FileObject scratchFolder = createScratchFolder();
        FileSystemOptions opts = scratchFolder.getFileSystem().getFileSystemOptions();
        WebdavFileSystemConfigBuilder builder =
            (WebdavFileSystemConfigBuilder)getManager().getFileSystemConfigBuilder("webdav");
        builder.setVersioning(opts, true);
        FileObject file = getManager().resolveFile(scratchFolder, "file1.txt", opts);
        FileSystemOptions newOpts = file.getFileSystem().getFileSystemOptions();
        assertTrue(opts == newOpts);
        assertTrue(builder.isVersioning(newOpts));
        assertTrue(!file.exists());
        file.createFile();
        assertTrue(file.exists());
        assertSame(FileType.FILE, file.getType());
        assertEquals(0, file.getContent().getSize());
        assertFalse(file.isHidden());
        assertTrue(file.isReadable());
        assertTrue(file.isWriteable());
        Map<?, ?> map = file.getContent().getAttributes();
        String name = ((URLFileName)file.getName()).getUserName();
        assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
        if (name != null)
        {
            assertEquals(name, map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
        }
        assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));

        // Create the source file
        final String content = "Here is some sample content for the file.  Blah Blah Blah.";

        final OutputStream os = file.getContent().getOutputStream();
        try
        {
            os.write(content.getBytes("utf-8"));
        }
        finally
        {
            os.close();
        }
        assertSameContent(content, file);
        map = file.getContent().getAttributes();
        assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
        if (name != null)
        {
            assertEquals(name, map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
        }
View Full Code Here

    /**
     *
     */
    public void testVersioningWithCreator() throws Exception
    {
        FileObject scratchFolder = createScratchFolder();
        FileSystemOptions opts = scratchFolder.getFileSystem().getFileSystemOptions();
        WebdavFileSystemConfigBuilder builder =
            (WebdavFileSystemConfigBuilder)getManager().getFileSystemConfigBuilder("webdav");
        builder.setVersioning(opts, true);
        builder.setCreatorName(opts, "testUser");
        FileObject file = getManager().resolveFile(scratchFolder, "file1.txt", opts);
        FileSystemOptions newOpts = file.getFileSystem().getFileSystemOptions();
        assertTrue(opts == newOpts);
        assertTrue(builder.isVersioning(newOpts));
        assertTrue(!file.exists());
        file.createFile();
        assertTrue(file.exists());
        assertSame(FileType.FILE, file.getType());
        assertEquals(0, file.getContent().getSize());
        assertFalse(file.isHidden());
        assertTrue(file.isReadable());
        assertTrue(file.isWriteable());
        Map<?, ?> map = file.getContent().getAttributes();
        String name = ((URLFileName)file.getName()).getUserName();
        assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
        assertEquals(map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()),"testUser");
        if (name != null)
        {
            assertTrue(map.containsKey(DeltaVConstants.COMMENT.toString()));
            assertEquals("Modified by user " + name, map.get(DeltaVConstants.COMMENT.toString()));
        }
        assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));

        // Create the source file
        final String content = "Here is some sample content for the file.  Blah Blah Blah.";

        final OutputStream os = file.getContent().getOutputStream();
        try
        {
            os.write(content.getBytes("utf-8"));
        }
        finally
        {
            os.close();
        }
        assertSameContent(content, file);
        map = file.getContent().getAttributes();
        assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
        assertEquals(map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()),"testUser");
        if (name != null)
        {
            assertTrue(map.containsKey(DeltaVConstants.COMMENT.toString()));
View Full Code Here

TOP

Related Classes of org.jnode.command.util.AbstractDirectoryWalker$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.