io.vertx.core.file.impl.FileResolver Java Examples

The following examples show how to use io.vertx.core.file.impl.FileResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestVertxUtils.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateVertxWithFileCPResolving() {
  // Prepare
  ArchaiusUtils.resetConfig();
  String cacheDirBase = System.getProperty(FileResolver.CACHE_DIR_BASE_PROP_NAME,
      System.getProperty("java.io.tmpdir", ".") + File.separator + "vertx-cache");
  File file = new File(cacheDirBase);

  // create .vertx folder
  FileUtils.deleteQuietly(file);
  Assert.assertFalse(file.exists());
  ArchaiusUtils.setProperty(FileResolver.DISABLE_CP_RESOLVING_PROP_NAME, false);
  VertxUtils.getOrCreateVertxByName("testCreateVertxWithFileCPResolvingFalse", null);
  Assert.assertTrue(file.exists());
  VertxUtils.blockCloseVertxByName("testCreateVertxWithFileCPResolvingFalse");

  // don't create .vertx folder
  FileUtils.deleteQuietly(file);
  Assert.assertFalse(file.exists());
  ArchaiusUtils.setProperty(FileResolver.DISABLE_CP_RESOLVING_PROP_NAME, true);
  VertxUtils.getOrCreateVertxByName("testCreateVertxWithFileCPResolvingTrue", null);
  Assert.assertFalse(file.exists());
  VertxUtils.blockCloseVertxByName("testCreateVertxWithFileCPResolvingTrue");

  ArchaiusUtils.resetConfig();
}
 
Example #2
Source File: VertxVaadinService.java    From vertx-vaadin with MIT License 5 votes vote down vote up
private URL tryResolveFile(String path) {
    FileSystem fileSystem = getVertx().fileSystem();
    String relativePath = makePathRelative(path);
    if (fileSystem.existsBlocking(relativePath)) {
        try {
            return new FileResolver()
                .resolveFile(relativePath).toURI().toURL();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    return null;
}
 
Example #3
Source File: ClientVerticle.java    From VX-API-Gateway with MIT License 5 votes vote down vote up
/**
 * 获得模板的路径
 * 
 * @return
 */
public String getTemplateRoot() {
	if (PathUtil.isJarEnv()) {
		FileResolver fileResolver = new FileResolver();
		File file = fileResolver.resolveFile(new File(PathUtil.getPathString("templates")).getPath());
		return (file.getPath().startsWith("/") ? "" : "/") + file.getPath();
	} else {
		return "target/classes/templates";
	}

}
 
Example #4
Source File: VertxMetricsFactoryImpl.java    From vertx-dropwizard-metrics with Apache License 2.0 5 votes vote down vote up
private JsonObject loadOptionsFile(String configPath, FileResolver fileResolver) {
  File file = fileResolver.resolveFile(configPath);
  try (Scanner scanner = new Scanner(file)) {
    scanner.useDelimiter("\\A");
    String metricsConfigString = scanner.next();

    return new JsonObject(metricsConfigString);
  } catch (IOException ioe) {
    logger.error("Error while reading metrics config file", ioe);
  } catch (DecodeException de) {
    logger.error("Error while decoding metrics config file into JSON", de);
  }

  return new JsonObject();
}
 
Example #5
Source File: AmazonLambdaHttpProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
/**
 * Lambda provides /tmp for temporary files. Set vertx cache dir
 */
@BuildStep
void setTempDir(BuildProducer<SystemPropertyBuildItem> systemProperty) {
    systemProperty.produce(new SystemPropertyBuildItem(FileResolver.CACHE_DIR_BASE_PROP_NAME, "/tmp"));
}
 
Example #6
Source File: VertxUtils.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
/**
 * 配置vertx的文件缓存功能,默认关闭
 */
protected static void configureVertxFileCaching(VertxOptions vertxOptions) {
  boolean disableFileCPResolving = DynamicPropertyFactory.getInstance()
      .getBooleanProperty(FileResolver.DISABLE_CP_RESOLVING_PROP_NAME, true).get();
  vertxOptions.getFileSystemOptions().setClassPathResolvingEnabled(!disableFileCPResolving);
}
 
Example #7
Source File: VertxTestBase.java    From Lealone-Plugins with Apache License 2.0 4 votes vote down vote up
private static void setVertxProperties() {
    System.setProperty(FileResolver.DISABLE_FILE_CACHING_PROP_NAME, "true");
    System.setProperty(FileResolver.DISABLE_CP_RESOLVING_PROP_NAME, "true");
    System.setProperty(FileResolver.CACHE_DIR_BASE_PROP_NAME, "./" + TEST_DIR + "/.vertx");
}
 
Example #8
Source File: VertxNetServerStart.java    From Lealone-Plugins with Apache License 2.0 4 votes vote down vote up
private static void setVertxProperties() {
    System.setProperty(FileResolver.DISABLE_FILE_CACHING_PROP_NAME, "true");
    System.setProperty(FileResolver.DISABLE_CP_RESOLVING_PROP_NAME, "true");
    System.setProperty(FileResolver.CACHE_DIR_BASE_PROP_NAME,
            "./" + org.lealone.test.TestBase.TEST_DIR + "/.vertx");
}