本文整理汇总了Java中com.intellij.openapi.util.io.FileUtil.rename方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.rename方法的具体用法?Java FileUtil.rename怎么用?Java FileUtil.rename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.util.io.FileUtil
的用法示例。
在下文中一共展示了FileUtil.rename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: backup
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private boolean backup(final File file, final Project project, GenerationOptions genOptions, List<File> filesToRefresh) {
if (!genOptions.backupPreviouslyGeneratedFiles || !file.exists()) {
return true;
}
final String path = file.getPath();
final int extensionIndex = path.lastIndexOf(".");
final String extension = path.substring(extensionIndex, path.length());
//noinspection HardCodedStringLiteral
final String backupPath = path.substring(0, extensionIndex) +
"_" +
new Date(file.lastModified()).toString().replaceAll("\\s+", "_").replaceAll(":", "-") +
extension;
final File backupFile = new File(backupPath);
boolean ok;
try {
FileUtil.rename(file, backupFile);
ok = true;
}
catch (IOException e) {
Messages.showErrorDialog(project, CompilerBundle.message("error.ant.files.backup.failed", path),
CompilerBundle.message("generate.ant.build.title"));
ok = false;
}
filesToRefresh.add(backupFile);
return ok;
}
示例2: testFileCaseChange
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testFileCaseChange() throws Exception {
if (SystemInfo.isFileSystemCaseSensitive) {
System.err.println("Ignored: case-insensitive FS required");
return;
}
File topDir = createTestDir(myTempDirectory, "topDir");
File testFile = createTestFile(topDir, "file.txt", "123");
refresh(topDir);
LocalFileSystem.WatchRequest request = watch(topDir);
try {
myAccept = true;
File newFile = new File(testFile.getParent(), StringUtil.capitalize(testFile.getName()));
FileUtil.rename(testFile, newFile);
assertEvent(VFilePropertyChangeEvent.class, newFile.getPath());
}
finally {
unwatch(request);
}
}
示例3: moveToDir
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static List<Pair<File, DownloadableFileDescription>> moveToDir(List<Pair<File, DownloadableFileDescription>> downloadedFiles,
final File targetDir) throws IOException {
FileUtil.createDirectory(targetDir);
List<Pair<File, DownloadableFileDescription>> result = new ArrayList<Pair<File, DownloadableFileDescription>>();
for (Pair<File, DownloadableFileDescription> pair : downloadedFiles) {
final DownloadableFileDescription description = pair.getSecond();
final String fileName = description.generateFileName(new Condition<String>() {
@Override
public boolean value(String s) {
return !new File(targetDir, s).exists();
}
});
final File toFile = new File(targetDir, fileName);
FileUtil.rename(pair.getFirst(), toFile);
result.add(Pair.create(toFile, description));
}
return result;
}
示例4: testApplyingWithCaseChangedNames
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@Test
public void testApplyingWithCaseChangedNames() throws Exception {
FileUtil.rename(new File(myOlderDir, "Readme.txt"), new File(myOlderDir, "README.txt"));
Patch patch = PatchFileCreator.create(myPatchSpec, myFile, TEST_UI);
assertAppliedAndRevertedCorrectly(patch, PatchFileCreator.prepareAndValidate(myFile, myOlderDir, TEST_UI));
}
示例5: setUp
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
myOlderDir = getDataDir();
myNewerDir = getTempFile("newDir");
FileUtil.copyDir(myOlderDir, myNewerDir);
FileUtil.delete(new File(myNewerDir, "bin/idea.bat"));
FileUtil.writeToFile(new File(myNewerDir, "Readme.txt"), "hello".getBytes());
File newFile = new File(myNewerDir, "newDir/newFile.txt");
newFile.getParentFile().mkdirs();
newFile.createNewFile();
FileUtil.writeToFile(newFile, "hello".getBytes());
FileUtil.delete(new File(myOlderDir, "lib/annotations_changed.jar"));
FileUtil.delete(new File(myNewerDir, "lib/annotations.jar"));
FileUtil.rename(new File(myNewerDir, "lib/annotations_changed.jar"),
new File(myNewerDir, "lib/annotations.jar"));
FileUtil.delete(new File(myOlderDir, "lib/bootstrap_deleted.jar"));
FileUtil.delete(new File(myNewerDir, "lib/bootstrap.jar"));
FileUtil.rename(new File(myNewerDir, "lib/bootstrap_deleted.jar"),
new File(myNewerDir, "lib/bootstrap.jar"));
FileUtil.delete(new File(myOlderDir, "lib/boot2_changed_with_unchanged_content.jar"));
FileUtil.delete(new File(myNewerDir, "lib/boot2.jar"));
FileUtil.rename(new File(myNewerDir, "lib/boot2_changed_with_unchanged_content.jar"),
new File(myNewerDir, "lib/boot2.jar"));
}
示例6: testFileCaseChange
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testFileCaseChange() throws Exception {
if (SystemInfo.isFileSystemCaseSensitive) {
System.err.println("Ignored: case-insensitive FS required");
return;
}
File top = createTempDirectory(false);
File file = IoTestUtil.createTestFile(top, "file.txt", "test");
VirtualFile topDir = myFS.refreshAndFindFileByIoFile(top);
assertNotNull(topDir);
VirtualFile sourceFile = myFS.refreshAndFindFileByIoFile(file);
assertNotNull(sourceFile);
String newName = StringUtil.capitalize(file.getName());
FileUtil.rename(file, newName);
topDir.refresh(false, true);
assertFalse(((VirtualDirectoryImpl)topDir).allChildrenLoaded());
assertTrue(sourceFile.isValid());
assertEquals(newName, sourceFile.getName());
topDir.getChildren();
newName = newName.toLowerCase(Locale.ENGLISH);
FileUtil.rename(file, newName);
topDir.refresh(false, true);
assertTrue(((VirtualDirectoryImpl)topDir).allChildrenLoaded());
assertTrue(sourceFile.isValid());
assertEquals(newName, sourceFile.getName());
}
示例7: rollbackChanges
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private void rollbackChanges() throws IOException {
try {
FileUtil.delete(mySourceFile);
}
finally {
try {
FileUtil.rename(myTempFile, mySourceFile);
}
finally {
FileUtil.delete(myTempFile);
}
}
}
示例8: moveAllFiles
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static void moveAllFiles(@NotNull File from, @NotNull File to, @NotNull Collection<File> newFiles) throws IOException {
if (from.isFile()) {
FileUtil.rename(from, to);
newFiles.add(to);
}
else {
final File[] children = from.listFiles();
if (children != null) {
for (File child : children) {
moveAllFiles(child, new File(to, child.getName()), newFiles);
}
}
}
}
示例9: renameLocalFile
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void renameLocalFile(FileObject fileObject, ICvsFileSystem cvsFileSystem, String newFileName) {
final File originalFile = cvsFileSystem.getLocalFileSystem().getFile(fileObject);
final File targetFile = new File(originalFile.getParentFile(), newFileName);
try {
FileUtil.rename(originalFile, targetFile);
}
catch (IOException e) {
//ignore
}
}
示例10: testWhenAuthCredsNoInConfig
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testWhenAuthCredsNoInConfig() throws Exception {
final TestListener listener = new TestListener(mySynchObject);
myAuthenticationManager.addListener(listener);
final SavedOnceListener savedOnceListener = new SavedOnceListener();
myAuthenticationManager.addListener(savedOnceListener);
final File config = new File(myConfiguration.getConfigurationDirectory(), "config");
final String contents = FileUtil.loadFile(config);
final String auth = "[auth]";
final int idx = contents.indexOf(auth);
Assert.assertTrue(idx != -1);
final String newContents = contents.substring(0, idx + auth.length()) + "\nstore-auth-creds=no\n" + contents.substring(idx + auth.length());
final File oldConfig = new File(myConfiguration.getConfigurationDirectory(), "config_old");
FileUtil.rename(config, oldConfig);
try {
config.createNewFile();
FileUtil.appendToFile(config, newContents);
final SVNURL url = SVNURL.parseURIEncoded("http://some.host.com/repo");
final SVNException[] exception = new SVNException[1];
final Boolean[] result = new Boolean[1];
synchronousBackground(() -> {
try {
listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
commonScheme(url, false, null);
Assert.assertEquals(2, listener.getCnt());
Assert.assertEquals(1, myTestInteraction.getNumAuthWarn());
myTestInteraction.reset();
savedOnceListener.assertForAwt();
savedOnceListener.reset();
SvnConfiguration.RUNTIME_AUTH_CACHE.clear();
listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
commonScheme(url, false, null);
Assert.assertEquals(4, listener.getCnt());
Assert.assertEquals(1, myTestInteraction.getNumAuthWarn());
}
catch (SVNException e) {
exception[0] = e;
}
result[0] = true;
});
Assert.assertTrue(result[0]);
Assert.assertEquals(1, myTestInteraction.getNumAuthWarn());
Assert.assertEquals(4, listener.getCnt());
listener.assertForAwt();
savedOnceListener.assertForAwt();
savedOnceListener.assertNotSaved(url, ISVNAuthenticationManager.PASSWORD);
if (exception[0] != null) {
throw exception[0];
}
} finally {
FileUtil.delete(config);
FileUtil.rename(oldConfig, config);
}
}
示例11: testWhenPassSaveNoInServers
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testWhenPassSaveNoInServers() throws Exception {
final TestListener listener = new TestListener(mySynchObject);
myAuthenticationManager.addListener(listener);
final SavedOnceListener savedOnceListener = new SavedOnceListener();
myAuthenticationManager.addListener(savedOnceListener);
final File servers = new File(myConfiguration.getConfigurationDirectory(), "servers");
final File oldServers = new File(myConfiguration.getConfigurationDirectory(), "config_old");
FileUtil.copy(servers, oldServers);
try {
FileUtil.appendToFile(servers, "\nstore-passwords=no\n");
final SVNURL url = SVNURL.parseURIEncoded("http://some.host.com/repo");
final SVNException[] exception = new SVNException[1];
final Boolean[] result = new Boolean[1];
synchronousBackground(new Runnable() {
@Override
public void run() {
try {
listener.addStep(new Trinity<ProviderType, SVNURL, Type>(ProviderType.persistent, url, Type.request));
listener.addStep(new Trinity<ProviderType, SVNURL, Type>(ProviderType.interactive, url, Type.request));
listener.addStep(new Trinity<ProviderType, SVNURL, Type>(ProviderType.persistent, url, Type.without_pasword_save));
commonScheme(url, false, null);
Assert.assertEquals(3, listener.getCnt());
Assert.assertEquals(1, myTestInteraction.getNumPasswordsWarn());
myTestInteraction.reset();
savedOnceListener.assertForAwt();
savedOnceListener.reset();
SvnConfiguration.RUNTIME_AUTH_CACHE.clear();
listener.addStep(new Trinity<ProviderType, SVNURL, Type>(ProviderType.persistent, url, Type.request));
listener.addStep(new Trinity<ProviderType, SVNURL, Type>(ProviderType.interactive, url, Type.request));
listener.addStep(new Trinity<ProviderType, SVNURL, Type>(ProviderType.persistent, url, Type.without_pasword_save));
commonScheme(url, false, null);
Assert.assertEquals(6, listener.getCnt());
Assert.assertEquals(1, myTestInteraction.getNumPasswordsWarn());
}
catch (SVNException e) {
exception[0] = e;
}
result[0] = true;
}
});
Assert.assertTrue(result[0]);
Assert.assertEquals(1, myTestInteraction.getNumPasswordsWarn());
Assert.assertEquals(6, listener.getCnt());
listener.assertForAwt();
savedOnceListener.assertForAwt();
savedOnceListener.assertSaved(url, ISVNAuthenticationManager.PASSWORD);
if (exception[0] != null) {
throw exception[0];
}
} finally {
FileUtil.delete(servers);
FileUtil.rename(oldServers, servers);
}
}
示例12: renameFile
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@Override
public void renameFile(Object requestor, @NotNull final VirtualFile file, @NotNull final String newName) throws IOException {
if (!VirtualFile.isValidName(newName)) {
throw new IOException(VfsBundle.message("file.invalid.name.error", newName));
}
boolean sameName = !isCaseSensitive() && newName.equalsIgnoreCase(file.getName());
if (!file.exists()) {
throw new IOException(VfsBundle.message("vfs.file.not.exist.error", file.getPath()));
}
VirtualFile parent = file.getParent();
if (parent == null) {
throw new IOException(VfsBundle.message("cannot.rename.root.directory", file.getPath()));
}
if (!sameName && parent.findChild(newName) != null) {
throw new IOException(VfsBundle.message("vfs.target.already.exists.error", parent.getPath() + "/" + newName));
}
File ioFile = convertToIOFile(file);
if (!ioFile.exists()) {
throw new FileNotFoundException(VfsBundle.message("file.not.exist.error", ioFile.getPath()));
}
File ioTarget = new File(convertToIOFile(parent), newName);
if (!sameName && ioTarget.exists()) {
throw new IOException(VfsBundle.message("target.already.exists.error", ioTarget.getPath()));
}
if (!auxRename(file, newName)) {
if (!FileUtil.rename(ioFile, newName)) {
throw new IOException(VfsBundle.message("rename.failed.error", ioFile.getPath(), newName));
}
}
auxNotifyCompleted(new ThrowableConsumer<LocalFileOperationsHandler, IOException>() {
@Override
public void consume(LocalFileOperationsHandler handler) throws IOException {
handler.rename(file, newName);
}
});
}
示例13: finished
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@Override
public void finished(@Nullable final FileType fileType) {
final File localIOFile;
synchronized (myLock) {
LOG.debug("Downloading finished, size = " + myLocalFile.length() + ", file type=" + (fileType != null ? fileType.getName() : "null"));
if (fileType != null) {
String fileName = myLocalFile.getName();
int dot = fileName.lastIndexOf('.');
String extension = fileType.getDefaultExtension();
if (dot == -1 || !extension.regionMatches(true, 0, fileName, dot + 1, extension.length())) {
File newFile = FileUtil.findSequentNonexistentFile(myLocalFile.getParentFile(), fileName, extension);
try {
FileUtil.rename(myLocalFile, newFile);
myLocalFile = newFile;
}
catch (IOException e) {
LOG.debug(e);
}
}
}
localIOFile = myLocalFile;
}
VirtualFile localFile = new WriteAction<VirtualFile>() {
@Override
protected void run(@NotNull final Result<VirtualFile> result) {
final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(localIOFile);
if (file != null) {
file.refresh(false, false);
}
result.setResult(file);
}
}.execute().getResultObject();
LOG.assertTrue(localFile != null, "Virtual local file not found for " + localIOFile.getAbsolutePath());
LOG.debug("Virtual local file: " + localFile + ", size = " + localFile.getLength());
synchronized (myLock) {
myLocalVirtualFile = localFile;
myPrevLocalFile = null;
myState = RemoteFileState.DOWNLOADED;
myErrorMessage = null;
}
for (FileDownloadingListener listener : myListeners) {
listener.fileDownloaded(localFile);
}
}
示例14: testSavedAndReadUnix
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testSavedAndReadUnix() throws Exception {
if (SystemInfo.isWindows) return;
final TestListener listener = new TestListener(mySynchObject);
myAuthenticationManager.addListener(listener);
final SavedOnceListener savedOnceListener = new SavedOnceListener();
myAuthenticationManager.addListener(savedOnceListener);
final SVNURL url = SVNURL.parseURIEncoded("http://some.host.com/repo");
final SVNException[] exception = new SVNException[1];
final Boolean[] result = new Boolean[1];
final File servers = new File(myConfiguration.getConfigurationDirectory(), "servers");
final File oldServers = new File(myConfiguration.getConfigurationDirectory(), "config_old");
FileUtil.copy(servers, oldServers);
try {
FileUtil.appendToFile(servers, "\nstore-plaintext-passwords=yes\n");
synchronousBackground(() -> {
try {
listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request));
listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.save));
commonScheme(url, false, null);
Assert.assertEquals(3, listener.getCnt());
//long start = System.currentTimeMillis();
//waitListenerStep(start, listener, 3);
SvnConfiguration.RUNTIME_AUTH_CACHE.clear();
listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request));
commonScheme(url, false, null);
//start = System.currentTimeMillis();
//waitListenerStep(start, listener, 4);
Assert.assertEquals(4, listener.getCnt());
}
catch (SVNException e) {
exception[0] = e;
}
result[0] = true;
});
} finally {
FileUtil.delete(servers);
FileUtil.rename(oldServers, servers);
}
Assert.assertTrue(result[0]);
myTestInteraction.assertNothing();
Assert.assertEquals(4, listener.getCnt());
listener.assertForAwt();
savedOnceListener.assertForAwt();
savedOnceListener.assertSaved(url, ISVNAuthenticationManager.PASSWORD);
if (exception[0] != null) {
throw exception[0];
}
}
示例15: init
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private void init() throws IOException {
myTempFile = FileUtil.createTempFile(TMP_PREFIX, TMP_SUFFIX);
FileUtil.delete(myTempFile);
FileUtil.rename(mySourceFile, myTempFile);
}