All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.swagger.parser.util.PathUtils Maven / Gradle / Ivy

There is a newer version: 2.0.0-rc1
Show newest version
package io.swagger.parser.util;

import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class PathUtils {

    public static Path getParentDirectoryOfFile(String location) {
        Path file = null;
        try {
            location = location.replaceAll("\\\\","/");
            final String fileScheme = "file:";
            if (location.toLowerCase().startsWith(fileScheme)) {
                file = Paths.get(URI.create(location)).toAbsolutePath();
            } else {
                file = Paths.get(location).toAbsolutePath();
            }
            if (!Files.exists(file)) {
                URL url = PathUtils.class.getClassLoader().getResource(location);
                file = Paths.get((URI.create(url.toExternalForm())));
                return file.getParent();
            }



        } catch (Exception e) {
            e.getMessage();
        }

        return file.toAbsolutePath().getParent();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy