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:de.teamgrit.grit.report.PlainGenerator.java
/** * This method creates a plain-text file from a SubmissionObj instance. * // w w w .jav a 2 s . c om * @param submission * A SubmissionObj containing the information that the content * gets generated from. * @param outdir * the output directory * @param courseName * the name of the Course * @param exerciseName * the name of the exercise * @return The Path to the created plain-text file. * @throws IOException * If something goes wrong when writing. */ public static Path generatePlain(final Submission submission, final Path outdir, String courseName, String exerciseName) throws IOException { final File location = outdir.toFile(); File outputFile = new File(location, submission.getStudent().getName() + ".report.txt"); if (Files.exists(outputFile.toPath(), LinkOption.NOFOLLOW_LINKS)) { Files.delete(outputFile.toPath()); } outputFile.createNewFile(); writeHeader(outputFile, submission, courseName, exerciseName); writeOverview(outputFile, submission); writeTestResult(outputFile, submission); // if there are compile errors, put these in the text file instead of // JUnit Test result CheckingResult checkingResult = submission.getCheckingResult(); if (checkingResult.getCompilerOutput().compilerStreamBroken()) { writeCompilerErrors(outputFile, submission); } else { TestOutput testResults = checkingResult.getTestResults(); if ((testResults.getPassedTestCount() < testResults.getTestCount()) && testResults.getDidTest()) { writeFailedTests(outputFile, submission); } } writeCompilerOutput(outputFile, submission); return outputFile.toPath(); }
From source file:com.kamike.misc.FsUtils.java
public static void createDir(String dstPath) { Properties props = System.getProperties(); // String osName = props.getProperty("os.name"); //??? Path newdir = FileSystems.getDefault().getPath(dstPath); boolean pathExists = Files.exists(newdir, new LinkOption[] { LinkOption.NOFOLLOW_LINKS }); if (!pathExists) { Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxrwxrwx"); FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms); try {// ww w .j a v a2 s . c o m if (!osName.contains("Windows")) { Files.createDirectories(newdir, attr); } else { Files.createDirectories(newdir); } } catch (Exception e) { System.err.println(e); } } }
From source file:com.nsn.squirrel.tab.utils.PathUtils.java
/** * @param path//from ww w . ja va 2 s. co m * @return */ public static String getDosAttributesString(Path path) { DosFileAttributeView basicView = Files.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); StringBuilder attrs = new StringBuilder(); try { // + all basic attributes DosFileAttributes dosAttrs = basicView.readAttributes(); attrs.append(dosAttrs.isReadOnly() ? "r" : "-"); //$NON-NLS-1$ //$NON-NLS-2$ attrs.append(dosAttrs.isHidden() ? "h" : "-");//$NON-NLS-1$ //$NON-NLS-2$ attrs.append(dosAttrs.isArchive() ? "a" : "-");//$NON-NLS-1$ //$NON-NLS-2$ attrs.append(dosAttrs.isSystem() ? "s" : "-");//$NON-NLS-1$ //$NON-NLS-2$ } catch (IOException e) { log.warn("unable to read DOS attributes.", e); //$NON-NLS-1$ } return attrs.toString(); }
From source file:org.codice.ddf.configuration.migration.ExportMigrationPropertyReferencedEntryImplTest.java
@Before public void setup() throws Exception { createFile(createDirectory(DIRS), FILENAME); absoluteFilePath = ddfHome.resolve(UNIX_NAME).toRealPath(LinkOption.NOFOLLOW_LINKS); Mockito.when(context.getPathUtils()).thenReturn(new PathUtils()); Mockito.when(context.getReport()).thenReturn(report); Mockito.when(context.getId()).thenReturn(MIGRATABLE_ID); entry = Mockito.mock(ExportMigrationPropertyReferencedEntryImpl.class, Mockito.withSettings() .useConstructor(context, PROPERTY, UNIX_NAME).defaultAnswer(Answers.CALLS_REAL_METHODS)); }
From source file:cane.brothers.e4.commander.utils.PathUtils.java
/** * @param path/* w w w .j ava 2s . c o m*/ * @return */ public static String getDosAttributesString(Path path) { DosFileAttributeView basicView = Files.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); StringBuilder attrs = new StringBuilder(); try { // + all basic attributes DosFileAttributes dosAttrs = basicView.readAttributes(); attrs.append(dosAttrs.isReadOnly() ? "r" : "-"); //$NON-NLS-1$ //$NON-NLS-2$ attrs.append(dosAttrs.isHidden() ? "h" : "-");//$NON-NLS-1$ //$NON-NLS-2$ attrs.append(dosAttrs.isArchive() ? "a" : "-");//$NON-NLS-1$ //$NON-NLS-2$ attrs.append(dosAttrs.isSystem() ? "s" : "-");//$NON-NLS-1$ //$NON-NLS-2$ } catch (IOException e) { log.warn("unable to read DOS attributes.", e); //$NON-NLS-1$ } return attrs.toString(); }
From source file:org.codice.ddf.configuration.migration.ExportMigrationJavaPropertyReferencedEntryImplTest.java
@Before public void setup() throws Exception { final Path path = createFile(createDirectory(DIRS), FILENAME); propertiesPath = createFile(path.getParent(), PROPERTIES_FILENAME); absoluteFilePath = ddfHome.resolve(UNIX_NAME).toRealPath(LinkOption.NOFOLLOW_LINKS); Mockito.when(context.getPathUtils()).thenReturn(new PathUtils()); Mockito.when(context.getReport()).thenReturn(report); Mockito.when(context.getId()).thenReturn(MIGRATABLE_ID); entry = new ExportMigrationJavaPropertyReferencedEntryImpl(context, propertiesPath, PROPERTY, UNIX_NAME); }
From source file:org.codice.ddf.configuration.migration.ExportMigrationSystemPropertyReferencedEntryImplTest.java
@Before public void setup() throws Exception { createFile(createDirectory(DIRS), FILENAME); Mockito.when(context.getPathUtils()).thenReturn(new PathUtils()); Mockito.when(context.getReport()).thenReturn(report); Mockito.when(context.getId()).thenReturn(MIGRATABLE_ID); entry = new ExportMigrationSystemPropertyReferencedEntryImpl(context, PROPERTY, UNIX_NAME); absoluteFilePath = ddfHome.resolve(UNIX_NAME).toRealPath(LinkOption.NOFOLLOW_LINKS); }
From source file:org.codice.ddf.configuration.migration.ImportMigrationSystemPropertyReferencedEntryImpl.java
@Override protected void verifyPropertyAfterCompletion() { final MigrationReport report = getReport(); report.doAfterCompletion(r -> AccessUtils.doPrivileged(() -> { LOGGER.debug("Verifying {}...", toDebugString()); final String val = System.getProperty(getProperty()); if (val == null) { r.record(new MigrationException(Messages.IMPORT_SYSTEM_PROPERTY_NOT_DEFINED_ERROR, getProperty(), getPath()));/* w ww .jav a 2 s . c om*/ } else if (StringUtils.isBlank(val)) { r.record(new MigrationException(Messages.IMPORT_SYSTEM_PROPERTY_IS_EMPTY_ERROR, getProperty(), getPath())); } else { try { if (!getAbsolutePath().toRealPath(LinkOption.NOFOLLOW_LINKS).equals(getContext().getPathUtils() .resolveAgainstDDFHome(val).toRealPath(LinkOption.NOFOLLOW_LINKS))) { r.record(new MigrationException(Messages.IMPORT_SYSTEM_PROPERTY_ERROR, getProperty(), getPath(), "is now set to [" + val + ']')); } } catch (IOException e) { // cannot determine the location of either so it must not exist or be // different anyway r.record(new MigrationException(Messages.IMPORT_SYSTEM_PROPERTY_ERROR, getProperty(), getPath(), String.format("is now set to [%s]; %s", val, e.getMessage()), e)); } } })); }
From source file:org.codice.ddf.configuration.migration.ImportMigrationJavaPropertyReferencedEntryImplTest.java
@Before public void setup() throws Exception { properties = ddfHome.resolve(createFile(PROPERTIES_PATH)).toRealPath(LinkOption.NOFOLLOW_LINKS); FileUtils.writeStringToFile(properties.toFile(), PROPERTY_NAME + '=' + REFERENCED_PATH, Charsets.UTF_8, false);//from w w w . j av a2s . c om path = ddfHome.resolve(createFile(REFERENCED_PATH)).toRealPath(LinkOption.NOFOLLOW_LINKS); report = mock(MigrationReportImpl.class, Mockito.withSettings().useConstructor(MigrationOperation.IMPORT, Optional.empty()) .defaultAnswer(Mockito.CALLS_REAL_METHODS)); when(mockContext.getPathUtils()).thenReturn(new PathUtils()); when(mockContext.getReport()).thenReturn(report); when(mockContext.getOptionalEntry(any(Path.class))).thenReturn(Optional.of(referencedEntry)); entry = new ImportMigrationJavaPropertyReferencedEntryImpl(mockContext, METADATA_MAP); }
From source file:com.ignorelist.kassandra.steam.scraper.FileCache.java
private boolean exists(String key) { return Files.isRegularFile(buildCacheFile(key), LinkOption.NOFOLLOW_LINKS); }