當前位置: 首頁>>代碼示例>>Java>>正文


Java FileUtil.ensureCanCreateFile方法代碼示例

本文整理匯總了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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:ExternalSystemTestCase.java

示例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();
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:24,代碼來源:PyPackageManagerImpl.java

示例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);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:11,代碼來源:ExternalSystemTestCase.java

示例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");
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:8,代碼來源:PluginsAdvertiser.java

示例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);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:8,代碼來源:FileTemplateConfigurable.java

示例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();
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:39,代碼來源:PrepareToDeployAction.java

示例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)));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:7,代碼來源:PluginManagerCore.java


注:本文中的com.intellij.openapi.util.io.FileUtil.ensureCanCreateFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。