public static void createParentDirectories(Path p) throws IOException { // merge patch from t3stwhat, fix crash on save to windows path like 'C:\\abc.jar' Path parent = p.getParent(); if (parent != null && !Files.exists(parent)) { Files.createDirectories(parent); } }
public static void writePluginServices(Iterable<String> plugins, File root) throws IOException { Path path = root.toPath().resolve(SERVICES_FILE); createDirectories(path.getParent()); try (Writer out = new OutputStreamWriter(new FileOutputStream(path.toFile()), UTF_8)) { for (String plugin : plugins) { out.write(plugin + "\n"); } } }
private Path tempPath() { Path parent = path.getParent(); File file = parent.toFile(); if (!file.exists()) { file.mkdirs(); } return parent.resolve(path.getFileName().toString() + '.' + tempSuffix()); }
@Override public File[] listFiles( File directory, final FilenameFilter filter ) { try ( Stream<Path> listing = Files.list( path( directory ) ) ) { return listing .filter( entry -> filter.accept( entry.getParent().toFile(), entry.getFileName().toString() ) ) .map( Path::toFile ) .toArray( File[]::new ); } catch ( IOException e ) { return null; } }
/** * Creates an empty file and its intermediate directories if necessary. * * @param filePath pathname string of the file to create */ public static void createFile(String filePath) throws IOException { Path storagePath = Paths.get(filePath); Files.createDirectories(storagePath.getParent()); Files.createFile(storagePath); }
outputDir = file.getParent(); if (outputDir == null) { outputDir = Paths.get("."); .forEach(uncheck(entry -> { progress.update(Optional.of(entry.name()), done.getAndIncrement() / (double) total); Path entryFile = outputDir.resolve(entry.name()); Files.createDirectories(entryFile.getParent()); Files.copy(entry.inputStream(), entryFile, REPLACE_EXISTING); String bundleName = outputDir.getFileName().toString(); Path propsFile = outputDir.getParent().resolve(bundleName + ".json"); BundleProps.write(propsFile, bundle);
private String getSparkexJar() { try { Path path = Paths.get(EnableSparkSupportMagicCommand.class.getProtectionDomain().getCodeSource().getLocation().toURI()); return path.getParent().getParent().getParent().resolve("sparkex").resolve("lib").resolve("sparkex.jar").toString(); } catch (Exception e) { throw new RuntimeException(e); } } }
static void createJar(final URI jarURI, final File workDir, final File f) throws Exception { final Map<String, String> env = new HashMap<>(); env.put("create", "true"); final URI uri = URI.create("jar:file://" + jarURI.getRawPath()); try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) { final Path path = zipfs.getPath(workDir.toPath().relativize(f.toPath()).toString()); if (path.getParent() != null) { Files.createDirectories(path.getParent()); } Files.copy(f.toPath(), path, StandardCopyOption.REPLACE_EXISTING ); } }
public String deleteBackup(String aFilename) { log.debug("Delete backup repository: " + aFilename); try { Files.delete(FileSystems.getDefault().getPath(repositoryPath.getParent().toString(), aFilename)); } catch (IOException e) { log.error("Could not delete file: " + aFilename + " message: " + e.getMessage(), e); } return aFilename; }
public void finalizeDependencies() { if (realBuckBinaryPath != null) { Path linkedBinaryPath = rootProject.file(BUCK_BINARY_LOCATION).toPath().resolve(realBuckBinaryPath.getFileName()); // Delete already existing folder FileUtil.deleteQuietly(linkedBinaryPath.getParent()); // Make dirs linkedBinaryPath.getParent().toFile().mkdirs(); FileUtil.symlink(linkedBinaryPath, realBuckBinaryPath); } } }
private void ensureDirectoryExists(Path filePath) { try { Files.createDirectories(filePath.getParent()); } catch (Exception e) { throw new RuntimeException("Cannot create directory for flexibleConfig " + filePath.getFileName() + "!"); } }
public AtomicFileOutputStream(final Path path) throws IOException { final Path parent = path.getParent(); if (parent != null && parent.getNameCount() != 0 && ! Files.exists(parent)) { Files.createDirectories(parent); } current = new OpenState(Files.newOutputStream(path.resolveSibling(path.getFileName() + ".new"), CREATE, TRUNCATE_EXISTING), path); }
public FileWriter(@JsonProperty("typeNames") ImmutableList<String> typeNames, @JsonProperty("booleanAsNumber") boolean booleanAsNumber, @JsonProperty("debug") Boolean debugEnabled, @JsonProperty(PROPERTY_BASEPATH) String filepath, @JsonProperty(PROPERTY_LINE_FORMAT) String lineFormat, @JsonProperty("resultSerializer") ResultSerializer resultSerializer, @JsonProperty("settings") Map<String, Object> settings) throws IOException { super(typeNames, booleanAsNumber, debugEnabled, settings); this.outputFile = new File(filepath); Path outputFilePath = outputFile.toPath(); this.outputTempFile = new File(outputFilePath.getParent() + File.separator + "." + outputFilePath.getFileName()); if (resultSerializer == null) { if (lineFormat == null) { this.resultSerializer= KeyValueResultSerializer.createDefault(typeNames); } else { this.resultSerializer= new KeyValueResultSerializer(lineFormat, typeNames); } } else { if (lineFormat != null) { log.warn("Both lineFormat and resultSerializer are defined, lineFormat will be ignored"); } this.resultSerializer= resultSerializer; } // make sure the permissions allow to manage these files: touch(this.outputFile); touch(this.outputTempFile); }
Path zipFsPath = fileSystem.isDirectory( sourceToCompress ) ? zipFs.getPath( rootPath.relativize( sourcePath ).toString() ) : zipFs.getPath( sourcePath.getFileName().toString() ); if ( zipFsPath.getParent() != null ) Files.createDirectories( zipFsPath.getParent() );
private String getJarDirectoryPath() { URL url = Thread.currentThread().getContextClassLoader().getResource(""); String dirtyPath; if (url != null) { dirtyPath = url.toString(); } else { File file = new File(""); dirtyPath = file.getAbsolutePath(); } String jarPath = dirtyPath.replaceAll("^.*file:/", ""); // removes // file:/ and // everything // before it jarPath = jarPath.replaceAll("jar!.*", "jar"); // removes everything // after .jar, if .jar // exists in dirtyPath jarPath = jarPath.replaceAll("%20", " "); // necessary if path has // spaces within if (!jarPath.endsWith(".jar")) { // this is needed if you plan to run // the app using Spring Tools Suit play // button. jarPath = jarPath.replaceAll("/classes/.*", "/classes/"); } return Paths.get(jarPath).getParent().toString(); // Paths - from java 8 }
protected static String calculateDefaultOutputDirectory(Path currentPath) { Path currentAbsolutePath = currentPath.toAbsolutePath(); Path parent = currentAbsolutePath.getParent(); if (currentAbsolutePath.getRoot().equals(parent)) { return parent.toString(); } else { Path currentNormalizedPath = currentAbsolutePath.normalize(); return "../" + currentNormalizedPath.getFileName().toString(); } }
private File createFile(String uniqueId, String name) throws IOException { Path filePath = Paths.get(path, uniqueId, name); Path directoryPath = filePath.getParent(); if (directoryPath != null) { Files.createDirectories(directoryPath); } return filePath.toFile(); }