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;
}
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");
}
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;
}
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);
}
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;
}
Aggregations