Search in sources :

Example 1 with FileSystemException

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;
        }
    };
}
Also used : FileSystemException(io.vertx.core.file.FileSystemException) RandomAccessFile(java.io.RandomAccessFile) IOException(java.io.IOException)

Example 2 with FileSystemException

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);
}
Also used : FileSystemException(io.vertx.core.file.FileSystemException) IOException(java.io.IOException)

Example 3 with FileSystemException

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);
            }
        }
    };
}
Also used : Path(java.nio.file.Path) FileStore(java.nio.file.FileStore) FileSystemException(io.vertx.core.file.FileSystemException) IOException(java.io.IOException)

Example 4 with FileSystemException

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);
            }
        }
    };
}
Also used : Path(java.nio.file.Path) FileSystemException(io.vertx.core.file.FileSystemException) IOException(java.io.IOException)

Example 5 with FileSystemException

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;
        }
    };
}
Also used : Path(java.nio.file.Path) FileSystemException(io.vertx.core.file.FileSystemException) IOException(java.io.IOException)

Aggregations

FileSystemException (io.vertx.core.file.FileSystemException)14 IOException (java.io.IOException)14 Path (java.nio.file.Path)11 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3 RandomAccessFile (java.io.RandomAccessFile)2 FileVisitResult (java.nio.file.FileVisitResult)2 Buffer (io.vertx.core.buffer.Buffer)1 AsyncFile (io.vertx.core.file.AsyncFile)1 File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 FileStore (java.nio.file.FileStore)1 GroupPrincipal (java.nio.file.attribute.GroupPrincipal)1 PosixFileAttributeView (java.nio.file.attribute.PosixFileAttributeView)1 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)1 UserPrincipal (java.nio.file.attribute.UserPrincipal)1 UserPrincipalLookupService (java.nio.file.attribute.UserPrincipalLookupService)1 ArrayList (java.util.ArrayList)1