Package org.jnode.fs

Examples of org.jnode.fs.FSDirectory


     * @param level
     * @throws IOException
     */
    public static void createDirAndFiles(FSDirectory parent, int level) throws IOException {
        for (int i = 0; i < FILES_DIR_PER_LEVEL; i++) {
            FSDirectory subDir = createDirectory(parent, "dir" + i);
            if (level > 0)
                createDirAndFiles(subDir, level - 1);

            createFile(parent, "file_" + level + "_" + i);
        }
View Full Code Here


    public void testWriteFileThenRemountFSAndRead() throws Exception {
        setUp();

        final String fileName = "RWTest";

        FSDirectory rootDir = getFs().getRootEntry().getDirectory();
        FSFile file = null;
        ByteBuffer data = ByteBuffer.wrap(TestUtils.getTestData(FILE_SIZE_IN_WORDS));

        if (config.isReadOnly()) {
            try {
                file = rootDir.addFile(fileName).getFile();
                fail("addFile must throw ReadOnlyFileSystemException in readOnly mode");
            } catch (ReadOnlyFileSystemException rofse) {
                // success
            }
        } else {
            file = rootDir.addFile(fileName).getFile();
            file.write(0, data);
            file.flush();

            assertSize("bad file.length after write", data.capacity(), file.getLength());
        }

        remountFS(config, config.isReadOnly());

        if (!config.isReadOnly()) {
            FSDirectory rootDir2 = getFs().getRootEntry().getDirectory();
            FSFile file2 = rootDir2.getEntry(fileName).getFile();
            assertNotNull("file not saved", file2);
            assertSize("bad file.length after remount", data.capacity(), file2.getLength());

            ByteBuffer data2 = ByteBuffer.allocate(data.capacity());
            log.debug(
View Full Code Here

            final String fileName = "RWTest";

            ByteBuffer data = ByteBuffer.wrap(addTestFile(fileName, FILE_SIZE_IN_WORDS));

            // re-get the entry to our test file
            FSDirectory rootDir2 = getFs().getRootEntry().getDirectory();
            FSFile file2 = rootDir2.getEntry(fileName).getFile();

            // In readOnly mode, writing to our file must fail
            try {
                file2.write(0, data);
                fail("write must throw ReadOnlyFileSystemException in readOnly mode");
View Full Code Here

        fs.create(params);
        fs.close();
        fs = new HfsPlusFileSystemType().create(device, false);
        fs.read();
        fs.createRootEntry();
        FSDirectory root = fs.getRootEntry().getDirectory();
        Assert.assertFalse("Must be empty", root.iterator().hasNext());
        root.addDirectory("test");
        fs.flush();
        fs.close();
        fs = new HfsPlusFileSystemType().create(device, false);
        fs.read();
        Assert.assertEquals(1, fs.getVolumeHeader().getFolderCount());
        fs.createRootEntry();
        root = fs.getRootEntry().getDirectory();
        Assert.assertTrue("Must contains one directory", root.iterator().hasNext());
    }
View Full Code Here

     *
     * @param file
     * @throws IOException
     */
    public void delete(String file) throws IOException {
        final FSDirectory parentDirectory = getParentDirectoryEntry(file);
        if (parentDirectory == null) {
            throw new IOException("Parent of " + file + " not found");
        }

        parentDirectory.remove(getName(file));
        entryCache.removeEntries(file);
    }
View Full Code Here

            FSEntry entry = entryCache.getEntry(path);
            if (entry != null) {
                return entry;
            }
            final FSDirectory parentEntry = getParentDirectoryEntry(path);
            if (parentEntry != null) {
                try {
                    entry = parentEntry.getEntry(stripParentPath(path));

                    if (entry == null) {
                        return null;
                    }
View Full Code Here

            throw new IOException("Not a file " + file);
        }
        if (entry == null) {
            if (mode.canWrite()) {
                // Try to create the file
                FSDirectory parent = getParentDirectoryEntry(file);
                if (parent == null) {
                    throw new IOException("Cannot create " + file +
                            ", parent directory does not exist");
                }

                // Ok, add the file
                entry = parent.addFile(getName(file));
            } else {
                throw new FileNotFoundException(file);
            }
        }
        return fhm.open(entry.getFile(), mode);
View Full Code Here

        FSEntry entry = getEntry(file);
        if (entry != null) {
            log.debug(file + "exists");
            return false;
        }
        FSDirectory directory = getParentDirectoryEntry(file);
        if (directory == null) {
            return false;
        }
        // Ok, add the dir
        entry = directory.addDirectory(getName(file));
        return true;
    }
View Full Code Here

    public boolean mkFile(String file, VMOpenMode mode) throws IOException {
        FSEntry entry = getEntry(file);
        if ((entry != null) || !mode.canWrite()) {
            return false;
        }
        FSDirectory directory = getParentDirectoryEntry(file);
        if (directory == null)
            return false;
        // Ok, make the file
        entry = directory.addFile(getName(file));
        return true;
    }
View Full Code Here

        // newFd.start();
        final FileSystemService fSS = InitialNaming.lookup(FileSystemService.NAME);
        FatFileSystemType type = fSS.getFileSystemType(FatFileSystemType.ID);
        FatFileSystem fs = new FatFileSystem(newFd, false, type);

        FSDirectory dir = fs.getRootEntry().getDirectory();
        FSDirectory bDir = dir.addDirectory("boot").getDirectory();
        FSDirectory bgDir = bDir.addDirectory("grub").getDirectory();

        URLConnection urlConn =
                FatTest.class.getClassLoader().getResource("menu.lst").openConnection();
        //byte[] buf = new byte[urlConn.getContentLength()];
        ByteBuffer buf = ByteBuffer.allocate(urlConn.getContentLength());
        FileUtils.copy(urlConn.getInputStream(), buf.array());

        final FSFile fh1 = dir.addFile("test.lst").getFile();
        fh1.setLength(urlConn.getContentLength());
        fh1.write(0, buf);

        final FSFile fh2 = bgDir.addFile("menu.lst").getFile();
        fh2.setLength(urlConn.getContentLength());
        fh2.write(0, buf);

        fs.flush();
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.