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

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

Introduction

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

Prototype

long lastModifiedTime();

Source Link

Document

The date the file was last modified

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);//from  w w w .j  a va 2  s  .co  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:com.klwork.spring.vertx.render.MyStaticHandlerImpl.java

License:Open Source License

/**
 * Create all required header so content can be cache by Caching servers or Browsers
 *
 * @param request base HttpServerRequest
 * @param props   file properties// www  .ja  va  2 s  .c  om
 */
private void writeCacheHeaders(HttpServerRequest request, FileProps props) {

    MultiMap headers = request.response().headers();

    if (cachingEnabled) {
        // We use cache-control and last-modified
        // We *do not use* etags and expires (since they do the same thing - redundant)
        headers.set("cache-control", "public, max-age=" + maxAgeSeconds);
        headers.set("last-modified", dateTimeFormatter.format(props.lastModifiedTime()));
    }

    // date header is mandatory
    headers.set("date", dateTimeFormatter.format(new Date()));
}

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 {//from  w  w  w.j  a  va 2s  . c  o  m
        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);
    }
}