List of usage examples for java.nio.file LinkOption NOFOLLOW_LINKS
LinkOption NOFOLLOW_LINKS
To view the source code for java.nio.file LinkOption NOFOLLOW_LINKS.
Click Source Link
From source file:com.phoenixnap.oss.ramlapisync.plugin.SpringMvcRamlApiSyncMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { long startTime = System.currentTimeMillis(); if (project.getPackaging().equals("pom")) { this.getLog().info("Skipping [pom] project: " + project.getName()); } else if (project.getPackaging().equals("maven-plugin")) { this.getLog().info("Skipping [maven-plugin] project: " + project.getName()); } else if (!Files.isDirectory(Paths.get(project.getBuild().getSourceDirectory()), LinkOption.NOFOLLOW_LINKS)) { this.getLog().info("Skipping project with missing src folder: " + project.getName()); } else {/*from ww w . j av a2 s .c om*/ try { generateRaml(); } catch (IOException e) { ClassLoaderUtils.restoreOriginalClassLoader(); throw new MojoExecutionException(e, "Unexpected exception while executing Raml Sync Plugin.", e.toString()); } } this.getLog().info("Raml Generation Complete in:" + (System.currentTimeMillis() - startTime) + "ms"); }
From source file:org.commonjava.maven.galley.transport.htcli.internal.UploadMetadataGenTransferDecoratorTest.java
private void assertFile(final String filePath, boolean fileExists, final String httpMetaPath, boolean metaExists) throws Exception { final Path artifactPath = Paths.get(tempFolder.getAbsolutePath(), tempRepo, filePath); assertThat(Files.isRegularFile(artifactPath, LinkOption.NOFOLLOW_LINKS), equalTo(fileExists)); final Path metadataPath = Paths.get(tempFolder.getAbsolutePath(), tempRepo, httpMetaPath); assertThat(Files.isRegularFile(metadataPath, LinkOption.NOFOLLOW_LINKS), equalTo(metaExists)); if (metaExists) { String metaContent = FileUtils.readFileToString(metadataPath.toFile()); assertThat(metaContent.contains(FILE_SIZE.toString()), equalTo(true)); assertThat(metaContent.contains(MOCK_TIME), equalTo(true)); }/*from w w w . j a v a 2 s . co m*/ }
From source file:org.reactor.monitoring.util.FileHandler.java
public static Properties loadPropertiesFromFile(final String filePath) throws IOException { // reading property file Path path = Paths.get(filePath); // If it doesn't exist Path parentDir = path.getParent(); if (!Files.exists(parentDir)) { log.info("config directory doesn't exist"); Files.createDirectories(parentDir); }/*w w w . j a v a 2 s . c om*/ if (!Files.exists(path, LinkOption.NOFOLLOW_LINKS)) { log.info("config file doesn't exist"); Files.createFile(path); } Properties properties = new Properties(); byte[] bytes = readAllBytes(path); InputStream myInputStream = new ByteArrayInputStream(bytes); properties.load(myInputStream); return properties; }
From source file:com.nartex.RichFileManager.java
@Override public JSONObject getFolder(HttpServletRequest request) throws JSONException, IOException { JSONObject array = null;/*from w ww .ja va 2s . co m*/ boolean showThumbs = false; String paramshowThumbs = request.getParameter("showThumbs"); if (paramshowThumbs != null) { showThumbs = true; } Path root = documentRoot.resolve(this.get.get("path")); log.debug("path absolute:" + root.toAbsolutePath()); Path docDir = documentRoot.resolve(this.get.get("path")).toRealPath(LinkOption.NOFOLLOW_LINKS); File dir = docDir.toFile(); //new File(documentRoot + this.get.get("path")); File file = null; if (!dir.isDirectory()) { this.error(sprintf(lang("DIRECTORY_NOT_EXIST"), this.get.get("path"))); } else { if (!dir.canRead()) { this.error(sprintf(lang("UNABLE_TO_OPEN_DIRECTORY"), this.get.get("path"))); } else { array = new JSONObject(); String[] files = dir.list(); JSONObject data = null; JSONObject props = null; for (int i = 0; i < files.length; i++) { data = new JSONObject(); props = new JSONObject(); file = docDir.resolve(files[i]).toFile(); //new File(documentRoot + this.get.get("path") + files[i]); if (file.isDirectory() && !contains(config.getProperty("unallowed_dirs"), files[i])) { try { props.put("Date Created", (String) null); props.put("Date Modified", (String) null); props.put("Height", (String) null); props.put("Width", (String) null); props.put("Size", (String) null); data.put("Path", this.get.get("path") + files[i] + "/"); data.put("Filename", files[i]); data.put("File Type", "dir"); data.put("Thumbnail", config.getProperty("icons-path") + config.getProperty("icons-directory")); data.put("Error", ""); data.put("Code", 0); data.put("Properties", props); array.put(this.get.get("path") + files[i] + "/", data); } catch (Exception e) { this.error("JSONObject error"); } } else if (file.canRead() && (!contains(config.getProperty("unallowed_files"), files[i]))) { this.item = new HashMap<String, Object>(); this.item.put("properties", this.properties); this.getFileInfo(this.get.get("path") + files[i], showThumbs); //if (this.params.get("type") == null || (this.params.get("type") != null && (!this.params.get("type").equals("Image") || checkImageType()))) { if (this.params.get("type") == null || (this.params.get("type") != null && ((!this.params.get("type").equals("Image") && !this.params.get("type").equals("Flash")) || checkImageType() || checkFlashType()))) { try { //data.put("Path", this.get.get("path") + files[i]); data.put("Path", this.item.get("path")); data.put("Filename", this.item.get("filename")); data.put("File Type", this.item.get("filetype")); data.put("Properties", this.item.get("properties")); data.put("Error", ""); data.put("Code", 0); log.debug("data now :" + data.toString()); array.put(this.get.get("path") + files[i], data); } catch (Exception e) { this.error("JSONObject error"); } } } else { log.warn("not allowed file or dir:" + files[i]); } } } } log.debug("array size ready:" + ((array != null) ? array.toString() : "")); return array; }
From source file:org.codice.ddf.configuration.migration.ExportMigrationEntryImplTest.java
@Before public void before() throws Exception { final Path dirs = createDirectory(DIRS); createFile(dirs, FILENAME);/*from ww w .j a v a 2s.c om*/ createFile(dirs, FILENAME2); createFile(createDirectory(DIRS3), FILENAME3); pathUtils = new PathUtils(); absoluteFilePath = ddfHome.resolve(UNIX_NAME).toRealPath(LinkOption.NOFOLLOW_LINKS); Mockito.when(context.getPathUtils()).thenReturn(pathUtils); Mockito.when(context.getReport()).thenReturn(report); Mockito.when(context.getId()).thenReturn(MIGRATABLE_ID); entry = new ExportMigrationEntryImpl(context, FILE_PATH); }
From source file:com.drunkendev.io.recurse.tests.RecursionTest.java
/** * Answer provided by Brett Ryan.// ww w . jav a 2 s . co m * * This test uses Java-8's java {@link java.util.stream.Stream Stream API} * by {@link Files#walk}. * * This is the sequential version. * * @see <a href="http://stackoverflow.com/a/24006711/140037">Stack-Overflow answer by Brett Ryan</a> */ // @Test public void testJava8StreamSequential() { System.out.println("\nTEST: Java 8 Stream Sequential"); time(() -> { try { Map<Integer, Long> stats = Files.walk(startPath).sequential().collect( groupingBy(n -> Files.isDirectory(n, LinkOption.NOFOLLOW_LINKS) ? 1 : 2, counting())); System.out.format("Files: %d, dirs: %d. ", stats.get(2), stats.get(1)); } catch (IOException ex) { fail(ex.getMessage()); } }); }
From source file:org.codice.ddf.configuration.migration.PathUtils.java
/** * Creates a new path utility./*from w ww.j a va2 s . c om*/ * * @throws IOError if unable to determine ${ddf.home} */ public PathUtils() { try { this.ddfHome = Paths.get(System.getProperty("ddf.home")).toRealPath(LinkOption.NOFOLLOW_LINKS); } catch (IOException e) { throw new IOError(e); } }
From source file:com.twosigma.beaker.core.rest.FileIORest.java
@GET @Path("getPosixFileOwnerAndPermissions") @Produces(MediaType.APPLICATION_JSON)//from w w w .j a v a 2 s .c om public Response getPosixFileOwnerAndPermissions(@QueryParam("path") String pathString) throws IOException { pathString = removePrefix(pathString); java.nio.file.Path path = Paths.get(pathString); if (Files.exists(path)) { Map<String, Object> response = new HashMap<>(); response.put("permissions", Files.getPosixFilePermissions(path)); response.put("owner", Files.getOwner(path, LinkOption.NOFOLLOW_LINKS).getName()); response.put("group", Files.readAttributes(path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS) .group().getName()); return status(OK).entity(response).build(); } else { return status(BAD_REQUEST).build(); } }
From source file:org.eclipse.tycho.plugins.tar.TarGzArchiver.java
private PosixFileAttributes getAttributes(File source) { PosixFileAttributeView fileAttributeView = Files.getFileAttributeView(source.toPath(), PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); if (fileAttributeView == null) { return null; }//from w w w . java 2 s. co m PosixFileAttributes attrs; try { attrs = fileAttributeView.readAttributes(); } catch (IOException e) { return null; } return attrs; }
From source file:com.att.aro.core.fileio.impl.FileManagerImpl.java
public long getCreatedTime(String filePath) throws IOException { File file = new File(filePath); FileTime fileTime = (FileTime) Files.getAttribute(file.toPath(), "creationTime", LinkOption.NOFOLLOW_LINKS); if (fileTime != null) { return fileTime.to(TimeUnit.SECONDS); }// ww w. jav a2 s .c o m return 0; }