Package org.jnode.fs

Examples of org.jnode.fs.FSDirectory


    @Test
    public void testFSTree() throws IOException, Exception {
        if (!config.isReadOnly()) {
            setUp();

            FSDirectory rootDir = getFs().getRootEntry().getDirectory();
            FSEntry dir1 = rootDir.addDirectory("dir1");
            assertNotNull("dir1 not added", rootDir.getEntry("dir1"));

            /*FSEntry dir11=*/
            dir1.getDirectory().addDirectory("dir1.1");
            assertNotNull("dir11 not added", dir1.getDirectory().getEntry("dir1.1"));

            FSDirectory gotRootDir = getFs().getRootEntry().getDirectory();
            //assertNotNull("rootDir not saved", gotRootDir);
            assertTrue("same ref (gotRootDir) after remount", gotRootDir == rootDir);

            FSEntry gotDir1 = gotRootDir.getEntry("dir1");
            //assertNotNull("dir1 not saved", gotDir1);
            assertTrue("same ref (gotDir1) after remount", gotDir1 == dir1);
            assertEquals("returned bad entry", dir1.getName(), gotDir1.getName());
        }
    }
View Full Code Here


    private void doTestFSTreeWithRemount(FSTestConfig config, String fileName) throws Exception {
        if (!config.isReadOnly()) {
            setUp();

            FSDirectory rootDir = getFs().getRootEntry().getDirectory();
            log.debug("### testFSTreeWithRemount: rootDir=\n" + FSUtils.toString(rootDir, true));

            FSEntry dir1 = rootDir.addDirectory(fileName);
            assertNotNull("'" + fileName + "' not added", rootDir.getEntry(fileName));

            log.debug("### testFSTreeWithRemount: before remountFS");
            remountFS(config, getFs().isReadOnly());
            log.debug("### testFSTreeWithRemount: after remountFS");

            FSDirectory gotRootDir = getFs().getRootEntry().getDirectory();
            assertNotNull("rootDir not saved", gotRootDir);
            assertFalse("same ref (gotRootDir) after remount", gotRootDir == rootDir);
            log.debug("### testFSTreeWithRemount: gotRootDir=\n" + FSUtils.toString(gotRootDir, true));

            FSEntry gotDir1 = gotRootDir.getEntry(fileName);
            log.debug("### testFSTreeWithRemount: after gotRootDir.getEntry");
            assertNotNull("'" + fileName + "' not saved", gotDir1);
            assertFalse("same ref (gotDir1) after remount", gotDir1 == dir1);
            assertEquals("returned bad entry", dir1.getName(), gotDir1.getName());
        }
View Full Code Here

    @Test
    public void testAddDirectory() throws Exception {

        setUp();
        FSDirectory rootDir = getFs().getRootEntry().getDirectory();
        String dirName = "A new directory.text";

        log.debug("Root dir before testAddDirectory :");
        TestUtils.listEntries(rootDir.iterator());
        if (config.isReadOnly()) {
            try {
                rootDir.addDirectory(dirName);
                fail("addDirectory must fail in readOnly mode");
            } catch (ReadOnlyFileSystemException e) {
                // success
            }
            assertContainsOnly("must be empty", rootDir.iterator(), getEmptyDirNames(config, true));
        } else {
            try {
                FSEntry entry = rootDir.addDirectory(dirName);
                // success
                log.debug("added directory entry=" + FSUtils.toString(entry, true));
            } catch (ReadOnlyFileSystemException e) {
                fail("addDirectory must succeed in read/write mode");
            }
            assertContainsOnly("must contain " + dirName, rootDir.iterator(),
                TestUtils.append(getEmptyDirNames(config, true), new String[]{dirName}));
            FSEntry gotEntry = rootDir.getEntry(dirName);
            assertNotNull("must contain the added directory", gotEntry);
            assertEquals("returned bad entry", dirName, gotEntry.getName());
        }
        log.debug("Root dir after testAddDirectory :\n" + rootDir);
        TestUtils.listEntries(rootDir.iterator());
    }
View Full Code Here

    @Test
    public void testAddFile() throws Exception {
        setUp();

        FSDirectory rootDir = getFs().getRootEntry().getDirectory();
        String fileName = "A new file.text";

        log.debug("Root dir before testAddFile :");
        TestUtils.listEntries(rootDir.iterator());
        if (config.isReadOnly()) {
            try {
                rootDir.addFile(fileName);
                fail("addFile must fail in readOnly mode");
            } catch (ReadOnlyFileSystemException e) {
                // success
            }

            assertContainsOnly("must be empty", rootDir.iterator(), getEmptyDirNames(config, true));
        } else {
            try {
                FSEntry entry = rootDir.addFile(fileName);
                // success
                log.debug("added file entry=" + FSUtils.toString(entry, true));
            } catch (ReadOnlyFileSystemException e) {
                fail("addFile must succeed in read/write mode");
            }
            assertContainsOnly("must contain " + fileName, rootDir.iterator(),
                TestUtils.append(getEmptyDirNames(config, true), new String[]{fileName}));
            FSEntry gotEntry = rootDir.getEntry(fileName);
            assertNotNull("must contain the added file", gotEntry);
            assertEquals("returned bad entry", fileName, gotEntry.getName());
        }
        log.debug("Root dir after testAddFile :\n" + rootDir);
        TestUtils.listEntries(rootDir.iterator());
    }
View Full Code Here

    public void testAddFileThenRemountFSAndGetFile() throws Exception {
        if (!config.isReadOnly()) {
            setUp();

            String filename = "a file to test.text";
            FSDirectory rootDir = getFs().getRootEntry().getDirectory();
            FSEntry entry = rootDir.addFile(filename);
            FSEntry gotEntry = rootDir.getEntry(filename);
            assertNotNull("must contain the added file", gotEntry);
            assertEquals("returned bad entry", filename, gotEntry.getName());

            log.debug("entry before remount=" + FSUtils.toString(entry, true));
            remountFS(config, config.isReadOnly());

            FSDirectory rootDir2 = getFs().getRootEntry().getDirectory();
            TestUtils.listEntries(rootDir2.iterator());
            assertFalse("same ref (rootDir) after remount", rootDir == rootDir2);
            FSEntry gotEntry2 = rootDir2.getEntry(filename);
            assertFalse("same ref (gotEntry2) after remount", gotEntry == gotEntry2);
            assertNotNull("must contain the added file", gotEntry2);
            assertEquals("returned bad entry", filename, gotEntry2.getName());
            log.debug("entry after remount=" + FSUtils.toString(gotEntry2, true));
        }
View Full Code Here

        if (!config.isReadOnly()) {
            setUp();

            String filename = "a file to test.text";
            FSDirectory rootDir = getFs().getRootEntry().getDirectory();
            /*FSEntry entry =*/
            rootDir.addFile(filename);
            FSEntry gotEntry = rootDir.getEntry(filename);
            assertNotNull("must contain the added file", gotEntry);
            assertEquals("returned bad entry", filename, gotEntry.getName());

            rootDir.remove(filename);
            assertNull("must not contain the removed file", rootDir.getEntry(filename));

            remountFS(config, config.isReadOnly());

            FSDirectory rootDir2 = getFs().getRootEntry().getDirectory();
            TestUtils.listEntries(rootDir2.iterator());
            assertFalse("same ref (rootDir) after remount", rootDir == rootDir2);
            FSEntry gotEntry2 = rootDir2.getEntry(filename);
            assertNull("must not contain the removed file: FS=" + getFs().getType().getName(), gotEntry2);
        }
    }
View Full Code Here

        boolean oldReadOnly = config.isReadOnly();

        // remount FS in write mode, and write some data to our test file
        remountFS(config, false); // false = read/write mode

        FSDirectory rootDir = fs.getRootEntry().getDirectory();
        ByteBuffer data = ByteBuffer.wrap(TestUtils.getTestData(fileSizeInWords));
        FSFile file = rootDir.addFile(fileName).getFile();
        file.write(0, data);
        file.flush();

        // remount FS in readOnly mode
        remountFS(config, oldReadOnly);
View Full Code Here

            }

        } else {
            actual.append("\n");

            FSDirectory directory = entry.getDirectory();
            Iterator<? extends FSEntry> iterator = directory.iterator();

            while (iterator.hasNext()) {
                FSEntry child = iterator.next();

                if (".".equals(child.getName()) || "..".equals(child.getName())) {
View Full Code Here

        System.out.println("NTFS : Test extreme fragmentation (" + TEST_IMAGE_FILENAME_1 + ").");
        try {
            File file = new File(TEST_IMAGE_FILENAME_1);
            Device device = new FileDevice(file, "r");
            FileSystem<?> fileSystem = new NTFSFileSystemType().create(device, true);
            FSDirectory root = fileSystem.getRootEntry().getDirectory();

            // Check the big file.  Every byte should be readable as zero, hopefully.
            FSFile bigFile = root.getEntry("bigfile.dat").getFile();
            int increment = 1024 * 1024;
            assertEquals("Wrong file length for big file", 120 * increment, bigFile.getLength());
            byte[] actual = new byte[increment];
            for (int i = 0; i < 120 * increment; i += increment) {
                bigFile.read(i, ByteBuffer.wrap(actual));
View Full Code Here

        System.out.println("NTFS : Test sparse file (" + TEST_IMAGE_FILENAME_2 + ").");
        try {
            File file = new File(TEST_IMAGE_FILENAME_2);
            Device device = new FileDevice(file, "r");
            FileSystem<?> fileSystem = new NTFSFileSystemType().create(device, true);
            FSDirectory root = fileSystem.getRootEntry().getDirectory();

            // The first file has 256 bytes of real data at the front, and the rest is sparse.
            byte[] expectedContents = new byte[10240];
            for (int i = 0; i < 256; i++) {
                expectedContents[i] = (byte) i;
            }
            FSFile sparseFile1 = root.getEntry("sparsefile1.dat").getFile();
            assertEquals("Wrong length for sparse file 2", expectedContents.length, sparseFile1.getLength());
            byte[] actualContents = new byte[expectedContents.length];
            sparseFile1.read(0, ByteBuffer.wrap(actualContents));
            Arrays.fill(actualContents, 256, 4096, (byte) 0); // slack space contains garbage, so wipe it.
            assertEquals("Wrong contents for sparse file 1", expectedContents, actualContents);
            // The second file is 100% sparse.
            expectedContents = new byte[10240];
            FSFile sparseFile2 = root.getEntry("sparsefile2.dat").getFile();
            assertEquals("Wrong length for sparse file 2", expectedContents.length, sparseFile2.getLength());
            actualContents = new byte[expectedContents.length];
            sparseFile2.read(0, ByteBuffer.wrap(actualContents));
            assertEquals("Wrong contents for sparse file 2", expectedContents, actualContents);
            fileSystem.close();
View Full Code Here

TOP

Related Classes of org.jnode.fs.FSDirectory

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.