Example usage for java.nio.file Path isAbsolute

List of usage examples for java.nio.file Path isAbsolute

Introduction

In this page you can find the example usage for java.nio.file Path isAbsolute.

Prototype

boolean isAbsolute();

Source Link

Document

Tells whether or not this path is absolute.

Usage

From source file:org.codice.ddf.security.sts.claims.property.AttributeFileClaimsHandler.java

public void init() {
    if (attributeFileLocation != null) {
        Path ddfHomePath = Paths.get(System.getProperty("ddf.home"));
        Path path = Paths.get(attributeFileLocation);
        if (!path.isAbsolute()) {
            path = Paths.get(ddfHomePath.toString(), path.toString());
        }//  w  w  w  .  j av  a 2  s . com
        Set<String> claims = new HashSet<>();
        try (InputStream stream = Files.newInputStream(path)) {
            String jsonString = IOUtils.toString(stream);
            json = MAPPER.parser().parseMap(jsonString);
            Set<Map.Entry<String, Object>> entries = json.entrySet();
            for (Map.Entry<String, Object> entry : entries) {
                Object value = entry.getValue();
                if (value instanceof Map) {
                    Set keySet = ((Map) value).keySet();
                    for (Object key : keySet) {
                        claims.add((String) key);
                    }
                }
            }
            supportedClaimTypes.clear();
            supportedClaimTypes.addAll(claims.stream().map(URI::create).collect(Collectors.toList()));
        } catch (IOException e) {
            LOGGER.error("Unable to read attribute file for system users.", e);
        }
    }
}

From source file:org.sonar.batch.bootstrap.GlobalTempFolderProvider.java

public TempFolder provide(GlobalProperties bootstrapProps) {
    if (tempFolder == null) {

        String workingPathName = StringUtils.defaultIfBlank(
                bootstrapProps.property(CoreProperties.GLOBAL_WORKING_DIRECTORY),
                CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE);
        Path workingPath = Paths.get(workingPathName);

        if (!workingPath.isAbsolute()) {
            Path home = findSonarHome(bootstrapProps);
            workingPath = home.resolve(workingPath).normalize();
        }//from w  w w  .  ja v a2  s  .  co  m

        try {
            cleanTempFolders(workingPath);
        } catch (IOException e) {
            LOG.error(String.format("failed to clean global working directory: %s", workingPath), e);
        }
        Path tempDir = createTempFolder(workingPath);
        tempFolder = new DefaultTempFolder(tempDir.toFile(), true);
    }
    return tempFolder;
}

From source file:org.apache.storm.metric.FileBasedEventLogger.java

@Override
public void prepare(Map stormConf, TopologyContext context) {
    String workersArtifactDir; // workers artifact directory
    String stormId = context.getStormId();
    int port = context.getThisWorkerPort();
    if ((workersArtifactDir = (String) stormConf.get(Config.STORM_WORKERS_ARTIFACTS_DIR)) == null) {
        workersArtifactDir = "workers-artifacts";
    }//www.j  a va 2  s  .co  m
    /*
     * Include the topology name & worker port in the file name so that
     * multiple event loggers can log independently.
     */
    Path path = Paths.get(workersArtifactDir, stormId, Integer.toString(port), "events.log");
    if (!path.isAbsolute()) {
        path = Paths.get(getLogDir(stormConf), workersArtifactDir, stormId, Integer.toString(port),
                "events.log");
    }
    File dir = path.toFile().getParentFile();
    if (!dir.exists()) {
        dir.mkdirs();
    }
    initLogWriter(path);
    setUpFlushTask();
}

From source file:org.darkware.wpman.config.UpdatableCollectionConfig.java

/**
 * Set the directory where the configured components are installed to.
 *
 * @param baseDir The directory as a {@link Path}, or {@code null} if the default path should be used.
 *//*from  w  w w.  ja v  a 2s  . c  om*/
@JsonProperty("dir")
protected final void setBaseDir(final Path baseDir) {
    if (baseDir == null)
        this.baseDir = null;
    else
        this.baseDir = (baseDir.isAbsolute()) ? baseDir : this.getWpConfig().getContentDir().resolve(baseDir);
}

From source file:org.darkware.wpman.config.UpdatableCollectionConfig.java

/**
 * Set the gutter directory for this set of components.
 *
 * @param gutterDir The gutter directory as a {@link Path}.
 * @see #getGutterDir()//  ww w .j a v  a2  s  . c om
 */
@JsonProperty("gutterDir")
public final void setGutterDir(final Path gutterDir) {
    if (gutterDir == null)
        this.gutterDir = null;
    else
        this.gutterDir = (gutterDir.isAbsolute()) ? gutterDir
                : this.getWpConfig().getContentDir().resolve(gutterDir);
}

From source file:org.sakuli.actions.screenbased.ScreenshotActions.java

/**
 * Resolves a given String to absolute Path or if not absolute:
 * a) the current testcase folder//from w  w  w .ja v  a  2s.c  o  m
 * b) the current testsuite folder
 */
public Path resolveTakeScreenshotPath(String filename) {
    Path path = Paths.get(filename);
    if (path.isAbsolute()) {
        return path;
    }
    TestCase currentTestCase = baseActionLoader.getCurrentTestCase();
    Path folderPath = currentTestCase != null ? currentTestCase.getTcFile().getParent() : null;
    if (folderPath == null || !Files.exists(folderPath)) {
        LOGGER.warn("The test case folder could not be found => Fallback: Use test suite folder!");
        folderPath = baseActionLoader.getTestSuite().getTestSuiteFolder();
    }
    return folderPath.resolve(filename);
}

From source file:com.qspin.qtaste.testsuite.impl.TestDataImpl.java

private void loadFile(String key, String filename) throws QTasteDataException {
    Path filePath = Paths.get(filename);
    if (!filePath.isAbsolute()) {
        filePath = Paths.get(this.getTestCaseDirectory() + File.separator + filename);
    }/*from w  w  w .  j av a2  s . c  o m*/

    try {
        byte[] buffer = Files.readAllBytes(filePath);
        logger.debug("Loaded file: " + filePath.toString() + " size:" + buffer.length);
        hashFiles.put(key, buffer);
    } catch (IOException e) {
        throw new QTasteDataException(e.getMessage());
    }
}

From source file:grakn.core.daemon.executor.Storage.java

private Path getStorageLogPathFromGraknProperties() {
    Path logPath = Paths.get(graknProperties.getProperty(ConfigKey.LOG_DIR));
    return logPath.isAbsolute() ? logPath : graknHome.resolve(logPath);
}

From source file:fr.duminy.jbackup.core.archive.CompressorTest.java

@Theory
public void testCompress(Data data, boolean useListener, EntryType entryType) throws Throwable {
    // preparation of archiver & mocks
    boolean relativeEntries = EntryType.RELATIVE.equals(entryType);
    ErrorType errorType = ErrorType.NO_ERROR;
    ArchiveOutputStream mockOutput = mock(ArchiveOutputStream.class);
    ArgumentCaptor<String> pathArgument = ArgumentCaptor.forClass(String.class);
    doAnswer(new Answer() {
        @Override/*from   w w  w  .j  ava2 s  .  c  o m*/
        public Object answer(InvocationOnMock invocation) throws Throwable {
            InputStream input = (InputStream) invocation.getArguments()[1];
            IOUtils.copy(input, new ByteArrayOutputStream());
            return null;
        }
    }).when(mockOutput).addEntry(pathArgument.capture(), any(InputStream.class));

    ArchiveFactory mockFactory = createMockArchiveFactory(mockOutput);
    Path baseDirectory = createBaseDirectory();
    TaskListener listener = useListener ? mock(TaskListener.class) : null;

    final ArchiveParameters archiveParameters = new ArchiveParameters(createArchivePath(), relativeEntries);
    Map<Path, List<Path>> expectedFilesBySource = data.createFiles(baseDirectory, archiveParameters);
    List<Path> expectedFiles = mergeFiles(expectedFilesBySource);
    Map<String, Path> expectedEntryToFile = new HashMap<>();

    try {
        errorType.setUp(expectedFiles);

        // test compression
        compress(mockFactory, archiveParameters, listener, null);

        // assertions
        verify(mockFactory, times(1)).create(any(OutputStream.class));
        verifyNoMoreInteractions(mockFactory);

        for (Map.Entry<Path, List<Path>> sourceEntry : expectedFilesBySource.entrySet()) {
            for (Path file : sourceEntry.getValue()) {
                assertTrue("test self-check:  files must be absolute", file.isAbsolute());
                final String expectedEntry;
                if (relativeEntries) {
                    Path source = sourceEntry.getKey();
                    if (Files.isDirectory(source)) {
                        expectedEntry = source.getParent().relativize(file).toString();
                    } else {
                        expectedEntry = file.getFileName().toString();
                    }
                } else {
                    expectedEntry = file.toString();
                }
                expectedEntryToFile.put(expectedEntry, file);
                verify(mockOutput, times(1)).addEntry(eq(expectedEntry), any(InputStream.class));
            }
        }
        verify(mockOutput, times(1)).close();
        verifyNoMoreInteractions(mockOutput);
    } catch (Throwable t) {
        errorType.verifyExpected(t);
    } finally {
        errorType.tearDown(expectedFiles);
    }

    assertThatNotificationsAreValid(listener, pathArgument.getAllValues(), expectedEntryToFile, errorType);
}

From source file:org.darkware.wpman.config.WordpressConfigData.java

/**
 * Sets the base upload directory used the WordPress media library.
 *
 * @param uploadDir The root directory for all blogs' uploaded files.
 *//*from   w w  w  .  j a v  a2  s.  com*/
@JsonProperty("uploadDir")
public void setUploadDir(final Path uploadDir) {
    this.uploadDir = (uploadDir.isAbsolute()) ? uploadDir : this.getContentDir().resolve("uploads");
}