org.uberfire.java.nio.file.Paths Maven / Gradle / Ivy
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.uberfire.java.nio.file;
import java.net.URI;
import java.net.URISyntaxException;
import org.uberfire.java.nio.file.api.FileSystemProviders;
import static org.kie.soup.commons.validation.Preconditions.checkNotNull;
/**
* Back port of JSR-203 from Java Platform, Standard Edition 7.
*
* @see Original JavaDoc
*/
public final class Paths {
private Paths() {
}
/**
* @throws IllegalArgumentException
* @see JDK JavaDoc
*/
public static Path get(final String first,
final String... more)
throws IllegalArgumentException {
checkNotNull("first",
first);
if (first.trim().length() == 0) {
return FileSystems.getDefault().getPath(first);
}
URI uri = null;
if (more == null || more.length == 0) {
try {
uri = new URI(first);
} catch (URISyntaxException ex) {
try {
uri = URI.create(first);
} catch (IllegalArgumentException e) {
uri = null;
}
}
}
if (uri != null && uri.getScheme() != null) {
return get(uri);
}
return FileSystems.getDefault().getPath(first,
more);
}
/**
* @throws IllegalArgumentException
* @throws FileSystemNotFoundException
* @throws SecurityException
* @see JDK JavaDoc
*/
public static Path get(final URI uri)
throws IllegalArgumentException, FileSystemNotFoundException, SecurityException {
checkNotNull("uri",
uri);
return FileSystemProviders.resolveProvider(uri).getPath(uri);
}
}