本文整理汇总了Java中com.intellij.openapi.util.io.FileUtil.ensureCanCreateFile方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.ensureCanCreateFile方法的具体用法?Java FileUtil.ensureCanCreateFile怎么用?Java FileUtil.ensureCanCreateFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.util.io.FileUtil
的用法示例。
在下文中一共展示了FileUtil.ensureCanCreateFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createProjectJarSubFile
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@NotNull
protected VirtualFile createProjectJarSubFile(String relativePath, Pair<ByteSequence, String>... contentEntries) throws IOException {
assertTrue("Use 'jar' extension for JAR files: '" + relativePath + "'", FileUtilRt.extensionEquals(relativePath, "jar"));
File f = new File(getProjectPath(), relativePath);
FileUtil.ensureExists(f.getParentFile());
FileUtil.ensureCanCreateFile(f);
final boolean created = f.createNewFile();
if (!created) {
throw new AssertionError("Unable to create the project sub file: " + f.getAbsolutePath());
}
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
JarOutputStream target = new JarOutputStream(new FileOutputStream(f), manifest);
for (Pair<ByteSequence, String> contentEntry : contentEntries) {
addJarEntry(contentEntry.first.getBytes(), contentEntry.second, target);
}
target.close();
final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f);
assertNotNull(virtualFile);
final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(virtualFile);
assertNotNull(jarFile);
return jarFile;
}
示例2: uninstall
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void uninstall(@NotNull List<PyPackage> packages) throws ExecutionException {
final List<String> args = new ArrayList<String>();
try {
args.add(UNINSTALL);
boolean canModify = true;
for (PyPackage pkg : packages) {
if (canModify) {
final String location = pkg.getLocation();
if (location != null) {
canModify = FileUtil.ensureCanCreateFile(new File(location));
}
}
args.add(pkg.getName());
}
getHelperResult(PACKAGING_TOOL, args, !canModify, true, null);
}
catch (PyExecutionException e) {
throw new PyExecutionException(e.getMessage(), "pip", args, e.getStdout(), e.getStderr(), e.getExitCode(), e.getFixes());
}
finally {
clearCaches();
}
}
示例3: createProjectSubFile
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
protected VirtualFile createProjectSubFile(String relativePath) throws IOException {
File f = new File(getProjectPath(), relativePath);
FileUtil.ensureExists(f.getParentFile());
FileUtil.ensureCanCreateFile(f);
final boolean created = f.createNewFile();
if(!created) {
throw new AssertionError("Unable to create the project sub file: " + f.getAbsolutePath());
}
return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f);
}
示例4: saveExtensions
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static void saveExtensions(Map<String, Set<Plugin>> extensions) throws IOException {
File plugins = getExtensionsFile();
if (!plugins.isFile()) {
FileUtil.ensureCanCreateFile(plugins);
}
JDOMUtil.writeDocument(new Document(XmlSerializer.serialize(new KnownExtensions(extensions))), plugins, "\n");
}
示例5: isValidFilename
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static boolean isValidFilename(final String filename) {
if ( filename.contains("/") || filename.contains("\\") || filename.contains(":") ) {
return false;
}
final File tempFile = new File (FileUtil.getTempDirectory() + File.separator + filename);
return FileUtil.ensureCanCreateFile(tempFile);
}
示例6: processLibrariesAndJpsPlugins
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static void processLibrariesAndJpsPlugins(final File jarFile, final File zipFile, final String pluginName,
final Set<Library> libs,
Map<Module, String> jpsModules, final ProgressIndicator progressIndicator) throws IOException {
if (FileUtil.ensureCanCreateFile(zipFile)) {
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
addStructure(pluginName, zos);
addStructure(pluginName + "/" + MIDDLE_LIB_DIR, zos);
final String entryName = pluginName + JAR_EXTENSION;
ZipUtil.addFileToZip(zos, jarFile, getZipPath(pluginName, entryName), new HashSet<String>(),
createFilter(progressIndicator, FileTypeManager.getInstance()));
for (Map.Entry<Module, String> entry : jpsModules.entrySet()) {
File jpsPluginJar = jarModulesOutput(Collections.singleton(entry.getKey()), null, null);
ZipUtil.addFileToZip(zos, jpsPluginJar, getZipPath(pluginName, entry.getValue()), null, null);
}
Set<String> usedJarNames = new HashSet<String>();
usedJarNames.add(entryName);
Set<VirtualFile> jarredVirtualFiles = new HashSet<VirtualFile>();
for (Library library : libs) {
final VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
for (VirtualFile virtualFile : files) {
if (jarredVirtualFiles.add(virtualFile)) {
if (virtualFile.getFileSystem() instanceof JarFileSystem) {
addLibraryJar(virtualFile, zipFile, pluginName, zos, usedJarNames, progressIndicator);
}
else {
makeAndAddLibraryJar(virtualFile, zipFile, pluginName, zos, usedJarNames, progressIndicator, library.getName());
}
}
}
}
}
finally {
if (zos != null) zos.close();
}
}
}
示例7: savePluginsList
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static void savePluginsList(@NotNull Collection<String> ids, boolean append, @NotNull File plugins) throws IOException {
if (!plugins.isFile()) {
FileUtil.ensureCanCreateFile(plugins);
}
writePluginsList(ids, new BufferedWriter(new FileWriter(plugins, append)));
}