private BlockingAction<Boolean> existsInternal(String path, Handler<AsyncResult<Boolean>> handler) { Objects.requireNonNull(path); return new BlockingAction<Boolean>(handler) { File file = vertx.resolveFile(path); public Boolean perform() { return file.exists(); } }; }
public Void perform() { try { Path source = vertx.resolveFile(from).toPath(); Path target = vertx.resolveFile(to).toPath(); Files.move(source, target, copyOptions); } catch (IOException e) { throw new FileSystemException(e); } return null; } };
public Void perform() { try { Path source = vertx.resolveFile(from).toPath(); Path target = vertx.resolveFile(to).toPath(); Files.copy(source, target, copyOptions); } catch (IOException e) { throw new FileSystemException(e); } return null; } };
public AsyncFile perform() { String path = vertx.resolveFile(p).getAbsolutePath(); return doOpen(path, options, context); } };
public Buffer perform() { try { Path target = vertx.resolveFile(path).toPath(); byte[] bytes = Files.readAllBytes(target); Buffer buff = Buffer.buffer(bytes); return buff; } catch (IOException e) { throw new FileSystemException(e); } } };
public Void perform() { try { Path target = vertx.resolveFile(p).toPath(); if (attrs != null) { Files.createFile(target, attrs); } else { Files.createFile(target); } } catch (IOException e) { throw new FileSystemException(e); } return null; } };
public Void perform() { try { Path target = vertx.resolveFile(path).toPath(); Files.write(target, data.getBytes()); return null; } catch (IOException e) { throw new FileSystemException(e); } } };
public String perform() { try { Path source = vertx.resolveFile(link).toPath(); return Files.readSymbolicLink(source).toString(); } catch (IOException e) { throw new FileSystemException(e); } } };
public Void perform() { try { Path source = vertx.resolveFile(path).toPath(); if (createParents) { if (attrs != null) { Files.createDirectories(source, attrs); } else { Files.createDirectories(source); } } else { if (attrs != null) { Files.createDirectory(source, attrs); } else { Files.createDirectory(source); } } } catch (IOException e) { throw new FileSystemException(e); } return null; } };
public String perform() { try { Path tmpDir; if (parentDir != null) { Path dir = vertx.resolveFile(parentDir).toPath(); if (attrs != null) { tmpDir = Files.createTempDirectory(dir, prefix, attrs); } else { tmpDir = Files.createTempDirectory(dir, prefix); } } else { if (attrs != null) { tmpDir = Files.createTempDirectory(prefix, attrs); } else { tmpDir = Files.createTempDirectory(prefix); } } return tmpDir.toFile().getAbsolutePath(); } catch (IOException e) { throw new FileSystemException(e); } } };
public String perform() { try { Path tmpFile; if (parentDir != null) { Path dir = vertx.resolveFile(parentDir).toPath(); if (attrs != null) { tmpFile = Files.createTempFile(dir, prefix, suffix, attrs); } else { tmpFile = Files.createTempFile(dir, prefix, suffix); } } else { if (attrs != null) { tmpFile = Files.createTempFile(prefix, suffix, attrs); } else { tmpFile = Files.createTempFile(prefix, suffix); } } return tmpFile.toFile().getAbsolutePath(); } catch (IOException e) { throw new FileSystemException(e); } } };
public Void perform() { try { Path source = vertx.resolveFile(link).toPath(); Path target = vertx.resolveFile(existing).toPath(); if (symbolic) { Files.createSymbolicLink(source, target); } else { Files.createLink(source, target); } } catch (IOException e) { throw new FileSystemException(e); } return null; } };
public FileProps perform() { try { Path target = vertx.resolveFile(path).toPath(); BasicFileAttributes attrs; if (followLinks) { attrs = Files.readAttributes(target, BasicFileAttributes.class); } else { attrs = Files.readAttributes(target, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); } return new FilePropsImpl(attrs); } catch (IOException e) { throw new FileSystemException(e); } } };
public Void perform() { try { Path source = vertx.resolveFile(path).toPath(); delete(source, recursive); } catch (IOException e) { throw new FileSystemException(e); } return null; } };
public Void perform() { RandomAccessFile raf = null; try { String path = vertx.resolveFile(p).getAbsolutePath(); if (len < 0) { throw new FileSystemException("Cannot truncate file to size < 0"); } if (!Files.exists(Paths.get(path))) { throw new FileSystemException("Cannot truncate file " + path + ". Does not exist"); } try { raf = new RandomAccessFile(path, "rw"); raf.setLength(len); } finally { if (raf != null) raf.close(); } } catch (IOException e) { throw new FileSystemException(e); } return null; } };
public static KeyStoreHelper create(VertxInternal vertx, TrustOptions options) throws Exception { if (options instanceof KeyCertOptions) { return create(vertx, (KeyCertOptions) options); } else if (options instanceof PemTrustOptions) { PemTrustOptions trustOptions = (PemTrustOptions) options; Stream<Buffer> certValues = trustOptions. getCertPaths(). stream(). map(path -> vertx.resolveFile(path).getAbsolutePath()). map(vertx.fileSystem()::readFileBlocking); certValues = Stream.concat(certValues, trustOptions.getCertValues().stream()); return new KeyStoreHelper(loadCA(certValues), null); } else { return null; } }
public FileSystemProps perform() { try { Path target = vertx.resolveFile(path).toPath(); FileStore fs = Files.getFileStore(target); return new FileSystemPropsImpl(fs.getTotalSpace(), fs.getUnallocatedSpace(), fs.getUsableSpace()); } catch (IOException e) { throw new FileSystemException(e); } } };
public Void perform() { try { Path target = vertx.resolveFile(path).toPath(); UserPrincipalLookupService service = target.getFileSystem().getUserPrincipalLookupService(); UserPrincipal userPrincipal = user == null ? null : service.lookupPrincipalByName(user); GroupPrincipal groupPrincipal = group == null ? null : service.lookupPrincipalByGroupName(group); if (groupPrincipal != null) { PosixFileAttributeView view = Files.getFileAttributeView(target, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); if (view == null) { throw new FileSystemException("Change group of file not supported"); } view.setGroup(groupPrincipal); } if (userPrincipal != null) { Files.setOwner(target, userPrincipal); } } catch (SecurityException e) { throw new FileSystemException("Accessed denied for chown on " + path); } catch (IOException e) { throw new FileSystemException(e); } return null; } };
@Test public void testCacheDirDeletedOnVertxClose() { VertxInternal vertx2 = (VertxInternal)vertx(); File file = vertx2.resolveFile(webRoot + "/somefile.html"); assertTrue(file.exists()); File cacheDir = file.getParentFile().getParentFile(); assertTrue(cacheDir.exists()); vertx2.close(onSuccess(v -> { assertFalse(cacheDir.exists()); testComplete(); })); await(); }
@Test public void testResolveFileFromClasspathDisableCaching() throws Exception { VertxInternal vertx = (VertxInternal) Vertx.vertx(new VertxOptions().setFileResolverCachingEnabled(false)); try { for (int i = 0; i < 2; i++) { File file = vertx.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)); } } finally { vertx.close(); } }