Search in sources :

Example 1 with FileResolver

use of io.vertx.core.impl.FileResolver in project vert.x by eclipse.

the class FileResolverTestBase method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    resolver = new FileResolver(vertx);
}
Also used : FileResolver(io.vertx.core.impl.FileResolver)

Example 2 with FileResolver

use of io.vertx.core.impl.FileResolver in project vert.x by eclipse.

the class FileResolverTestBase method testDeleteCacheDir.

@Test
public void testDeleteCacheDir() throws Exception {
    Vertx vertx2 = vertx();
    FileResolver resolver2 = new FileResolver(vertx2);
    File file = resolver2.resolveFile(webRoot + "/somefile.html");
    assertTrue(file.exists());
    File cacheDir = file.getParentFile().getParentFile();
    assertTrue(cacheDir.exists());
    resolver2.close(onSuccess(res -> {
        assertFalse(cacheDir.exists());
        vertx2.close(res2 -> {
            testComplete();
        });
    }));
    await();
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) Files(java.nio.file.Files) Vertx(io.vertx.core.Vertx) StandardOpenOption(java.nio.file.StandardOpenOption) Test(org.junit.Test) Random(java.util.Random) File(java.io.File) ArrayList(java.util.ArrayList) FileResolver(io.vertx.core.impl.FileResolver) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Assert(org.junit.Assert) Vertx(io.vertx.core.Vertx) FileResolver(io.vertx.core.impl.FileResolver) File(java.io.File) Test(org.junit.Test)

Example 3 with FileResolver

use of io.vertx.core.impl.FileResolver in project VX-API-Gateway by EliMirren.

the class ClientVerticle method getTemplateRoot.

/**
 * 获得模板的路径
 *
 * @return
 */
public String getTemplateRoot() {
    if (PathUtil.isJarEnv()) {
        FileResolver resolver = new FileResolver(vertx);
        File file = resolver.resolveFile(new File(PathUtil.getPathString("templates")).getPath());
        return "/" + file.getPath();
    } else {
        return "target/classes/templates";
    }
}
Also used : FileResolver(io.vertx.core.impl.FileResolver) File(java.io.File)

Example 4 with FileResolver

use of io.vertx.core.impl.FileResolver in project vert.x by eclipse.

the class FileResolverTestBase method testResolveFileFromClasspathDisableCaching.

@Test
public void testResolveFileFromClasspathDisableCaching() throws Exception {
    System.setProperty(FileResolver.DISABLE_FILE_CACHING_PROP_NAME, "true");
    resolver = new FileResolver(vertx);
    for (int i = 0; i < 2; i++) {
        File file = resolver.resolveFile("afile.html");
        assertTrue(file.exists());
        assertTrue(file.getPath().startsWith(".vertx" + File.separator + "file-cache-"));
        assertFalse(file.isDirectory());
        assertEquals("<html><body>afile</body></html>", readFile(file));
    }
}
Also used : FileResolver(io.vertx.core.impl.FileResolver) File(java.io.File) Test(org.junit.Test)

Example 5 with FileResolver

use of io.vertx.core.impl.FileResolver in project vertx-swagger by bobxwang.

the class Application method demo.

/**
 * a demo method about how to using vertx
 *
 * @param applicationContext
 */
private void demo(ApplicationContext applicationContext) {
    final Vertx vertx = applicationContext.getBean(Vertx.class);
    vertx.setPeriodic(1000, id -> {
        // This handler will get called every second
        System.out.println("timer fired!" + new Date().toString());
    });
    vertx.setTimer(1000, id -> {
        // this handler will called after one second, just once
        System.out.println("And one second later this is printed");
    });
    // 拦截所有消息
    vertx.eventBus().addInterceptor(event -> {
        Message message = event.message();
        logger.info(message);
        event.next();
    });
    FileResolver fileResolver = new FileResolver(vertx);
    File file = fileResolver.resolveFile("webjars/bycdao-ui/cdao/DUI.js");
    if (file != null) {
        System.out.println(file.getAbsoluteFile());
    } else {
        System.out.println("null");
    }
}
Also used : Message(io.vertx.core.eventbus.Message) Vertx(io.vertx.core.Vertx) FileResolver(io.vertx.core.impl.FileResolver) File(java.io.File) Date(java.util.Date)

Aggregations

FileResolver (io.vertx.core.impl.FileResolver)5 File (java.io.File)4 Vertx (io.vertx.core.Vertx)2 Test (org.junit.Test)2 Buffer (io.vertx.core.buffer.Buffer)1 Message (io.vertx.core.eventbus.Message)1 HttpClientOptions (io.vertx.core.http.HttpClientOptions)1 HttpMethod (io.vertx.core.http.HttpMethod)1 HttpServerOptions (io.vertx.core.http.HttpServerOptions)1 VertxInternal (io.vertx.core.impl.VertxInternal)1 Files (java.nio.file.Files)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Assert (org.junit.Assert)1