Example usage for io.vertx.core.file FileProps creationTime

List of usage examples for io.vertx.core.file FileProps creationTime

Introduction

In this page you can find the example usage for io.vertx.core.file FileProps creationTime.

Prototype

long creationTime();

Source Link

Document

The date the file was created

Usage

From source file:FileAccess.java

public JsonObject getProjectStructure(String projectId) {
    JsonObject projectStructure = new JsonObject();

    JsonArray rootFolder = new JsonArray();

    JsonArray rootFile = new JsonArray();

    List<String> rootDirectorys = vertx.fileSystem().readDirBlocking("project/" + projectId);

    System.out.println(new JsonArray(rootDirectorys).toString());

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    for (String directory : rootDirectorys) {
        System.out.println(directory + "directory");
        FileProps something = vertx.fileSystem().lpropsBlocking(directory);
        if (something.isDirectory()) {
            JsonObject directoryJSON = new JsonObject();
            String splitDirectory[] = directory.split("\\\\");
            directoryJSON.put("name", splitDirectory[splitDirectory.length - 1]);
            //                tinggal tambahkan encode menggunakan base 64 agar tidak terdeteksi titik.
            String id = splitDirectory[splitDirectory.length - 2];
            String tmpId = new Base32().encodeAsString(splitDirectory[splitDirectory.length - 1].getBytes())
                    .replace("=", "0");
            directoryJSON.put("id", tmpId);
            directoryJSON.put("create_date", dateFormat.format(new Date(something.creationTime())));
            directoryJSON.put("modify_date", dateFormat.format(new Date(something.lastModifiedTime())));
            rootFolder.add(directoryJSON);

            List<String> subDirectorysFiles = vertx.fileSystem().readDirBlocking(directory);
            JsonArray subFiles = new JsonArray();
            for (String subDirectoryFile : subDirectorysFiles) {
                JsonObject fileJSON = new JsonObject();
                String splitFile[] = subDirectoryFile.split("\\\\");
                fileJSON.put("name", splitFile[splitFile.length - 1]);
                fileJSON.put("id", new Base32().encodeAsString(
                        (splitFile[splitFile.length - 2] + "/" + splitFile[splitFile.length - 1]).getBytes())
                        .replace("=", "0"));
                fileJSON.put("create_date", dateFormat.format(new Date(something.creationTime())));
                fileJSON.put("modify_date", dateFormat.format(new Date(something.lastModifiedTime())));

                subFiles.add(fileJSON);//  ww  w.  j a va 2  s  . c o m
            }
            directoryJSON.put("files", subFiles);

        } else {
            JsonObject fileJSON = new JsonObject();
            String splitFile[] = directory.split("\\\\");
            fileJSON.put("name", splitFile[splitFile.length - 1]);
            fileJSON.put("id",
                    new Base32().encodeAsString(splitFile[splitFile.length - 1].getBytes()).replace("=", "0"));
            fileJSON.put("create_date", dateFormat.format(new Date(something.creationTime())));
            fileJSON.put("modify_date", dateFormat.format(new Date(something.lastModifiedTime())));
            rootFile.add(fileJSON);
        }
    }

    projectStructure.put("folders", rootFolder);
    projectStructure.put("files", rootFile);

    System.out.println(projectStructure.toString());
    return projectStructure;
}

From source file:org.entcore.common.storage.impl.FileStorage.java

License:Open Source License

@Override
public void fileStats(String id, Handler<AsyncResult<FileStats>> handler) {
    try {//  w w  w  . ja v  a 2  s  .com
        fs.props(getPath(id), res -> {
            if (res.succeeded()) {
                FileProps props = res.result();
                handler.handle(new DefaultAsyncResult<>(
                        new FileStats(props.creationTime(), props.lastModifiedTime(), props.size())));
            } else {
                handler.handle(new DefaultAsyncResult<>(res.cause()));
                log.error(res.cause().getMessage(), res.cause());
            }
        });
    } catch (FileNotFoundException e) {
        handler.handle(new DefaultAsyncResult<>(e));
        log.warn(e.getMessage(), e);
    }
}