@Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Files.createDirectories(dest.resolve(src.relativize(dir))); return FileVisitResult.CONTINUE; } @Override
/** * Creates an empty directory and its intermediate directories if necessary. * * @param path path of the directory to create */ public static void createDir(String path) throws IOException { Files.createDirectories(Paths.get(path)); }
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"); } } }
/** * 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); }
@Test void shouldRoundTripFilesWithDifferentContent() throws IOException, IncorrectFormat { Path directory = testDirectory.directory( "a-directory" ).toPath(); Files.createDirectories( directory ); Files.write( directory.resolve( "a-file" ), "text".getBytes() ); Files.write( directory.resolve( "another-file" ), "some-different-text".getBytes() ); assertRoundTrips( directory ); }
private File findLocalCacheDir() { try { String defaultCacheDir = m_configUtil.getDefaultLocalCacheDir(); Path path = Paths.get(defaultCacheDir); if (!Files.exists(path)) { Files.createDirectories(path); } if (Files.exists(path) && Files.isWritable(path)) { return new File(defaultCacheDir, CONFIG_DIR); } } catch (Throwable ex) { //ignore } return new File(ClassLoaderUtil.getClassPath(), CONFIG_DIR); }
private void onSyncPackageJson(Config conf, Path workDirectory, Throwing.Consumer<String> action) throws IOException { Path tmp = Paths.get(conf.getString("application.tmpdir"), "package.json"); Files.createDirectories(tmp); String sha1 = Hashing.sha256() .hashBytes(Files.readAllBytes(workDirectory.resolve("package.json"))) .toString(); Path lastSha1 = tmp.resolve(sha1); if (!Files.exists(lastSha1) || !Files.exists(workDirectory.resolve("node_modules"))) { action.accept("install"); Try.of(Files.walk(tmp)) .run(files -> files.filter(f -> !f.equals(tmp)).forEach(throwingConsumer(Files::deleteIfExists))); Files.write(tmp.resolve(lastSha1), Arrays.asList("")); } }
private static void mkdir(File dir) { try { Files.createDirectories(dir.toPath()); } catch (IOException e) { throw new IllegalStateException("Fail to create cache directory: " + dir, e); } }
@Test void shouldMakeFromCanonical() throws IOException, CommandFailed, IncorrectUsage, IncorrectFormat { Path dataDir = testDirectory.directory( "some-other-path" ).toPath(); Path databaseDir = dataDir.resolve( "databases/foo.db" ); Files.createDirectories( databaseDir ); Files.write( configDir.resolve( Config.DEFAULT_CONFIG_FILE_NAME ), singletonList( formatProperty( data_directory, dataDir ) ) ); new LoadCommand( homeDir, configDir, loader ) .execute( ArrayUtil.concat( new String[]{"--database=foo.db", "--from=foo.dump"} ) ); verify( loader ).load( eq( Paths.get( new File( "foo.dump" ).getCanonicalPath() ) ), any(), any() ); }
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 ); } }
private void saveHistory() { Path historyFile = Paths.get(Utils.getConfigDir() + File.separator + "history.json"); try { if (!Files.exists(historyFile)) { Files.createDirectories(historyFile.getParent()); Files.createFile(historyFile); } HISTORY.toFile(historyFile.toString()); Utils.setConfigList("download.history", Collections.emptyList()); } catch (IOException e) { LOGGER.error("Failed to save history to file " + historyFile, e); } }
private void copy(String sourceResourcePath, String destinationFileName) throws IOException { final Path destinationPath = this.pluginBasePath.resolve(destinationFileName); Files.createDirectories(destinationPath.getParent()); Files.copy(EmbulkNew.class.getClassLoader().getResourceAsStream(sourceResourcePath), destinationPath); }
@Test void shouldNotDeleteTheOldDatabaseIfForceArgumentIsNotProvided() throws CommandFailed, IncorrectUsage, IOException, IncorrectFormat { Path databaseDirectory = homeDir.resolve( "data/databases/foo.db" ); Files.createDirectories( databaseDirectory ); doAnswer( ignored -> { assertThat( Files.exists( databaseDirectory ), equalTo( true ) ); return null; } ).when( loader ).load( any(), any(), any() ); execute( "foo.db" ); }
@Override public void write(Path path, List<String> lines) throws IOException { Files.createDirectories(path.getParent()); Files.write(path, lines, StandardCharsets.UTF_8); } }
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); }
private void ensureExistence(Path directory) throws IOException { if (!Files.exists(directory)) { Files.createDirectories(directory); } }
private void ensureBeansXml(Path classesDir) throws IOException { Path beansPath = classesDir.resolve("META-INF/beans.xml"); if (Files.exists(beansPath)) { return; } try (InputStream beanXmlTemplate = HelidonDeployableContainer.class.getResourceAsStream("/templates/beans.xml")) { Path metaInfPath = beansPath.getParent(); if (null != metaInfPath) { Files.createDirectories(metaInfPath); } if (null == beanXmlTemplate) { Files.write(beansPath, new byte[0]); } else { Files.copy(beanXmlTemplate, beansPath); } } }
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(); }
@Test void shouldRoundTripFilesInDirectories() throws IOException, IncorrectFormat { Path directory = testDirectory.directory( "a-directory" ).toPath(); Path subdir = directory.resolve( "a-subdirectory" ); Files.createDirectories( subdir ); Files.write( subdir.resolve( "a-file" ), "text".getBytes() ); assertRoundTrips( directory ); }