long bytes = java.nio.file.Files.copy( new java.io.File("<filepath1>").toPath(), new java.io.File("<filepath2>").toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING, java.nio.file.StandardCopyOption.COPY_ATTRIBUTES, java.nio.file.LinkOption.NOFOLLOW_LINKS);
private void copyCreationMetadataIfExists(File currentDir, File v3Dir) throws IOException { File v2CreationFile = new File(currentDir, V1Constants.SEGMENT_CREATION_META); if (v2CreationFile.exists()) { File v3CreationFile = new File(v3Dir, V1Constants.SEGMENT_CREATION_META); Files.copy(v2CreationFile.toPath(), v3CreationFile.toPath()); } }
@Override public void visit(File f, String relativePath) throws IOException { if (f.isFile()) { File target = new File(dest, relativePath); mkdirsE(target.getParentFile()); Path targetPath = fileToPath(writing(target)); exceptionEncountered = exceptionEncountered || !tryCopyWithAttributes(f, targetPath); if (exceptionEncountered) { Files.copy(fileToPath(f), targetPath, StandardCopyOption.REPLACE_EXISTING); if (!logMessageShown) { LOGGER.log(Level.INFO, "JENKINS-52325: Jenkins failed to retain attributes when copying to {0}, so proceeding without attributes.", dest.getAbsolutePath()); logMessageShown = true; } } count.incrementAndGet(); } } private boolean tryCopyWithAttributes(File f, Path targetPath) {
@Test public void testWatchManager() throws Exception { Assume.assumeTrue(!IS_WINDOWS || Boolean.getBoolean(FORCE_RUN_KEY)); final ConfigurationScheduler scheduler = new ConfigurationScheduler(); scheduler.incrementScheduledItems(); final WatchManager watchManager = new WatchManager(scheduler); watchManager.setIntervalSeconds(1); scheduler.start(); watchManager.start(); try { final File sourceFile = new File(originalFile); Path source = Paths.get(sourceFile.toURI()); try (final FileOutputStream targetStream = new FileOutputStream(testFile)) { Files.copy(source, targetStream); } final File updateFile = new File(newFile); final File targetFile = new File(testFile); final BlockingQueue<File> queue = new LinkedBlockingQueue<>(); watchManager.watchFile(targetFile, new TestWatcher(queue)); Thread.sleep(1000); source = Paths.get(updateFile.toURI()); Files.copy(source, Paths.get(targetFile.toURI()), StandardCopyOption.REPLACE_EXISTING); Thread.sleep(1000); final File f = queue.poll(1, TimeUnit.SECONDS); assertNotNull("File change not detected", f); } finally { watchManager.stop(); scheduler.stop(); } }
@Override public void copyToLocalFile(URI srcUri, File dstFile) throws Exception { if (dstFile.exists()) { if (dstFile.isDirectory()) { FileUtils.deleteDirectory(dstFile); } else { FileUtils.deleteQuietly(dstFile); } } try (InputStream adlStream = _adlStoreClient.getReadStream(srcUri.getPath())) { Path dstFilePath = Paths.get(dstFile.toURI()); /* Copy the source file to the destination directory as a file with the same name as the source, * replace an existing file with the same name in the destination directory, if any. * Set new file permissions on the copied file. */ Files.copy(adlStream, dstFilePath); } catch (Exception ex) { throw ex; } }
static void init() throws Exception { jarDir = TMP.newFolder().toPath(); // properties are set property by surefire plugin final String parameterProgramJarName = System.getProperty("parameterJarName") + ".jar"; final String parameterProgramWithoutManifestJarName = System.getProperty("parameterJarWithoutManifestName") + ".jar"; final Path jarLocation = Paths.get(System.getProperty("targetDir")); jarWithManifest = Files.copy( jarLocation.resolve(parameterProgramJarName), jarDir.resolve("program-with-manifest.jar")); jarWithoutManifest = Files.copy( jarLocation.resolve(parameterProgramWithoutManifestJarName), jarDir.resolve("program-without-manifest.jar")); restfulGateway = new TestingDispatcherGateway.Builder() .setBlobServerPort(BLOB_SERVER_RESOURCE.getBlobServerPort()) .setSubmitFunction(jobGraph -> { LAST_SUBMITTED_JOB_GRAPH_REFERENCE.set(jobGraph); return CompletableFuture.completedFuture(Acknowledge.get()); }) .build(); gatewayRetriever = () -> CompletableFuture.completedFuture(restfulGateway); localAddressFuture = CompletableFuture.completedFuture("shazam://localhost:12345"); timeout = Time.seconds(10); responseHeaders = Collections.emptyMap(); executor = TestingUtils.defaultExecutor(); }
/** * Copy file to working directory. * * @param filePath File path. * @return File name. * @throws IOException If coping failed. */ String copyToWorkDir(String filePath) throws IOException { Path srcFile = Paths.get(filePath); if (Files.exists(srcFile)) { checkDownloadFolder(); Path newDir = Paths.get(downloadFolder); Path fileName = srcFile.getFileName(); Files.copy(srcFile, newDir.resolve(fileName), StandardCopyOption.REPLACE_EXISTING); return fileName.toString(); } return null; }
void copyDiskInitFile(DiskStoreImpl diskStore) throws IOException { File diskInitFile = diskStore.getDiskInitFile().getIFFile(); String subDirName = Integer.toString(diskStore.getInforFileDirIndex()); Path subDir = temporaryFiles.getDirectory().resolve(subDirName); Files.createDirectories(subDir); Files.copy(diskInitFile.toPath(), subDir.resolve(diskInitFile.getName()), StandardCopyOption.COPY_ATTRIBUTES); backupDefinition.addDiskInitFile(diskStore, subDir.resolve(diskInitFile.getName())); }
private static void extract(JarFile jar, JarEntry file) throws IOException { Path workingDirectory = Paths.get("").toAbsolutePath(); File target = new File(workingDirectory.toString() + File.separator + file.getName()); if (target.exists()) return; if (file.isDirectory()) { target.mkdir(); return; } Files.copy(jar.getInputStream(file), target.toPath()); }
@Override public Void invoke(File f, VirtualChannel channel) throws IOException { File targetFile = new File(target.remote); File targetDir = targetFile.getParentFile(); filterNonNull().mkdirs(targetDir); Files.createDirectories(fileToPath(targetDir)); Files.copy(fileToPath(reading(f)), fileToPath(writing(targetFile)), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING); return null; } }
private Optional<File> compressJar(PluginInfo plugin, File jar) { if (!configuration.getBoolean(PROPERTY_PLUGIN_COMPRESSION_ENABLE).orElse(false)) { return Optional.empty(); } Path targetPack200 = getPack200Path(jar.toPath()); Path sourcePack200Path = getPack200Path(plugin.getNonNullJarFile().toPath()); // check if packed file was deployed alongside the jar. If that's the case, use it instead of generating it (SONAR-10395). if (sourcePack200Path.toFile().exists()) { try { LOG.debug("Found pack200: " + sourcePack200Path); Files.copy(sourcePack200Path, targetPack200); } catch (IOException e) { throw new IllegalStateException("Failed to copy pack200 file from " + sourcePack200Path + " to " + targetPack200, e); } } else { pack200(jar.toPath(), targetPack200, plugin.getKey()); } return Optional.of(targetPack200.toFile()); }
+ "deine Boten, Herr, verehren Das sanfte Wandeln deines Tags."; final java.nio.file.Path compressDir = tmp.newFolder("compressDir").toPath(); final java.nio.file.Path extractDir = tmp.newFolder("extractDir").toPath(); final java.nio.file.Path originalDir = Paths.get("rootDir"); final java.nio.file.Path emptySubDir = originalDir.resolve("emptyDir"); final java.nio.file.Path fullSubDir = originalDir.resolve("fullDir"); final java.nio.file.Path file1 = originalDir.resolve("file1"); final java.nio.file.Path file2 = originalDir.resolve("file2"); final java.nio.file.Path file3 = fullSubDir.resolve("file3"); Files.createDirectory(compressDir.resolve(emptySubDir)); Files.createDirectory(compressDir.resolve(fullSubDir)); Files.copy(new ByteArrayInputStream(testFileContent.getBytes(StandardCharsets.UTF_8)), compressDir.resolve(file1)); Files.createFile(compressDir.resolve(file2)); Files.copy(new ByteArrayInputStream(testFileContent.getBytes(StandardCharsets.UTF_8)), compressDir.resolve(file3));