Search in sources :

Example 11 with VirtualFile

use of org.apache.derby.impl.io.vfmem.VirtualFile in project derby by apache.

the class VirtualFileTest method testMkdirsInvalidRelative.

public void testMkdirsInvalidRelative() throws IOException {
    DataStore store = getStore();
    VirtualFile tmp = new VirtualFile("seg0", store);
    assertTrue(tmp.mkdir());
    tmp = new VirtualFile(PathUtilTest.join("seg0", "datafile"), store);
    assertTrue(tmp.createNewFile());
    assertTrue(tmp.exists());
    assertFalse(tmp.isDirectory());
    VirtualFile vFile = new VirtualFile(PathUtilTest.join("seg0", "datafile", "anotherdir"), store);
    assertFalse(vFile.mkdir());
    assertFalse(vFile.mkdirs());
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore)

Example 12 with VirtualFile

use of org.apache.derby.impl.io.vfmem.VirtualFile in project derby by apache.

the class VirtualFileTest method testMkdirsValidAbsolute.

public void testMkdirsValidAbsolute() {
    DataStore store = getStore();
    VirtualFile vFile = new VirtualFile(PathUtilTest.joinAbs(NON_EXISTING_DIRS), store);
    assertTrue(vFile.mkdirs());
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore)

Example 13 with VirtualFile

use of org.apache.derby.impl.io.vfmem.VirtualFile in project derby by apache.

the class VirtualFileTest method testDeleteAll.

public void testDeleteAll() throws IOException {
    DataStore store = getStore();
    String[] dirs = new String[] { "seg0", PathUtilTest.join("seg0", "dir1"), "seg1", PathUtilTest.join("seg0", "dir2") };
    for (int i = 0; i < dirs.length; i++) {
        assertTrue(new VirtualFile(dirs[i], store).mkdir());
    }
    String[] files = new String[] { PathUtilTest.join("seg0", "f1"), PathUtilTest.join("seg0", "dir1", "f1"), PathUtilTest.join("seg1", "f1"), PathUtilTest.join("seg0", "f5") };
    for (int i = 0; i < files.length; i++) {
        assertTrue(new VirtualFile(files[i], store).createNewFile());
    }
    String root = "seg0";
    VirtualFile rootToDelete = new VirtualFile(root, store);
    assertTrue(rootToDelete.deleteAll());
    for (int i = 0; i < dirs.length; i++) {
        assertEquals(!dirs[i].startsWith(root), new VirtualFile(dirs[i], store).exists());
    }
    for (int i = 0; i < files.length; i++) {
        assertEquals(!files[i].startsWith(root), new VirtualFile(files[i], store).exists());
    }
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore)

Example 14 with VirtualFile

use of org.apache.derby.impl.io.vfmem.VirtualFile in project derby by apache.

the class VirtualFileTest method testGetRAFOnDirectory.

/**
 * Opening a random access file on a directory should fail.
 */
public void testGetRAFOnDirectory() {
    DataStore store = getStore();
    VirtualFile vFile = new VirtualFile("mydir", store);
    assertTrue(vFile.mkdir());
    assertTrue(vFile.exists());
    assertTrue(vFile.isDirectory());
    // Try opening in read mode.
    try {
        vFile.getRandomAccessFile("r");
        fail("Opening a RAF on a directory should have failed");
    } catch (FileNotFoundException fnfe) {
    // Expected.
    }
    // Try opening in write mode.
    try {
        vFile.getRandomAccessFile("r");
        fail("Opening a RAF on a directory should have failed");
    } catch (FileNotFoundException fnfe) {
    // Expected.
    }
    // A few sanity checks.
    assertTrue(vFile.exists());
    assertTrue(vFile.isDirectory());
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore) FileNotFoundException(java.io.FileNotFoundException)

Example 15 with VirtualFile

use of org.apache.derby.impl.io.vfmem.VirtualFile in project derby by apache.

the class VirtualFileTest method testGetRAExistingReadOnly.

/**
 * Opens a random access file for a file which has been marked as read-only.
 * <p>
 * Opening for reading only should work, opening for writing should fail.
 */
public void testGetRAExistingReadOnly() throws FileNotFoundException {
    DataStore store = getStore();
    VirtualFile vFile = new VirtualFile("aNewFile.txt", store);
    assertFalse(vFile.exists());
    assertTrue(vFile.createNewFile());
    assertTrue(vFile.exists());
    assertTrue(vFile.setReadOnly());
    assertNotNull(vFile.getRandomAccessFile("r"));
    // Try opening in write mode, which should fail.
    try {
        vFile.getRandomAccessFile("rw");
        fail("Should not be able to open a read-only file in write mode");
    } catch (FileNotFoundException fnfe) {
    // Expected.
    }
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

DataStore (org.apache.derby.impl.io.vfmem.DataStore)19 VirtualFile (org.apache.derby.impl.io.vfmem.VirtualFile)19 FileNotFoundException (java.io.FileNotFoundException)3 StorageFile (org.apache.derby.io.StorageFile)3 StorageRandomAccessFile (org.apache.derby.io.StorageRandomAccessFile)2 File (java.io.File)1