canonical example by Tabnine
public void pathUsage() { Path currentDir = Paths.get("."); // currentDir = "." Path fullPath = currentDir.toAbsolutePath(); // fullPath = "/Users/guest/workspace" Path one = currentDir.resolve("file.txt"); // one = "./file.txt" Path fileName = one.getFileName(); // fileName = "file.txt" }
CannotWriteException( Path file ) { super( format( "Could not write to: %s", file.toAbsolutePath().toString() ) ); } }
private static String unixifyPath(String path) { return Paths.get(path).toAbsolutePath().toString().replace("\\", "/"); }
public DirectoryLock(Path directory) { this.lockFilePath = directory.resolve(LOCK_FILE_NAME).toAbsolutePath(); }
static String resolveLocalRepoPath(String localRepoPath) { // todo decouple home folder resolution // find homedir String home = System.getenv("ZEPPELIN_HOME"); if (home == null) { home = System.getProperty("zeppelin.home"); } if (home == null) { home = ".."; } return Paths.get(home).resolve(localRepoPath).toAbsolutePath().toString(); }
/** * Creates the storage directory path, including any necessary but nonexistent parent directories. * If the directory already exists, do nothing. * * Also, appropriate directory permissions (w/ StickyBit) are set. * * @param path storage directory path to create * @param workerDataFolderPermissions the permissions to set for the worker's data folder * @return true if the directory is created and false if the directory already exists */ public static boolean createStorageDirPath(String path, String workerDataFolderPermissions) throws IOException { if (Files.exists(Paths.get(path))) { return false; } Path storagePath; try { storagePath = Files.createDirectories(Paths.get(path)); } catch (UnsupportedOperationException | SecurityException | IOException e) { throw new IOException("Failed to create folder " + path, e); } String absolutePath = storagePath.toAbsolutePath().toString(); changeLocalFilePermission(absolutePath, workerDataFolderPermissions); setLocalDirStickyBit(absolutePath); return true; }
public void stopFlinkCluster() throws IOException { AutoClosableProcess.runBlocking("Stop Flink Cluster", bin.resolve("stop-cluster.sh").toAbsolutePath().toString()); }
private PersistentAtomicReference(final Path filename, final JavaType javaType, final Supplier<? extends T> initialValue) throws IOException, InterruptedException { try { this.filename = filename.toAbsolutePath(); this.tempfilename = filename.getFileSystem().getPath(this.filename.toString() + ".tmp"); if (Files.exists(filename)) { final byte[] bytes = Files.readAllBytes(filename); if (bytes.length > 0) { value = Json.read(bytes, javaType); } else { value = initialValue.get(); } } else { value = initialValue.get(); } } catch (InterruptedIOException | ClosedByInterruptException e) { throw new InterruptedException(e.getMessage()); } }
DownloadCommandArguments( final ArgumentDelegates.CacheArguments cacheArguments ) { this.cacheArguments = cacheArguments; this.fileUris = Lists.newArrayList(); this.destinationDirectory = Paths.get("").toAbsolutePath().toFile(); }
public static String createTempDir(String name) { Path tmpDir; try { tmpDir = Files.createTempDirectory(name); } catch (IOException e) { throw new RuntimeException("Couldn't create temporary directory!", e); } String tmpPath = tmpDir.toAbsolutePath().toString(); tmpDir.toFile().deleteOnExit(); return tmpPath; }
private Path findSonarHome(ScannerProperties props) { String home = props.property("sonar.userHome"); if (home != null) { return Paths.get(home).toAbsolutePath(); } home = system.envVariable("SONAR_USER_HOME"); if (home != null) { return Paths.get(home).toAbsolutePath(); } home = system.property("user.home"); return Paths.get(home, ".sonar").toAbsolutePath(); }
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"); }
@Nonnull public AnalysisRunner addAuxClasspathEntry(Path path) { Objects.requireNonNull(path); if (!path.toFile().canRead()) { throw new IllegalArgumentException("Cannot read " + path.toAbsolutePath()); } auxClasspathEntries.add(path); return this; }
private JwkKeys loadJwkKeysFromLocation(String uri) { Path path; try { path = Paths.get(uri); } catch (InvalidPathException e) { path = null; } if (path != null && Files.exists(path)) { try { return loadJwkKeys(new String(Files.readAllBytes(path), UTF_8)); } catch (IOException e) { throw new SecurityException("Failed to load public key(s) from path: " + path.toAbsolutePath(), e); } } else { try (InputStream is = locateStream(uri)) { return getPublicKeyFromContent(is); } catch (IOException e) { throw new SecurityException("Failed to load public key(s) from : " + uri, e); } } }
private void processFileError(InputFile inputFile, SensorContext context) { Path ioFile = inputFile.file().toPath(); Path errorFile = ioFile.resolveSibling(ioFile.getFileName() + ERROR_EXTENSION).toAbsolutePath(); if (Files.exists(errorFile) && Files.isRegularFile(errorFile)) { LOG.debug("Processing " + errorFile.toString()); try { List<String> lines = Files.readAllLines(errorFile, context.fileSystem().encoding()); for (String line : lines) { if (StringUtils.isBlank(line) || line.startsWith("#")) { continue; } processLine(line, inputFile, context); } } catch (IOException e) { throw new IllegalStateException(e); } } }
private Path relative(final List<Object[]> paths, final Path path) { for (Object[] meta : paths) { Path root = ((Path) meta[0]).toAbsolutePath(); Path relative = root.relativize(path); if (Files.exists(root.resolve(relative))) { return relative; } } return path; }
FileSystemHttpVfs(Path rootDir) { this.rootDir = requireNonNull(rootDir, "rootDir").toAbsolutePath(); if (!Files.exists(this.rootDir) || !Files.isDirectory(this.rootDir)) { throw new IllegalArgumentException("rootDir: " + rootDir + " (not a directory"); } }
private String buildGemfilePath(final String bundleDirectoryString) throws ProvisionException { final Path bundleDirectory; try { bundleDirectory = Paths.get(bundleDirectoryString); } catch (InvalidPathException ex) { throw new ProvisionException("Bundle directory is invalid: \"" + bundleDirectoryString + "\"", ex); } return bundleDirectory.toAbsolutePath().resolve("Gemfile").toString(); }
/** * @return the path to current folder */ public static String getCurrentPath() { return Paths.get("").toAbsolutePath().toString(); }
/** * Formats the worker data folder. * * @param folder folder path */ private static void formatWorkerDataFolder(String folder) throws IOException { Path path = Paths.get(folder); if (Files.exists(path)) { FileUtils.deletePathRecursively(folder); } Files.createDirectory(path); // For short-circuit read/write to work, others needs to be able to access this directory. // Therefore, default is 777 but if the user specifies the permissions, respect those instead. String permissions = ServerConfiguration.get(PropertyKey.WORKER_DATA_FOLDER_PERMISSIONS); Set<PosixFilePermission> perms = PosixFilePermissions.fromString(permissions); Files.setPosixFilePermissions(path, perms); FileUtils.setLocalDirStickyBit(path.toAbsolutePath().toString()); }