List of usage examples for io.vertx.core.file FileProps isDirectory
boolean isDirectory();
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);/* www . j a v a 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:com.klwork.spring.vertx.render.MyStaticHandlerImpl.java
License:Open Source License
private void sendStatic(RoutingContext context, String path) { String file = null;/* w ww. j a v a 2 s . com*/ if (!includeHidden) { file = getFile(path, context); int idx = file.lastIndexOf('/'); String name = file.substring(idx + 1); if (name.length() > 0 && name.charAt(0) == '.') { context.fail(NOT_FOUND.code()); return; } } // Look in cache CacheEntry entry = null; if (cachingEnabled) { entry = propsCache().get(path); if (entry != null) { HttpServerRequest request = context.request(); if ((filesReadOnly || !entry.isOutOfDate()) && entry.shouldUseCached(request)) { context.response().setStatusCode(NOT_MODIFIED.code()).end(); return; } } } if (file == null) { file = getFile(path, context); } FileProps props; if (filesReadOnly && entry != null) { props = entry.props; sendFile(context, file, props); } else { // Need to read the props from the filesystem String sfile = file; getFileProps(context, file, res -> { if (res.succeeded()) { FileProps fprops = res.result(); if (fprops == null) { // File does not exist context.fail(NOT_FOUND.code()); } else if (fprops.isDirectory()) { sendDirectory(context, path, sfile); } else { propsCache().put(path, new CacheEntry(fprops, System.currentTimeMillis())); sendFile(context, sfile, fprops); } } else { if (res.cause() instanceof NoSuchFileException || (res.cause().getCause() != null && res.cause().getCause() instanceof NoSuchFileException)) { context.fail(NOT_FOUND.code()); } else { context.fail(res.cause()); } } }); } }