Search in sources :

Example 16 with DataStore

use of org.apache.derby.impl.io.vfmem.DataStore 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 17 with DataStore

use of org.apache.derby.impl.io.vfmem.DataStore 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)

Example 18 with DataStore

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

the class VirtualFileTest method testRenameToSimple.

public void testRenameToSimple() {
    DataStore store = getStore();
    VirtualFile vFile = new VirtualFile("originalFile", store);
    assertFalse(vFile.canWrite());
    vFile.createNewFile();
    assertTrue(vFile.canWrite());
    VirtualFile newFile = new VirtualFile("newFile", store);
    assertFalse(newFile.exists());
    assertTrue(vFile.renameTo(newFile));
    assertFalse(vFile.exists());
    assertFalse(vFile.canWrite());
    assertTrue(newFile.exists());
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore)

Example 19 with DataStore

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

the class VirtualFileTest method testGetParentRelative.

public void testGetParentRelative() {
    DataStore store = getStore();
    VirtualFile vFile = new VirtualFile(PathUtilTest.join(NON_EXISTING_DIRS), store);
    int count = 0;
    StorageFile parent = vFile.getParentDir();
    while (parent != null) {
        count++;
        parent = parent.getParentDir();
    }
    assertEquals(4, count);
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore) StorageFile(org.apache.derby.io.StorageFile)

Example 20 with DataStore

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

the class VirtualFileTest method testCreateDirInRoot.

public void testCreateDirInRoot() {
    DataStore store = getStore();
    VirtualFile vFile = new VirtualFile("seg0", store);
    assertFalse(vFile.exists());
    vFile.mkdir();
    assertTrue(vFile.exists());
    assertTrue(vFile.isDirectory());
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore)

Aggregations

DataStore (org.apache.derby.impl.io.vfmem.DataStore)21 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