Package org.jnode.fs

Examples of org.jnode.fs.FSFile


     * @param file
     * @return
     * @throws IOException
     */
    public static FSFile createFile(FSDirectory parent, String file) throws IOException {
        FSFile f = parent.addFile(file).getFile();
        ByteBuffer data = ByteBuffer.wrap(TestUtils.getTestData(FILE_SIZE_IN_WORDS));
        f.write(0, data);
        f.flush();
        return f;
    }
View Full Code Here


        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(
                getFs().getClass().getName() + ": buffer after alloc\n" + FSUtils.toString(data2.array(), 0, 512));
            file2.read(0, data2);
            log.debug(getFs().getClass().getName() + ": buffer after read\n" + FSUtils.toString(data2.array(), 0, 512));
            assertTrue("read and written data are differents", TestUtils.equals(data.array(), data2.array()));
        }
    }
View Full Code Here

            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");
            } catch (ReadOnlyFileSystemException rofse) {
                // success
            }
        }
View Full Code Here

        final String fileName = "RWTest";

        if (config.isReadOnly()) {
            byte[] data = addTestFile(fileName, FILE_SIZE_IN_WORDS);

            FSFile file = getFs().getRootEntry().getDirectory().getEntry(fileName).getFile();
            try {
                file.setLength(newSize);
                fail("setLength must throw ReadOnlyFileSystemException in readOnly mode");
            } catch (ReadOnlyFileSystemException rofse) {
                // success
            }
            assertEquals("setLength mustn't change size in readOnly mode", String.valueOf(data.length),
                String.valueOf(file.getLength()));
        } else {
            /*byte[] data =*/
            addTestFile(fileName, FILE_SIZE_IN_WORDS);

            FSFile file = getFs().getRootEntry().getDirectory().getEntry(fileName).getFile();
            file.setLength(newSize);
            assertSize("setLength must change size", newSize, file.getLength());
        }
    }
View Full Code Here

                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();

        //newFd.stop();
        newFd.close();
View Full Code Here

    @Test
    public void testRead() throws Throwable {
        setUp();

        FSFile file = prepareFile(config);

        Monitor monitor = new Monitor("testRead");

        createReaders(monitor, file);
View Full Code Here

    @Test @Ignore("Fix concurrency issues")
    public void testWrite() throws Throwable {
        if (!config.isReadOnly()) {
            setUp();

            FSFile file = prepareFile(config);
            Monitor monitor = new Monitor("testWrite");
            createWriters(monitor, file);
            monitor.waitAll();
            assertTrue("integrity test failed", isGoodResultFile(file));
        }
View Full Code Here

    @Test @Ignore("Fix concurrency issues")
    public void testReadWrite() throws Throwable {
        setUp();

        FSFile file = prepareFile(config);
        Monitor monitor = new Monitor("testReadWrite");
        createReaders(monitor, file);
        if (!config.isReadOnly()) {
            createWriters(monitor, file);
        }
View Full Code Here

        remountFS(config, false);

        final String fileName = "RWTest";
        FSEntry rootEntry = getFs().getRootEntry();
        FSEntry entry = rootEntry.getDirectory().addFile(fileName);
        FSFile file = entry.getFile();
        file.setLength(FILE_SIZE_IN_WORDS * 2);
        file.flush();
        assertSize("Bad file size", FILE_SIZE_IN_WORDS * 2, file.getLength());

        remountFS(config, getFs().isReadOnly());

        rootEntry = getFs().getRootEntry();
        entry = rootEntry.getDirectory().getEntry(fileName);
        file = entry.getFile();
        assertSize("Bad file size", FILE_SIZE_IN_WORDS * 2, file.getLength());

        return file;
    }
View Full Code Here

        // 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);

        return data.array();
View Full Code Here

TOP

Related Classes of org.jnode.fs.FSFile

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.