本文整理汇总了Java中com.intellij.openapi.util.io.FileUtil.writeToFile方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.writeToFile方法的具体用法?Java FileUtil.writeToFile怎么用?Java FileUtil.writeToFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.util.io.FileUtil
的用法示例。
在下文中一共展示了FileUtil.writeToFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: change
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
protected static void change(String filePath, final @Nullable String newContent) {
try {
File file = new File(FileUtil.toSystemDependentName(filePath));
assertTrue("File " + file.getAbsolutePath() + " doesn't exist", file.exists());
if (newContent != null) {
FileUtil.writeToFile(file, newContent);
}
long oldTimestamp = FileSystemUtil.lastModified(file);
long time = System.currentTimeMillis();
setLastModified(file, time);
if (FileSystemUtil.lastModified(file) <= oldTimestamp) {
setLastModified(file, time + 1);
long newTimeStamp = FileSystemUtil.lastModified(file);
if (newTimeStamp <= oldTimestamp) {
//Mac OS and some versions of Linux truncates timestamp to nearest second
setLastModified(file, time + 1000);
newTimeStamp = FileSystemUtil.lastModified(file);
assertTrue("Failed to change timestamp for " + file.getAbsolutePath(), newTimeStamp > oldTimestamp);
}
sleepUntil(newTimeStamp);
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
示例2: testDirectoryMixed
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testDirectoryMixed() throws Exception {
File topDir = createTestDir(myTempDirectory, "top");
File watchedFile1 = createTestFile(topDir, "test.txt");
File sub1Dir = createTestDir(topDir, "sub1");
File unwatchedFile = createTestFile(sub1Dir, "test.txt");
File sub2Dir = createTestDir(topDir, "sub2");
File sub2subDir = createTestDir(sub2Dir, "sub");
File watchedFile2 = createTestFile(sub2subDir, "test.txt");
refresh(topDir);
LocalFileSystem.WatchRequest topRequest = watch(topDir, false);
LocalFileSystem.WatchRequest subRequest = watch(sub2Dir);
try {
myAccept = true;
FileUtil.writeToFile(watchedFile1, "new content");
FileUtil.writeToFile(watchedFile2, "new content");
FileUtil.writeToFile(unwatchedFile, "new content");
assertEvent(VFileContentChangeEvent.class, watchedFile1.getPath(), watchedFile2.getPath());
}
finally {
unwatch(subRequest, topRequest);
delete(topDir);
}
}
示例3: recreateIndex
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static void recreateIndex(final String canonicalIndexName,
final int indexVersion,
final File projectBuildSystemDirectory,
final File indexDir) {
if (indexDir.exists()) {
FileUtil.delete(indexDir);
}
try {
FileUtil.writeToFile(new File(ClassFilesIndexStorageBase.getIndexDir(canonicalIndexName, projectBuildSystemDirectory), VERSION_FILE_NAME),
String.valueOf(indexVersion));
}
catch (final IOException e) {
throw new RuntimeException(e);
}
IndexState.NOT_EXIST.save(indexDir);
}
示例4: testFileLinkSwitch
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testFileLinkSwitch() throws Exception {
File target1 = createTestFile(myTempDir, "target1.txt");
FileUtil.writeToFile(target1, "some text");
File target2 = createTestFile(myTempDir, "target2.txt");
FileUtil.writeToFile(target2, "some quite another text");
File link = createSymLink(target1.getPath(), myTempDir + "/link");
VirtualFile vLink1 = refreshAndFind(link);
assertTrue("link=" + link + ", vLink=" + vLink1,
vLink1 != null && !vLink1.isDirectory() && vLink1.is(VFileProperty.SYMLINK));
assertEquals(FileUtil.loadFile(target1), VfsUtilCore.loadText(vLink1));
assertPathsEqual(target1.getPath(), vLink1.getCanonicalPath());
assertTrue(link.toString(), link.delete());
createSymLink(target2.getPath(), myTempDir + "/" + link.getName());
refresh();
assertTrue(vLink1.isValid());
VirtualFile vLink2 = myFileSystem.findFileByIoFile(link);
assertEquals(vLink1, vLink2);
assertTrue("link=" + link + ", vLink=" + vLink2,
vLink2 != null && !vLink2.isDirectory() && vLink2.is(VFileProperty.SYMLINK));
assertEquals(FileUtil.loadFile(target2), VfsUtilCore.loadText(vLink2));
assertPathsEqual(target2.getPath(), vLink1.getCanonicalPath());
}
示例5: build
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@Override
public void build(CompileContext context) throws ProjectBuildException {
BuildDataPaths dataPaths = context.getProjectDescriptor().dataManager.getDataPaths();
MavenProjectConfiguration projectConfiguration = JpsMavenExtensionService.getInstance().getMavenProjectConfiguration(dataPaths);
if (projectConfiguration == null) return;
final MavenModuleResourceConfiguration moduleResourceConfiguration = projectConfiguration.moduleConfigurations.get(getModuleName(myArtifact.getName()));
if (moduleResourceConfiguration != null && StringUtil.isNotEmpty(moduleResourceConfiguration.manifest)) {
try {
File output = new File(myArtifact.getOutputPath(), JarFile.MANIFEST_NAME);
FileUtil.writeToFile(output, Base64.decode(moduleResourceConfiguration.manifest));
handleSkinnyWars(context, projectConfiguration, moduleResourceConfiguration);
}
// do not fail the whole 'Make' if there is an invalid manifest cached (e.g. non encoded string generated by previous IDEA version)
catch (Exception e) {
LOG.debug(e);
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:MavenManifestGenerationBuildTaskProvider.java
示例6: createTempFile
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private File createTempFile( byte[] bytes )
{
try
{
File file = FileUtil.createTempFile( new File( PathManager.getTempPath() ), "manifoldHotSwap", ".class" );
FileUtil.writeToFile( file, bytes );
return file;
}
catch( IOException e )
{
throw new RuntimeException( e );
}
}
示例7: generateInitScript
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@Nullable
public static File generateInitScript(boolean isBuildSrcProject, @NotNull Set<Class> toolingExtensionClasses) {
InputStream stream = Init.class.getResourceAsStream("/org/jetbrains/plugins/gradle/tooling/internal/init/init.gradle");
try {
if (stream == null) {
LOG.warn("Can't get init script template");
return null;
}
final String toolingExtensionsJarPaths = getToolingExtensionsJarPaths(toolingExtensionClasses);
String s = FileUtil.loadTextAndClose(stream).replaceFirst(Pattern.quote("${EXTENSIONS_JARS_PATH}"), toolingExtensionsJarPaths);
if (isBuildSrcProject) {
String buildSrcDefaultInitScript = getBuildSrcDefaultInitScript();
if (buildSrcDefaultInitScript == null) return null;
s += buildSrcDefaultInitScript;
}
final File tempFile = FileUtil.createTempFile("ijinit", '.' + GradleConstants.EXTENSION, true);
FileUtil.writeToFile(tempFile, s);
return tempFile;
}
catch (Exception e) {
LOG.warn("Can't generate IJ gradle init script", e);
return null;
}
finally {
StreamUtil.closeStream(stream);
}
}
示例8: testExternalReplaceWithTheSameText
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testExternalReplaceWithTheSameText() throws Exception {
final VirtualFile file = createFile();
long modificationStamp = file.getModificationStamp();
DocumentEx document = (DocumentEx)myDocumentManager.getDocument(file);
FileUtil.writeToFile(new File(file.getPath()), "xxx");
file.refresh(false, false);
assertNotNull(file.toString(), document);
assertNotSame(file.getModificationStamp(), modificationStamp);
assertEquals(file.getModificationStamp(), document.getModificationStamp());
}
示例9: testExternalFileCreation
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testExternalFileCreation() throws Exception {
VirtualFile root = ProjectRootManager.getInstance(myProject).getContentRoots()[0];
String newFilePath = root.getPresentableUrl() + File.separatorChar + "New.java";
FileUtil.writeToFile(new File(newFilePath), "class A{ Object o;}".getBytes());
VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(newFilePath.replace(File.separatorChar, '/'));
assertNotNull(file);
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
PsiClass objectClass = myJavaFacade.findClass(CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject()));
assertNotNull(objectClass);
checkUsages(objectClass, new String[]{"New.java"});
}
示例10: testDirectoryRecursive
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testDirectoryRecursive() throws Exception {
File topDir = createTestDir(myTempDirectory, "top");
refresh(topDir);
LocalFileSystem.WatchRequest request = watch(topDir);
try {
myAccept = true;
File subDir = createTestDir(topDir, "sub");
assertEvent(VFileCreateEvent.class, subDir.getPath());
refresh(subDir);
myAccept = true;
File file = createTestFile(subDir, "test.txt");
assertEvent(VFileCreateEvent.class, file.getPath());
myAccept = true;
FileUtil.writeToFile(file, "new content");
assertEvent(VFileContentChangeEvent.class, file.getPath());
myAccept = true;
FileUtil.delete(file);
assertEvent(VFileDeleteEvent.class, file.getPath());
myAccept = true;
FileUtil.writeToFile(file, "re-creation");
assertEvent(VFileCreateEvent.class, file.getPath());
}
finally {
unwatch(request);
delete(topDir);
}
}
示例11: logCantRunException
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
protected void logCantRunException(ExecutionException e) {
try {
final String message = "CantRunException" + e.getMessage() + "\n";
FileUtil.writeToFile(myTempFile, message.getBytes());
}
catch (IOException e1) {
LOG.error(e1);
}
}
示例12: testApplyingWithAbsentOptionalFile
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@Test
public void testApplyingWithAbsentOptionalFile() throws Exception {
FileUtil.writeToFile(new File(myNewerDir, "bin/idea.bat"), "new content".getBytes());
myPatchSpec.setOptionalFiles(Collections.singletonList("bin/idea.bat"));
Patch patch = PatchFileCreator.create(myPatchSpec, myFile, TEST_UI);
new File(myOlderDir, "bin/idea.bat").delete();
PatchFileCreator.PreparationResult preparationResult = PatchFileCreator.prepareAndValidate(myFile, myOlderDir, TEST_UI);
assertTrue(preparationResult.validationResults.isEmpty());
assertAppliedAndRevertedCorrectly(patch, preparationResult);
}
示例13: testUploadModifiedApk
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testUploadModifiedApk() throws Exception {
assertFalse(myService.isInstalled(myDevice1, myFile, myPkgName));
myService.setInstalled(myDevice1, myFile, myPkgName);
assertTrue(myService.isInstalled(myDevice1, myFile, myPkgName));
FileUtil.writeToFile(myFile, "changed!");
assertFalse(myService.isInstalled(myDevice1, myFile, myPkgName));
}
示例14: testNonCanonicallyNamedFileRoot
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testNonCanonicallyNamedFileRoot() throws Exception {
if (SystemInfo.isFileSystemCaseSensitive) {
System.err.println("Ignored: case-insensitive FS required");
return;
}
File file = createTestFile(myTempDirectory, "test.txt");
refresh(file);
String watchRoot = file.getPath().toUpperCase(Locale.US);
LocalFileSystem.WatchRequest request = watch(new File(watchRoot));
try {
myAccept = true;
FileUtil.writeToFile(file, "new content");
assertEvent(VFileContentChangeEvent.class, file.getPath());
myAccept = true;
FileUtil.delete(file);
assertEvent(VFileDeleteEvent.class, file.getPath());
myAccept = true;
FileUtil.writeToFile(file, "re-creation");
assertEvent(VFileCreateEvent.class, file.getPath());
}
finally {
unwatch(request);
delete(file);
}
}
示例15: overwrite
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static void overwrite(@NotNull File file, @NotNull String content) throws IOException {
FileUtil.writeToFile(file, content.getBytes(), false);
}