本文整理了Java中org.apache.commons.io.FileUtils.moveDirectory()
方法的一些代码示例,展示了FileUtils.moveDirectory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.moveDirectory()
方法的具体详情如下:
包路径:org.apache.commons.io.FileUtils
类名称:FileUtils
方法名:moveDirectory
[英]Moves a directory.
When the destination directory is on another file system, do a "copy and delete".
[中]移动目录。
当目标目录位于另一个文件系统上时,请执行“复制并删除”。
代码示例来源:origin: apache/geode
private void moveFileOrDirectory(Path userFile, Path destination) throws IOException {
if (Files.isDirectory(userFile)) {
FileUtils.moveDirectory(userFile.toFile(), destination.toFile());
} else {
Files.move(userFile, destination);
}
}
代码示例来源:origin: commons-io/commons-io
throw new IOException("Destination '" + destDir + "' is not a directory");
moveDirectory(src, new File(destDir, src.getName()));
代码示例来源:origin: jenkinsci/jenkins
@Override
public void movedTo(DirectlyModifiableTopLevelItemGroup destination, AbstractItem newItem, File destDir) throws IOException {
Job newJob = (Job) newItem; // Missing covariant parameters type here.
File oldBuildDir = getBuildDir();
super.movedTo(destination, newItem, destDir);
File newBuildDir = getBuildDir();
if (oldBuildDir.isDirectory()) {
FileUtils.moveDirectory(oldBuildDir, newBuildDir);
}
}
代码示例来源:origin: geoserver/geoserver
/**
* Renames a file.
*
* @param source The file to rename.
* @param dest The file to rename to.
*/
public static void rename(File source, File dest) throws IOException {
// same path? Do nothing
if (source.getCanonicalPath().equalsIgnoreCase(dest.getCanonicalPath())) return;
// windows needs special treatment, we cannot rename onto an existing file
boolean win = System.getProperty("os.name").startsWith("Windows");
if (win && dest.exists()) {
// windows does not do atomic renames, and can not rename a file if the dest file
// exists
if (!dest.delete()) {
throw new IOException("Could not delete: " + dest.getCanonicalPath());
}
}
// make sure the rename actually succeeds
if (!source.renameTo(dest)) {
FileUtils.deleteQuietly(dest);
if (source.isDirectory()) {
FileUtils.moveDirectory(source, dest);
} else {
FileUtils.moveFile(source, dest);
}
}
}
}
代码示例来源:origin: SonarSource/sonarqube
private File unzipFile(File cachedFile) throws IOException {
String filename = cachedFile.getName();
File destDir = new File(cachedFile.getParentFile(), filename + "_unzip");
File lockFile = new File(cachedFile.getParentFile(), filename + "_unzip.lock");
if (!destDir.exists()) {
FileOutputStream out = new FileOutputStream(lockFile);
try {
java.nio.channels.FileLock lock = out.getChannel().lock();
try {
// Recheck in case of concurrent processes
if (!destDir.exists()) {
File tempDir = pluginFiles.createTempDir();
ZipUtils.unzip(cachedFile, tempDir, newLibFilter());
FileUtils.moveDirectory(tempDir, destDir);
}
} finally {
lock.release();
}
} finally {
out.close();
deleteQuietly(lockFile);
}
}
return destDir;
}
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public void onLocationChanged(Item item, String oldFullName, String newFullName) {
final Jenkins jenkins = Jenkins.getInstance();
if (!jenkins.isDefaultBuildDir() && item instanceof Job) {
File newBuildDir = ((Job)item).getBuildDir();
try {
if (!Util.isDescendant(item.getRootDir(), newBuildDir)) {
//OK builds are stored somewhere outside of the item's root, so none of the other move operations has probably moved it.
//So let's try even though we lack some information
String oldBuildsDir = Jenkins.expandVariablesForDirectory(jenkins.getRawBuildsDir(), oldFullName, "<NOPE>");
if (oldBuildsDir.contains("<NOPE>")) {
LOGGER.severe(String.format("Builds directory for job %1$s appears to be outside of item root," +
" but somehow still containing the item root path, which is unknown. Cannot move builds from %2$s to %1$s.", newFullName, oldFullName));
} else {
File oldDir = new File(oldBuildsDir);
if (oldDir.isDirectory()) {
try {
FileUtils.moveDirectory(oldDir, newBuildDir);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, String.format("Failed to move %s to %s", oldBuildsDir, newBuildDir.getAbsolutePath()), e);
}
}
}
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to inspect " + item.getRootDir() + ". Builds might not be moved.", e);
}
}
}
}
代码示例来源:origin: apache/incubator-pinot
public void downloadAndReplaceSegment(@Nonnull String segmentName,
@Nonnull LLCRealtimeSegmentZKMetadata llcSegmentMetadata, @Nonnull IndexLoadingConfig indexLoadingConfig) {
final String uri = llcSegmentMetadata.getDownloadUrl();
File tempSegmentFolder =
new File(_indexDir, "tmp-" + segmentName + "." + String.valueOf(System.currentTimeMillis()));
File tempFile = new File(_indexDir, segmentName + ".tar.gz");
final File segmentFolder = new File(_indexDir, segmentName);
FileUtils.deleteQuietly(segmentFolder);
try {
SegmentFetcherFactory.getInstance().getSegmentFetcherBasedOnURI(uri).fetchSegmentToLocal(uri, tempFile);
_logger.info("Downloaded file from {} to {}; Length of downloaded file: {}", uri, tempFile, tempFile.length());
TarGzCompressionUtils.unTar(tempFile, tempSegmentFolder);
_logger.info("Uncompressed file {} into tmp dir {}", tempFile, tempSegmentFolder);
FileUtils.moveDirectory(tempSegmentFolder.listFiles()[0], segmentFolder);
_logger.info("Replacing LLC Segment {}", segmentName);
replaceLLSegment(segmentName, indexLoadingConfig);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
FileUtils.deleteQuietly(tempFile);
FileUtils.deleteQuietly(tempSegmentFolder);
}
}
代码示例来源:origin: alibaba/jstorm
File destDir = new File(stormRoot);
try {
FileUtils.moveDirectory(srcDir, destDir);
} catch (FileExistsException e) {
FileUtils.copyDirectory(srcDir, destDir);
代码示例来源:origin: apache/incubator-pinot
FileUtils.deleteDirectory(indexDir);
FileUtils.moveDirectory(tempIndexDir, indexDir);
LOGGER.info("Successfully downloaded segment: {} for table: {} to: {}", segmentName, tableName, indexDir);
return indexDir.getAbsolutePath();
代码示例来源:origin: alibaba/jstorm
File destDir = new File(stormRoot);
try {
FileUtils.moveDirectory(srcDir, destDir);
} catch (FileExistsException e) {
FileUtils.copyDirectory(srcDir, destDir);
代码示例来源:origin: commons-io/commons-io
@Test
public void testMoveDirectory_Rename() throws Exception {
final File dir = getTestDirectory();
final File src = new File(dir, "testMoveDirectory1Source");
final File testDir = new File(src, "foo");
final File testFile = new File(testDir, "bar");
testDir.mkdirs();
if (!testFile.getParentFile().exists()) {
throw new IOException("Cannot create file " + testFile
+ " as the parent directory does not exist");
}
final BufferedOutputStream output =
new BufferedOutputStream(new FileOutputStream(testFile));
try {
TestUtils.generateTestData(output, 0);
} finally {
IOUtils.closeQuietly(output);
}
final File destination = new File(dir, "testMoveDirectory1Dest");
FileUtils.deleteDirectory(destination);
// Move the directory
FileUtils.moveDirectory(src, destination);
// Check results
assertTrue("Check Exist", destination.exists());
assertTrue("Original deleted", !src.exists());
final File movedDir = new File(destination, testDir.getName());
final File movedFile = new File(movedDir, testFile.getName());
assertTrue("Check dir moved", movedDir.exists());
assertTrue("Check file moved", movedFile.exists());
}
代码示例来源:origin: syncany/syncany
FileUtils.moveDirectory(conflictingPath.toFile(), conflictedCopyPath.toFile());
代码示例来源:origin: commons-io/commons-io
FileUtils.moveDirectory(src, destination);
代码示例来源:origin: jenkinsci/jenkins
FileUtils.moveDirectory(item.getRootDir(), destDir);
oldParent.remove(item);
I newItem = destination.add(item, name);
代码示例来源:origin: commons-io/commons-io
@Test
public void testMoveDirectory_Errors() throws Exception {
try {
FileUtils.moveDirectory(null, new File("foo"));
fail("Expected NullPointerException when source is null");
} catch (final NullPointerException e) {
FileUtils.moveDirectory(new File("foo"), null);
fail("Expected NullPointerException when destination is null");
} catch (final NullPointerException e) {
FileUtils.moveDirectory(new File("nonexistant"), new File("foo"));
fail("Expected FileNotFoundException for source");
} catch (final FileNotFoundException e) {
FileUtils.moveDirectory(testFile, new File("foo"));
fail("Expected IOException when source is not a directory");
} catch (final IOException e) {
testDestFile.mkdir();
try {
FileUtils.moveDirectory(testSrcFile, testDestFile);
fail("Expected FileExistsException when dest already exists");
} catch (final FileExistsException e) {
代码示例来源:origin: syncany/syncany
public void moveFile(String fileFrom, String fileTo) throws Exception {
File fromLocalFile = getLocalFile(fileFrom);
File toLocalFile = getLocalFile(fileTo);
try {
if (fromLocalFile.isDirectory()) {
FileUtils.moveDirectory(fromLocalFile, toLocalFile);
}
else {
FileUtils.moveFile(fromLocalFile, toLocalFile);
}
}
catch (Exception e) {
throw new Exception("Move failed: " + fileFrom + " --> " + fileTo, e);
}
}
代码示例来源:origin: apache/incubator-pinot
FileUtils.deleteQuietly(destDir);
try {
FileUtils.moveDirectory(tempSegmentFolder.listFiles()[0], destDir);
if (forCommit) {
TarGzCompressionUtils.createTarGzOfDirectory(destDir.getAbsolutePath());
代码示例来源:origin: apache/incubator-pinot
FileUtils.moveDirectory(tempIndexDir, segmentOutputDir);
代码示例来源:origin: alibaba/mdrill
FileUtils.moveDirectory(new File(tmproot), new File(stormroot));
代码示例来源:origin: apache/flink
FileUtils.moveDirectory(jobManagerSavepoint, new File(savepointPath));
} else {
FileUtils.moveFile(jobManagerSavepoint, new File(savepointPath));
内容来源于网络,如有侵权,请联系作者删除!