Search in sources :

Example 6 with VirtualFile

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

the class VirtualFileTest method testGetRAFNonExisting.

/**
 * Getting a random access file in write mode for a non-existing file
 * should cause the file to be created.
 */
public void testGetRAFNonExisting() throws FileNotFoundException {
    DataStore store = getStore();
    VirtualFile vFile = new VirtualFile("aNewFile.txt", store);
    assertFalse(vFile.exists());
    StorageRandomAccessFile vRAF = vFile.getRandomAccessFile("rw");
    assertNotNull(vRAF);
    assertTrue(vFile.exists());
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) StorageRandomAccessFile(org.apache.derby.io.StorageRandomAccessFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore)

Example 7 with VirtualFile

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

the class VirtualFileTest method testGetParentAbsolute.

public void testGetParentAbsolute() {
    DataStore store = getStore();
    VirtualFile vFile = new VirtualFile(PathUtilTest.joinAbs(NON_EXISTING_DIRS), store);
    int count = 0;
    StorageFile parent = vFile.getParentDir();
    while (parent != null) {
        count++;
        parent = parent.getParentDir();
    }
    assertEquals(5, 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 8 with VirtualFile

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

the class VirtualFileTest method testCreateInvalidDir.

public void testCreateInvalidDir() {
    DataStore store = getStore();
    VirtualFile vFile = new VirtualFile(PathUtilTest.join(NON_EXISTING_DIRS), store);
    assertFalse(vFile.exists());
    VirtualFile tmp = new VirtualFile("", store);
    assertTrue(tmp.mkdir());
    assertFalse("Dir creation should have failed", vFile.mkdir());
}
Also used : VirtualFile(org.apache.derby.impl.io.vfmem.VirtualFile) DataStore(org.apache.derby.impl.io.vfmem.DataStore)

Example 9 with VirtualFile

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

the class VirtualFileTest method testMkdirsValidRelative.

public void testMkdirsValidRelative() {
    DataStore store = getStore();
    VirtualFile vFile = new VirtualFile(PathUtilTest.join(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 10 with VirtualFile

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

the class VirtualFileTest method testGetRAFNonExistingReadMode.

/**
 * Getting a random access file in read mode for a non-existing file
 * should fail, and the file shouldn't be created.
 */
public void testGetRAFNonExistingReadMode() throws FileNotFoundException {
    DataStore store = getStore();
    VirtualFile vFile = new VirtualFile("aNewFile.txt", store);
    assertFalse(vFile.exists());
    try {
        vFile.getRandomAccessFile("r");
        fail("Cannot read from a non-exsiting file");
    } catch (FileNotFoundException fnfe) {
    // Expected.
    }
    assertFalse(vFile.exists());
}
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