use of io.vertx.core.file.FileSystemException in project vert.x by eclipse.
the class FileSystemImpl method truncateInternal.
private BlockingAction<Void> truncateInternal(String p, long len, Handler<AsyncResult<Void>> handler) {
Objects.requireNonNull(p);
return new BlockingAction<Void>(handler) {
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;
}
};
}
use of io.vertx.core.file.FileSystemException in project vert.x by eclipse.
the class AsyncFileImpl method doFlush.
private synchronized void doFlush(Handler<AsyncResult<Void>> handler) {
checkClosed();
context.executeBlocking(() -> {
try {
ch.force(false);
return null;
} catch (IOException e) {
throw new FileSystemException(e);
}
}, handler);
}
use of io.vertx.core.file.FileSystemException in project vert.x by eclipse.
the class FileSystemImpl method fsPropsInternal.
private BlockingAction<FileSystemProps> fsPropsInternal(String path, Handler<AsyncResult<FileSystemProps>> handler) {
Objects.requireNonNull(path);
return new BlockingAction<FileSystemProps>(handler) {
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);
}
}
};
}
use of io.vertx.core.file.FileSystemException in project vert.x by eclipse.
the class FileSystemImpl method writeFileInternal.
private BlockingAction<Void> writeFileInternal(String path, Buffer data, Handler<AsyncResult<Void>> handler) {
Objects.requireNonNull(path);
Objects.requireNonNull(data);
return new BlockingAction<Void>(handler) {
public Void perform() {
try {
Path target = vertx.resolveFile(path).toPath();
Files.write(target, data.getBytes());
return null;
} catch (IOException e) {
throw new FileSystemException(e);
}
}
};
}
use of io.vertx.core.file.FileSystemException in project vert.x by eclipse.
the class FileSystemImpl method link.
private BlockingAction<Void> link(String link, String existing, boolean symbolic, Handler<AsyncResult<Void>> handler) {
Objects.requireNonNull(link);
Objects.requireNonNull(existing);
return new BlockingAction<Void>(handler) {
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;
}
};
}
Aggregations