use of java.nio.file.InvalidPathException in project knime-core by knime.
the class LocalFileSystemBrowser method createFileFromPath.
/**
* {@inheritDoc}
*/
@Override
protected File createFileFromPath(final String path) {
try {
URL url = FileUtil.toURL(path);
Path localPath = FileUtil.resolveToPath(url);
if (localPath != null) {
return localPath.toFile();
}
} catch (IOException | URISyntaxException | InvalidPathException ex) {
// ignore
}
return null;
}
use of java.nio.file.InvalidPathException in project syncany by syncany.
the class FileVersionComparator method captureFileProperties.
public FileProperties captureFileProperties(File file, FileChecksum knownChecksum, boolean forceChecksum) {
FileProperties fileProperties = new FileProperties();
fileProperties.relativePath = FileUtil.getRelativeDatabasePath(rootFolder, file);
Path filePath = null;
try {
filePath = Paths.get(file.getAbsolutePath());
fileProperties.exists = Files.exists(filePath, LinkOption.NOFOLLOW_LINKS);
} catch (InvalidPathException e) {
// This throws an exception if the filename is invalid,
// e.g. colon in filename on windows "file:name"
logger.log(Level.FINE, "InvalidPath", e);
logger.log(Level.WARNING, "- Path '{0}' is invalid on this file system. It cannot exist. ", file.getAbsolutePath());
fileProperties.exists = false;
return fileProperties;
}
if (!fileProperties.exists) {
return fileProperties;
}
try {
// Read operating system dependent file attributes
BasicFileAttributes fileAttributes = null;
if (EnvironmentUtil.isWindows()) {
DosFileAttributes dosAttrs = Files.readAttributes(filePath, DosFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
fileProperties.dosAttributes = FileUtil.dosAttrsToString(dosAttrs);
fileAttributes = dosAttrs;
} else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
PosixFileAttributes posixAttrs = Files.readAttributes(filePath, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
fileProperties.posixPermissions = PosixFilePermissions.toString(posixAttrs.permissions());
fileAttributes = posixAttrs;
} else {
fileAttributes = Files.readAttributes(filePath, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
}
fileProperties.lastModified = fileAttributes.lastModifiedTime().toMillis();
fileProperties.size = fileAttributes.size();
// Type
if (fileAttributes.isSymbolicLink()) {
fileProperties.type = FileType.SYMLINK;
fileProperties.linkTarget = FileUtil.readSymlinkTarget(file);
} else if (fileAttributes.isDirectory()) {
fileProperties.type = FileType.FOLDER;
fileProperties.linkTarget = null;
} else {
fileProperties.type = FileType.FILE;
fileProperties.linkTarget = null;
}
// Checksum
if (knownChecksum != null) {
fileProperties.checksum = knownChecksum;
} else {
if (fileProperties.type == FileType.FILE && forceChecksum) {
try {
if (fileProperties.size > 0) {
fileProperties.checksum = new FileChecksum(FileUtil.createChecksum(file, checksumAlgorithm));
} else {
fileProperties.checksum = null;
}
} catch (NoSuchAlgorithmException | IOException e) {
logger.log(Level.FINE, "Failed create checksum", e);
logger.log(Level.SEVERE, "SEVERE: Unable to create checksum for file {0}", file);
fileProperties.checksum = null;
}
} else {
fileProperties.checksum = null;
}
}
// Must be last (!), used for vanish-test later
fileProperties.exists = Files.exists(filePath, LinkOption.NOFOLLOW_LINKS);
fileProperties.locked = fileProperties.exists && FileUtil.isFileLocked(file);
return fileProperties;
} catch (IOException e) {
logger.log(Level.FINE, "Failed to read file", e);
logger.log(Level.SEVERE, "SEVERE: Cannot read file {0}. Assuming file is locked.", file);
fileProperties.exists = true;
fileProperties.locked = true;
return fileProperties;
}
}
use of java.nio.file.InvalidPathException in project BachelorPraktikum by lucasbuschlinger.
the class OpenDiabetesPluginManager method getInstance.
/**
* Singleton factory method.
* @return the Singleton OpenDiabetesPluginManager instance
*/
public static OpenDiabetesPluginManager getInstance() {
if (singletonInstance == null) {
// Resolving base directory is needed, as Netbeans does not use project root as working directory...
Path basedir;
try {
basedir = Paths.get(OpenDiabetesPluginManager.class.getResource("").getPath().replace("%20", " "));
} catch (InvalidPathException exception) {
basedir = Paths.get(OpenDiabetesPluginManager.class.getResource("").getPath().replace("%20", " ").substring(1));
}
basedir = basedir.getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent();
singletonInstance = new OpenDiabetesPluginManager(basedir.resolve("export"), basedir.resolve("properties"));
}
return singletonInstance;
}
use of java.nio.file.InvalidPathException in project dbeaver by serge-rider.
the class TextWithOpenFile method getDialogDirectory.
protected String getDialogDirectory() {
final String text = getText();
if (CommonUtils.isEmptyTrimmed(text)) {
return null;
}
try {
final Path path = Paths.get(text);
if (Files.isDirectory(path)) {
return path.toString();
}
final Path parent = path.getParent();
if (parent != null) {
return parent.toString();
}
} catch (InvalidPathException ignored) {
}
return null;
}
use of java.nio.file.InvalidPathException in project dbeaver by dbeaver.
the class TextWithOpenFile method getDialogDirectory.
protected String getDialogDirectory() {
final String text = getText();
if (CommonUtils.isEmptyTrimmed(text)) {
return null;
}
try {
final Path path = Paths.get(text);
if (Files.isDirectory(path)) {
return path.toString();
}
final Path parent = path.getParent();
if (parent != null) {
return parent.toString();
}
} catch (InvalidPathException ignored) {
}
return null;
}
Aggregations