Example usage for java.nio.file Path toAbsolutePath

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

Introduction

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

Prototype

Path toAbsolutePath();

Source Link

Document

Returns a Path object representing the absolute path of this path.

Usage

From source file:org.restcomm.sbc.managers.controller.ManagementProviderFactory.java

public static ManagementProvider getDefaultProvider()
        throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    if (instance != null)
        return instance;

    String providerClass = null;/*from w w  w.  j a v a2  s  .c  om*/
    Path currentRelativePath = Paths.get("");
    String path = currentRelativePath.toAbsolutePath().toString();
    System.out.println("Current relative path is: " + path);
    Configuration configuration = (Configuration) ShiroResources.getInstance().get(Configuration.class);

    if (path.endsWith("testsuite")) {
        providerClass = "org.restcomm.sbc.managers.controller.dummy.embedded.Provider";
    } else if (path.toLowerCase().contains("jboss")) {
        providerClass = "org.restcomm.sbc.managers.controller.wildfly.Provider";
    } else if (path.endsWith("tomcat")) {
        providerClass = "org.restcomm.sbc.managers.controller.tomcat.Provider";
    }

    if (providerClass == null) {
        System.err.println("Please check your configuration!");
        System.exit(0);
    }

    if (LOG.isInfoEnabled()) {
        LOG.info("Factoring ManagerProvider " + providerClass);
    }
    Class<?> factory = Class.forName(providerClass);
    instance = (ManagementProvider) factory.newInstance();
    return instance;

}

From source file:com.datazuul.iiif.presentation.api.ManifestGenerator.java

private static void addPage(String urlPrefix, String imageDirectoryName, List<Canvas> canvases, int pageCounter,
        Path file) throws IOException, URISyntaxException {
    Path fileName = file.getFileName();
    System.out.println(fileName.toAbsolutePath());

    BufferedImage bimg = ImageIO.read(file.toFile());
    int width = bimg.getWidth();
    int height = bimg.getHeight();

    // add a new page
    Canvas canvas1 = new Canvas(urlPrefix + imageDirectoryName + "/canvas/canvas-" + pageCounter,
            "p-" + pageCounter, height, width);
    canvases.add(canvas1);/*from  w  ww . j ava2  s .  c  o m*/

    List<Image> images = new ArrayList<>();
    canvas1.setImages(images);

    Image image1 = new Image();
    image1.setOn(canvas1.getId());
    images.add(image1);

    ImageResource imageResource1 = new ImageResource(
            urlPrefix + imageDirectoryName + "/" + fileName.toString());
    imageResource1.setHeight(height);
    imageResource1.setWidth(width);
    image1.setResource(imageResource1);

    Service service1 = new Service(urlPrefix + imageDirectoryName + "/" + fileName.toString() + "?");
    service1.setContext("http://iiif.io/api/image/2/context.json");
    service1.setProfile("http://iiif.io/api/image/2/level1.json");
    imageResource1.setService(service1);
}

From source file:com.yqboots.fss.util.ZipUtils.java

/**
 * Compresses the specified directory to a zip file
 *
 * @param dir the directory to compress//from  ww w .  j  a  v  a2 s.  co m
 * @return the compressed file
 * @throws IOException
 */
public static Path compress(Path dir) throws IOException {
    Assert.isTrue(Files.exists(dir), "The directory does not exist: " + dir.toAbsolutePath());
    Assert.isTrue(Files.isDirectory(dir), "Should be a directory: " + dir.toAbsolutePath());

    Path result = Paths.get(dir.toAbsolutePath() + FileType.DOT_ZIP);
    try (final ZipOutputStream out = new ZipOutputStream(
            new BufferedOutputStream(new FileOutputStream(result.toFile())))) {
        // out.setMethod(ZipOutputStream.DEFLATED);
        final byte data[] = new byte[BUFFER];
        // get a list of files from current directory
        Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs)
                    throws IOException {
                final File file = path.toFile();

                // compress to relative directory, not absolute
                final String root = StringUtils.substringAfter(file.getParent(), dir.toString());
                try (final BufferedInputStream origin = new BufferedInputStream(new FileInputStream(file),
                        BUFFER)) {
                    final ZipEntry entry = new ZipEntry(root + File.separator + path.getFileName());
                    out.putNextEntry(entry);
                    int count;
                    while ((count = origin.read(data, 0, BUFFER)) != -1) {
                        out.write(data, 0, count);
                    }
                }

                return FileVisitResult.CONTINUE;
            }
        });
    }

    return result;
}

From source file:es.upm.oeg.tools.quality.ldsniffer.cmd.LDSnifferApp.java

public static String eval(List<String> urlList, boolean includeMetrics, int timeout) throws IOException {

    Path tempPath = Files.createTempDirectory("tdb_");
    String tdbDirectory = tempPath.toAbsolutePath().toString();

    evaluationTimeout = timeout;/* w w  w. j  a  va2 s.c  o  m*/
    includeMetricDefinitions = includeMetrics;
    rdfOutput = true;

    Executor executor = new Executor(tdbDirectory, urlList);
    return executor.execute();

}

From source file:org.sonarlint.cli.config.ConfigurationReader.java

private static ProjectConfiguration validate(@Nullable ProjectConfiguration projectConfig,
        Path configFilePath) {
    if (projectConfig == null) {
        throw new IllegalStateException(FAIL_PARSE_JSON + configFilePath.toAbsolutePath());
    }//from   w  w  w  . j a v a  2s .  co m
    if (StringUtils.isEmpty(projectConfig.projectKey())) {
        throw new IllegalStateException(
                "Project binding must have a project key defined. Check the configuration in: "
                        + configFilePath.toAbsolutePath());
    }
    return projectConfig;
}

From source file:org.apache.nifi.toolkit.tls.standalone.TlsToolkitStandaloneCommandLine.java

protected static String calculateDefaultOutputDirectory(Path currentPath) {
    Path currentAbsolutePath = currentPath.toAbsolutePath();
    Path parent = currentAbsolutePath.getParent();
    if (parent == currentAbsolutePath.getRoot()) {
        return parent.toString();
    } else {//from w  ww  .  jav a 2s .  c  om
        Path currentNormalizedPath = currentAbsolutePath.normalize();
        return "../" + currentNormalizedPath.getFileName().toString();
    }
}

From source file:org.sonarlint.cli.config.ConfigurationReader.java

private static GlobalConfiguration validate(@Nullable GlobalConfiguration globalConfig, Path configFilePath) {
    Set<String> serverUrls = new HashSet<>();

    if (globalConfig == null) {
        throw new IllegalStateException(FAIL_PARSE_JSON + configFilePath.toAbsolutePath());
    }/*from   w  w  w.j a  v a2  s. c  o m*/
    if (globalConfig.servers() != null) {
        for (SonarQubeServer s : globalConfig.servers()) {
            if (StringUtils.isEmpty(s.url())) {
                throw new IllegalStateException(
                        "Invalid SonarQube servers configuration: server URL must be defined. Check the configuration in: "
                                + configFilePath);
            }

            if (serverUrls.contains(s.url())) {
                throw new IllegalStateException(
                        "Invalid SonarQube servers configuration: Each server configured must have a unique URL. Check the configuration in: "
                                + configFilePath);
            }

            serverUrls.add(s.url());
        }
    }
    return globalConfig;
}

From source file:com.netflix.genie.agent.cli.UserConsole.java

/**
 * Move the log file from the current position to the given destination.
 * Refuses to move across filesystems. Moving within the same filesystem should not invalidate any open descriptors.
 *
 * @param destinationPath destination path
 * @throws IOException if source and destination are on different filesystem devices, if destination exists, or if
 *                     the move fails.// ww  w .  j  av a2 s.  co  m
 */
public static synchronized void relocateLogFile(final Path destinationPath) throws IOException {

    final Path sourcePath = CURRENT_LOG_FILE_PATH.get();
    final Path destinationAbsolutePath = destinationPath.toAbsolutePath();

    if (!Files.exists(sourcePath)) {
        throw new IOException("Log file does not exists: " + sourcePath.toString());
    } else if (Files.exists(destinationAbsolutePath)) {
        throw new IOException("Destination already exists: " + destinationAbsolutePath.toString());
    } else if (!sourcePath.getFileSystem().provider()
            .equals(destinationAbsolutePath.getFileSystem().provider())) {
        throw new IOException("Source and destination are not in the same filesystem");
    }

    Files.move(sourcePath, destinationAbsolutePath);
    CURRENT_LOG_FILE_PATH.set(destinationAbsolutePath);

    getLogger().info("Agent log file relocated to: " + getLogFilePath());
}

From source file:org.sonarlint.cli.config.ConfigurationReader.java

private static String getContents(Path filePath) {
    try {/*from   ww  w  .  ja  v a  2  s.  c  o m*/
        return Files.toString(filePath.toFile(), Charsets.UTF_8);
    } catch (IOException e) {
        throw new IllegalStateException("Error reading configuration file: " + filePath.toAbsolutePath(), e);
    }
}

From source file:com.seleniumtests.util.helper.AppTestDocumentation.java

private static void parseWebPage(Path path) throws FileNotFoundException {
    javadoc.append(String.format("\nh2. Page: %s\n", path.getFileName().toString()));

    FileInputStream in = new FileInputStream(path.toAbsolutePath().toString());

    // parse the file
    CompilationUnit cu = JavaParser.parse(in);

    // prints the resulting compilation unit to default system output
    cu.accept(new ClassVisitor(), "Pages");
    cu.accept(new WebPageMethodVisitor(), null);
}