io.vertx.core.file.FileSystemException Java Examples
The following examples show how to use
io.vertx.core.file.FileSystemException.
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: VxApiLauncher.java From VX-API-Gateway with MIT License | 6 votes |
/** * 设置vert.x配置 */ @Override public void beforeStartingVertx(VertxOptions options) { try { byte[] bytes = Files.readAllBytes(PathUtil.getPath("conf.json")); Buffer buff = Buffer.buffer(bytes); // 总配置文件 JsonObject conf = buff.toJsonObject(); // vert.x配置文件 JsonObject vertxc = conf.getJsonObject("vertx", getDefaultVertxConfig()); initVertxConfig(vertxc, options); // 集群配置文件 JsonObject clusterc = conf.getJsonObject("cluster", new JsonObject().put("clusterType", CLUSTER_TYPE)); if (!CLUSTER_TYPE.equals(clusterc.getString("clusterType"))) { ClusterManager cmgr = VxApiClusterManagerFactory.getClusterManager(clusterc.getString("clusterType"), clusterc.getJsonObject("clusterConf", getDefaultClusterConfig())); options.setClusterManager(cmgr); options.setClustered(true); } } catch (IOException e) { throw new FileSystemException(e); } }
Example #2
Source File: YamlProcessorTest.java From vertx-config with Apache License 2.0 | 6 votes |
@Test public void testWithMissingFile(TestContext tc) { Async async = tc.async(); retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore( new ConfigStoreOptions() .setType("file") .setFormat("yaml") .setConfig(new JsonObject().put("path", "src/test/resources/some-missing-file.yaml")))); retriever.getConfig(ar -> { assertThat(ar.failed()).isTrue(); assertThat(ar.cause()).isNotNull().isInstanceOf(FileSystemException.class); async.complete(); }); }
Example #3
Source File: HoconProcessorTest.java From vertx-config with Apache License 2.0 | 6 votes |
@Test public void testWithMissingFile(TestContext tc) { Async async = tc.async(); retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore( new ConfigStoreOptions() .setType("file") .setFormat("hocon") .setConfig(new JsonObject().put("path", "src/test/resources/some-missing-file.conf")))); retriever.getConfig(ar -> { assertThat(ar.failed()).isTrue(); assertThat(ar.cause()).isNotNull().isInstanceOf(FileSystemException.class); async.complete(); }); }
Example #4
Source File: RemoteFileSyncer.java From prebid-server-java with Apache License 2.0 | 5 votes |
/** * Creates if doesn't exists and checks write permissions for the given directory. */ private static void createAndCheckWritePermissionsFor(FileSystem fileSystem, String filePath) { try { final String dirPath = Paths.get(filePath).getParent().toString(); final FileProps props = fileSystem.existsBlocking(dirPath) ? fileSystem.propsBlocking(dirPath) : null; if (props == null || !props.isDirectory()) { fileSystem.mkdirsBlocking(dirPath); } else if (!Files.isWritable(Paths.get(dirPath))) { throw new PreBidException(String.format("No write permissions for directory: %s", dirPath)); } } catch (FileSystemException | InvalidPathException e) { throw new PreBidException(String.format("Cannot create directory for file: %s", filePath), e); } }
Example #5
Source File: VendorListService.java From prebid-server-java with Apache License 2.0 | 5 votes |
/** * Creates if doesn't exists and checks write permissions for the given directory. */ private static void createAndCheckWritePermissionsFor(FileSystem fileSystem, String dir) { final FileProps props = fileSystem.existsBlocking(dir) ? fileSystem.propsBlocking(dir) : null; if (props == null || !props.isDirectory()) { try { fileSystem.mkdirsBlocking(dir); } catch (FileSystemException e) { throw new PreBidException(String.format("Cannot create directory: %s", dir), e); } } else if (!Files.isWritable(Paths.get(dir))) { throw new PreBidException(String.format("No write permissions for directory: %s", dir)); } }
Example #6
Source File: RemoteFileSyncerTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
@Test public void createShouldThrowPreBidExceptionWhenPropsThrowException() { // given reset(fileSystem); when(fileSystem.existsBlocking(eq(DIR_PATH))).thenReturn(true); when(fileSystem.propsBlocking(eq(DIR_PATH))).thenThrow(FileSystemException.class); // when and then assertThatThrownBy(() -> RemoteFileSyncer.create(SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_COUNT, RETRY_INTERVAL, TIMEOUT, UPDATE_INTERVAL, httpClient, vertx, fileSystem)) .isInstanceOf(PreBidException.class); }
Example #7
Source File: AttachmentTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testCreationFromMissingFile() { File missing = new File("missing"); Attachment attachment = new Attachment("missing", missing, "text/plain"); Assertions.assertThrows(FileSystemException.class, () -> MutinyMailerImpl.getAttachmentStream(vertx, attachment).await().indefinitely()); }
Example #8
Source File: TestReadStreamPart.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void saveToFile_notExist_notCreate() throws InterruptedException, ExecutionException, IOException { File dir = new File("target/notExist-" + UUID.randomUUID().toString()); File file = new File(dir, "a.txt"); Assert.assertFalse(dir.exists()); expectedException.expect(ExecutionException.class); expectedException.expectCause(Matchers.instanceOf(FileSystemException.class)); OpenOptions openOptions = new OpenOptions().setCreateNew(false); part.saveToFile(file, openOptions).get(); }
Example #9
Source File: FreeMarkerTemplateHander.java From VX-API-Gateway with MIT License | 5 votes |
public FreeMarkerTemplateHander(Vertx vertx, String templateDirectory, String contentType) { super(DEFAULT_TEMPLATE_EXTENSION, DEFAULT_MAX_CACHE_SIZE); this.contentType = contentType; config = new Configuration(Configuration.VERSION_2_3_28); try { config.setDirectoryForTemplateLoading(new File(templateDirectory)); } catch (IOException e) { throw new FileSystemException("not found template directory:" + templateDirectory); } config.setObjectWrapper(new VertxWebObjectWrapper(config.getIncompatibleImprovements())); config.setCacheStorage(new NullCacheStorage()); }
Example #10
Source File: JWTAuthProviderImpl.java From vertx-auth with Apache License 2.0 | 4 votes |
public JWTAuthProviderImpl(Vertx vertx, JWTAuthOptions config) { this.permissionsClaimKey = config.getPermissionsClaimKey(); this.jwtOptions = config.getJWTOptions(); final KeyStoreOptions keyStore = config.getKeyStore(); // attempt to load a Key file try { if (keyStore != null) { KeyStore ks = KeyStore.getInstance(keyStore.getType()); // synchronize on the class to avoid the case where multiple file accesses will overlap synchronized (JWTAuthProviderImpl.class) { final Buffer keystore = vertx.fileSystem().readFileBlocking(keyStore.getPath()); try (InputStream in = new ByteArrayInputStream(keystore.getBytes())) { ks.load(in, keyStore.getPassword().toCharArray()); } } // load all available keys in the keystore for (JWK key : JWK.load(ks, keyStore.getPassword(), keyStore.getPasswordProtection())) { jwt.addJWK(key); } } // attempt to load pem keys final List<PubSecKeyOptions> keys = config.getPubSecKeys(); if (keys != null) { for (PubSecKeyOptions pubSecKey : config.getPubSecKeys()) { jwt.addJWK(new JWK(pubSecKey)); } } // attempt to load jwks final List<JsonObject> jwks = config.getJwks(); if (jwks != null) { for (JsonObject jwk : jwks) { this.jwt.addJWK(new JWK(jwk)); } } } catch (KeyStoreException | IOException | FileSystemException | CertificateException | NoSuchAlgorithmException e) { throw new RuntimeException(e); } }