use of io.vertx.core.file.FileSystemException in project vert.x by eclipse.
the class FileSystemImpl method createFileInternal.
protected BlockingAction<Void> createFileInternal(String p, String perms, Handler<AsyncResult<Void>> handler) {
Objects.requireNonNull(p);
FileAttribute<?> attrs = perms == null ? null : PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString(perms));
return new BlockingAction<Void>(handler) {
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;
}
};
}
use of io.vertx.core.file.FileSystemException in project vert.x by eclipse.
the class FileSystemImpl method mkdirInternal.
protected BlockingAction<Void> mkdirInternal(String path, String perms, boolean createParents, Handler<AsyncResult<Void>> handler) {
Objects.requireNonNull(path);
FileAttribute<?> attrs = perms == null ? null : PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString(perms));
return new BlockingAction<Void>(handler) {
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;
}
};
}
use of io.vertx.core.file.FileSystemException in project vert.x by eclipse.
the class FileSystemImpl method copyInternal.
private BlockingAction<Void> copyInternal(String from, String to, boolean recursive, Handler<AsyncResult<Void>> handler) {
Objects.requireNonNull(from);
Objects.requireNonNull(to);
return new BlockingAction<Void>(handler) {
public Void perform() {
try {
Path source = vertx.resolveFile(from).toPath();
Path target = vertx.resolveFile(to).toPath();
if (recursive) {
Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
Path targetDir = target.resolve(source.relativize(dir));
try {
Files.copy(dir, targetDir);
} catch (FileAlreadyExistsException e) {
if (!Files.isDirectory(targetDir)) {
throw e;
}
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.copy(file, target.resolve(source.relativize(file)));
return FileVisitResult.CONTINUE;
}
});
} else {
Files.copy(source, target);
}
} catch (IOException e) {
throw new FileSystemException(e);
}
return null;
}
};
}
use of io.vertx.core.file.FileSystemException in project vert.x by eclipse.
the class FileSystemImpl method readFileInternal.
private BlockingAction<Buffer> readFileInternal(String path, Handler<AsyncResult<Buffer>> handler) {
Objects.requireNonNull(path);
return new BlockingAction<Buffer>(handler) {
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);
}
}
};
}
Aggregations