Search in sources :

Example 11 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class FilesTest method testLastModified.

@Test
public void testLastModified() throws IOException, NumericException {
    try (Path path = new Path()) {
        File f = temporaryFolder.newFile();
        Assert.assertTrue(Files.touch(path.of(f.getAbsolutePath()).$()));
        long t = DateFormatUtils.parseDateTime("2015-10-17T10:00:00.000Z");
        Assert.assertTrue(Files.setLastModified(path, t));
        Assert.assertEquals(t, Files.getLastModified(path));
    }
}
Also used : Path(com.questdb.std.str.Path) File(java.io.File) Test(org.junit.Test)

Example 12 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class FilesTest method testListDir.

@Test
public void testListDir() {
    String temp = temporaryFolder.getRoot().getAbsolutePath();
    ObjList<String> names = new ObjList<>();
    try (Path path = new Path().of(temp).$()) {
        try (Path cp = new Path()) {
            Assert.assertTrue(Files.touch(cp.of(temp).concat("a.txt").$()));
            NativeLPSZ name = new NativeLPSZ();
            long pFind = Files.findFirst(path);
            Assert.assertTrue(pFind != 0);
            try {
                do {
                    names.add(name.of(Files.findName(pFind)).toString());
                } while (Files.findNext(pFind) > 0);
            } finally {
                Files.findClose(pFind);
            }
        }
    }
    names.sort(Chars::compare);
    Assert.assertEquals("[.,..,a.txt]", names.toString());
}
Also used : Path(com.questdb.std.str.Path) ObjList(com.questdb.std.ObjList) NativeLPSZ(com.questdb.std.str.NativeLPSZ) Chars(com.questdb.std.Chars) Test(org.junit.Test)

Example 13 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class FilesTest method testTruncate.

@Test
public void testTruncate() throws Exception {
    File temp = temporaryFolder.newFile();
    Files.writeStringToFile(temp, "abcde");
    try (Path path = new Path().of(temp.getAbsolutePath()).$()) {
        Assert.assertTrue(Files.exists(path));
        Assert.assertEquals(5, Files.length(path));
        long fd = Files.openRW(path);
        try {
            Files.truncate(fd, 3);
            Assert.assertEquals(3, Files.length(path));
            Files.truncate(fd, 0);
            Assert.assertEquals(0, Files.length(path));
        } finally {
            Files.close(fd);
        }
    }
}
Also used : Path(com.questdb.std.str.Path) File(java.io.File) Test(org.junit.Test)

Example 14 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class FilesTest method testDeleteOpenFile.

@Test
public void testDeleteOpenFile() throws Exception {
    try (Path path = new Path()) {
        File f = temporaryFolder.newFile();
        long fd = Files.openRW(path.of(f.getAbsolutePath()).$());
        Assert.assertTrue(Files.exists(fd));
        Assert.assertTrue(Files.remove(path));
        Assert.assertFalse(Files.exists(fd));
        Files.close(fd);
    }
}
Also used : Path(com.questdb.std.str.Path) File(java.io.File) Test(org.junit.Test)

Example 15 with Path

use of com.questdb.std.str.Path in project questdb by bluestreak01.

the class FilesTest method testListNonExistingDir.

@Test
public void testListNonExistingDir() {
    String temp = temporaryFolder.getRoot().getAbsolutePath();
    try (Path path = new Path().of(temp).concat("xyz")) {
        long pFind = Files.findFirst(path);
        Assert.assertTrue(pFind == 0);
    }
}
Also used : Path(com.questdb.std.str.Path) Test(org.junit.Test)

Aggregations

Path (com.questdb.std.str.Path)74 Test (org.junit.Test)46 File (java.io.File)8 Rnd (com.questdb.std.Rnd)7 LPSZ (com.questdb.std.str.LPSZ)6 NativeLPSZ (com.questdb.std.str.NativeLPSZ)5 NumericException (com.questdb.common.NumericException)3 RecordColumnMetadata (com.questdb.common.RecordColumnMetadata)3 DirectCharSequence (com.questdb.std.str.DirectCharSequence)3 StringSink (com.questdb.std.str.StringSink)3 RowCursor (com.questdb.common.RowCursor)2 CreateTableModel (com.questdb.griffin.lexer.model.CreateTableModel)2 ObjList (com.questdb.std.ObjList)2 JournalMetadata (com.questdb.store.factory.configuration.JournalMetadata)2 TestMicroClock (com.questdb.test.tools.TestMicroClock)2 ByteBuffer (java.nio.ByteBuffer)2 Record (com.questdb.common.Record)1 RecordCursor (com.questdb.common.RecordCursor)1 Chars (com.questdb.std.Chars)1 FilesFacade (com.questdb.std.FilesFacade)1