Search in sources :

Example 71 with InvalidPathException

use of java.nio.file.InvalidPathException in project certmgr by hdecarne.

the class CertReaders method readURL.

/**
 * Read all available certificate objects from an {@link URL}.
 * <p>
 * All registered {@link CertReader}s are considered for reading certificate object until one recognizes the file
 * data.
 *
 * @param url The URL to read from.
 * @param password The callback to use for querying passwords (if needed).
 * @return The read certificate objects, or {@code null} if no certificate data was recognized.
 * @throws IOException if an I/O error occurs during reading/decoding.
 */
@Nullable
public static CertObjectStore readURL(URL url, PasswordCallback password) throws IOException {
    Deque<CertReader> certReaders = new ArrayDeque<>();
    Path file;
    try {
        String urlPath = url.getPath();
        int fileNameIndex = urlPath.lastIndexOf('/');
        String fileName = (fileNameIndex >= 0 ? urlPath.substring(fileNameIndex + 1) : urlPath);
        file = Paths.get(fileName);
    } catch (InvalidPathException e) {
        throw new IOException(e.getLocalizedMessage(), e);
    }
    for (CertReader reader : REGISTERED.providers()) {
        if (matchFileName(reader, file)) {
            certReaders.addFirst(reader);
        } else {
            certReaders.addLast(reader);
        }
    }
    CertObjectStore certObjects = null;
    for (CertReader reader : certReaders) {
        try (IOResource<InputStream> in = new IOResource<>(url.openStream(), file.toString())) {
            certObjects = reader.readBinary(in, password);
        } catch (IOException e) {
            Exceptions.ignore(e);
        }
        if (certObjects != null) {
            break;
        }
    }
    return certObjects;
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) IOException(java.io.IOException) CertObjectStore(de.carne.certmgr.certs.CertObjectStore) CertReader(de.carne.certmgr.certs.spi.CertReader) ArrayDeque(java.util.ArrayDeque) InvalidPathException(java.nio.file.InvalidPathException) Nullable(de.carne.check.Nullable)

Example 72 with InvalidPathException

use of java.nio.file.InvalidPathException in project embulk by embulk.

the class EmbulkRun method buildEmbulkHome.

// TODO: Manage the "home directory" in one place in a configurable way.
// https://github.com/embulk/embulk/issues/910
private Path buildEmbulkHome() {
    final String userHomeProperty = System.getProperty("user.home");
    if (userHomeProperty == null) {
        throw new RuntimeException("User home directory is not set in Java properties.");
    }
    final Path userHome;
    try {
        userHome = Paths.get(userHomeProperty);
    } catch (InvalidPathException ex) {
        throw new RuntimeException("User home directory is invalid: \"" + userHomeProperty + "\"", ex);
    }
    return userHome.toAbsolutePath().resolve(".embulk");
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException)

Example 73 with InvalidPathException

use of java.nio.file.InvalidPathException in project Bytecoder by mirkosertic.

the class ProxyClassesDumper method getInstance.

public static ProxyClassesDumper getInstance(String path) {
    if (null == path) {
        return null;
    }
    try {
        path = path.trim();
        final Path dir = Paths.get(path.length() == 0 ? "." : path);
        AccessController.doPrivileged(new PrivilegedAction<>() {

            @Override
            public Void run() {
                validateDumpDir(dir);
                return null;
            }
        }, null, new FilePermission("<<ALL FILES>>", "read, write"));
        return new ProxyClassesDumper(dir);
    } catch (InvalidPathException ex) {
        PlatformLogger.getLogger(ProxyClassesDumper.class.getName()).warning("Path " + path + " is not valid - dumping disabled", ex);
    } catch (IllegalArgumentException iae) {
        PlatformLogger.getLogger(ProxyClassesDumper.class.getName()).warning(iae.getMessage() + " - dumping disabled");
    }
    return null;
}
Also used : Path(java.nio.file.Path) FilePermission(java.io.FilePermission) InvalidPathException(java.nio.file.InvalidPathException)

Example 74 with InvalidPathException

use of java.nio.file.InvalidPathException in project java-common-lib by sosy-lab.

the class FileTypeConverter method convert.

@Override
public Object convert(String optionName, String pValue, TypeToken<?> pType, Annotation secondaryOption, Path pSource, LogManager logger) throws InvalidConfigurationException {
    Class<?> type = pType.getRawType();
    checkApplicability(type, secondaryOption, optionName);
    assert secondaryOption != null : "checkApplicability should ensure this";
    Path path;
    try {
        path = Paths.get(pValue);
    } catch (InvalidPathException e) {
        throw new InvalidConfigurationException(String.format("Invalid file name in option %s: %s", optionName, e.getMessage()), e);
    }
    return handleFileOption(optionName, path, ((FileOption) secondaryOption).value(), type, pSource);
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException)

Example 75 with InvalidPathException

use of java.nio.file.InvalidPathException in project ddf by codice.

the class FileSystemTokenStorage method setBaseDirectory.

public void setBaseDirectory(String baseDirectory) throws IOException {
    // Get path to base directory
    String normalized = FilenameUtils.normalize(baseDirectory);
    String path;
    try {
        path = Paths.get(normalized).toFile().getCanonicalPath();
    } catch (InvalidPathException e) {
        path = System.getProperty(KARAF_HOME);
    }
    Path directoryPath = Paths.get(path);
    // Make sure directory exists
    if (!directoryPath.toFile().exists()) {
        directoryPath = Files.createDirectories(directoryPath);
    }
    this.baseDirectory = directoryPath;
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException)

Aggregations

InvalidPathException (java.nio.file.InvalidPathException)111 Path (java.nio.file.Path)58 IOException (java.io.IOException)30 File (java.io.File)17 URL (java.net.URL)15 MalformedURLException (java.net.MalformedURLException)12 Test (org.junit.Test)11 AlluxioURI (alluxio.AlluxioURI)7 ArrayList (java.util.ArrayList)7 Resource (org.springframework.core.io.Resource)7 Nullable (org.springframework.lang.Nullable)7 URI (java.net.URI)6 URISyntaxException (java.net.URISyntaxException)6 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5 BufferedReader (java.io.BufferedReader)5 URIStatus (alluxio.client.file.URIStatus)4 ViewResolve (com.nvlad.yii2support.views.entities.ViewResolve)4 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4