Example usage for io.vertx.core.file FileSystem move

List of usage examples for io.vertx.core.file FileSystem move

Introduction

In this page you can find the example usage for io.vertx.core.file FileSystem move.

Prototype

Future<Void> move(String from, String to, CopyOptions options);

Source Link

Document

Like #move(String,String,CopyOptions,Handler) but returns a Future of the asynchronous result

Usage

From source file:examples.CoreExamples.java

License:Open Source License

public void exampleFuture6(Vertx vertx) {

    FileSystem fs = vertx.fileSystem();
    Future<Void> startFuture = Future.future();

    Future<Void> fut1 = Future.future();
    fs.createFile("/foo", fut1.completer());

    fut1.compose(v -> {//from  w w w  . j av a2 s. co m
        // When the file is created (fut1), execute this:
        Future<Void> fut2 = Future.future();
        fs.writeFile("/foo", Buffer.buffer(), fut2.completer());
        return fut2;
    }).compose(v -> {
        // When the file is written (fut2), execute this:
        fs.move("/foo", "/bar", startFuture.completer());
    },
            // mark startFuture it as failed if any step fails.
            startFuture);
}

From source file:org.entcore.directory.pojo.ImportInfos.java

License:Open Source License

private void moveFiles(final List<String> l, final FileSystem fs, final Handler<AsyncResult<String>> handler) {
    final String p = path + File.separator + structureName
            + (isNotEmpty(structureExternalId) ? "@" + structureExternalId : "") + "_"
            + (isNotEmpty(UAI) ? UAI : "") + "_" + (isNotEmpty(overrideClass) ? overrideClass : "");
    fs.mkdir(p, new Handler<AsyncResult<Void>>() {
        @Override/*from w  w  w  .java  2 s.  co m*/
        public void handle(AsyncResult<Void> event) {
            if (event.succeeded()) {
                final AtomicInteger count = new AtomicInteger(l.size());
                for (String f : l) {
                    fs.move(f, p + File.separator + f.substring(path.length() + 1),
                            new Handler<AsyncResult<Void>>() {
                                @Override
                                public void handle(AsyncResult<Void> event2) {
                                    if (event2.succeeded()) {
                                        if (count.decrementAndGet() == 0) {
                                            handler.handle(new DefaultAsyncResult<>((String) null));
                                        }
                                    } else {
                                        count.set(-1);
                                        handler.handle(new DefaultAsyncResult<String>(event2.cause()));
                                    }
                                }
                            });
                }
            } else {
                handler.handle(new DefaultAsyncResult<String>(event.cause()));
            }
        }
    });
}

From source file:org.entcore.feeder.csv.CsvImportsLauncher.java

License:Open Source License

private void moveCsvFiles(final String structureExternalId, final FileSystem fs, final String dirName,
        final String parentDir, final Handler<Void>[] handlers, final int j) {
    fs.readDir(dirName, ".*.csv", new Handler<AsyncResult<List<String>>>() {
        @Override//  w  w  w.  j ava  2  s. c  om
        public void handle(final AsyncResult<List<String>> l) {
            if (l.succeeded()) {
                final int size = l.result().size();
                if (!(size > 0)) {
                    emptyDirectory(fs, parentDir, handlers, j);
                    return;
                }

                final AtomicInteger validFilesCount = new AtomicInteger(size);
                final AtomicInteger count = new AtomicInteger(size);
                for (final String f : l.result()) {
                    String profile = null;
                    for (String profilePattern : profiles.fieldNames()) {
                        if (f.contains(profilePattern)) {
                            profile = profiles.getString(profilePattern);
                            break;
                        }
                    }
                    if (profile == null) {
                        validFilesCount.decrementAndGet();
                        fs.delete(f, new Handler<AsyncResult<Void>>() {
                            @Override
                            public void handle(AsyncResult<Void> event) {
                                if (count.decrementAndGet() == 0) {
                                    importFiles(validFilesCount, parentDir, structureExternalId, handlers, j,
                                            fs);
                                }
                            }
                        });
                        continue;
                    }

                    fs.move(f, dirName + File.separator + profile + ".csv", new Handler<AsyncResult<Void>>() {
                        @Override
                        public void handle(AsyncResult<Void> event2) {
                            if (event2.succeeded()) {
                                if (count.decrementAndGet() == 0) {
                                    importFiles(validFilesCount, parentDir, structureExternalId, handlers, j,
                                            fs);
                                }
                            } else {
                                fs.deleteRecursive(parentDir, true, null);
                                log.error("Error mv csv file : " + f, l.cause());
                                handlers[j + 1].handle(null);
                            }
                        }
                    });
                }
            } else {
                fs.deleteRecursive(parentDir, true, null);
                log.error("Error listing csv in directory : " + dirName, l.cause());
                handlers[j + 1].handle(null);
            }
        }
    });
}