当前位置: 首页>>代码示例>>Java>>正文


Java FileUtil.createIfDoesntExist方法代码示例

本文整理汇总了Java中com.intellij.openapi.util.io.FileUtil.createIfDoesntExist方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.createIfDoesntExist方法的具体用法?Java FileUtil.createIfDoesntExist怎么用?Java FileUtil.createIfDoesntExist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.util.io.FileUtil的用法示例。


在下文中一共展示了FileUtil.createIfDoesntExist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createNotSignApk

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static String createNotSignApk(File apkFile, String tempPath, String apkNameWithoutExtension)
        throws FileNotFoundException {
    String tempApkPath = tempPath + File.separator + apkNameWithoutExtension + "-unsigned.apk";
    File tempApk = new File(tempApkPath);
    FileUtil.createIfDoesntExist(tempApk);

    //delete signature
    boolean success = ZipHelper.update(new FileInputStream(apkFile), new FileOutputStream(tempApk),
            new HashMap<>(0));
    if (!success) {
        String message = "create tempApk failed, please try again";
        NotificationHelper.error(message);
        throw new RuntimeException(message);
    }
    return tempApkPath;
}
 
开发者ID:nukc,项目名称:ApkMultiChannelPlugin,代码行数:17,代码来源:BuildHelper.java

示例2: saveVersion

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void saveVersion() {
  final Boolean differs = myVersionDiffers;
  if (differs == null || differs) {
    try {
      FileUtil.createIfDoesntExist(myVersionFile);
      final DataOutputStream os = new DataOutputStream(new FileOutputStream(myVersionFile));
      try {
        os.writeInt(VERSION);
        myVersionDiffers = Boolean.FALSE;
      }
      finally {
        os.close();
      }
    }
    catch (IOException ignored) {
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:BuildDataManager.java

示例3: copyWithFiltering

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private void copyWithFiltering(File file, File outputFile) throws IOException {
  final String encoding = myEncodingConfig != null? myEncodingConfig.getEncoding(file) : null;
  PrintWriter writer;
  try {
    writer = encoding != null ? new PrintWriter(outputFile, encoding) : new PrintWriter(outputFile);
  }
  catch (FileNotFoundException e) {
    FileUtil.createIfDoesntExist(outputFile);
    writer = encoding != null ? new PrintWriter(outputFile, encoding) : new PrintWriter(outputFile);
  }
  try {
    final byte[] bytes = FileUtil.loadFileBytes(file);
    final String text = encoding != null? new String(bytes, encoding) : new String(bytes);
    doFilterText(text, getDelimitersPattern(), getProperties(), null, writer);
  }
  finally {
    writer.close();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:MavenResourceFileProcessor.java

示例4: saveDetectors

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private void saveDetectors() {
  final File file = getDetectorsRegistryFile();
  FileUtil.createIfDoesntExist(file);
  try {
    DataOutputStream output = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
    try {
      output.writeInt(REGISTRY_VERSION);
      output.writeInt(myDetectorsVersion);
      final FrameworkDetector[] detectors = FrameworkDetector.EP_NAME.getExtensions();
      output.writeInt(detectors.length);
      for (FrameworkDetector detector : detectors) {
        output.writeUTF(detector.getDetectorId());
        output.writeInt(myDetectorIds.get(detector.getDetectorId()));
        output.writeInt(detector.getDetectorVersion());
      }
    }
    finally {
      output.close();
    }
  }
  catch (IOException e) {
    LOG.info(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:FrameworkDetectorRegistryImpl.java

示例5: testNonExistentDirectoryRoot

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testNonExistentDirectoryRoot() throws IOException {
  String dir = getAbsolutePath("d");
  JpsArtifact a = addArtifact(root().dirCopy(dir));
  buildArtifacts(a);
  assertEmptyOutput(a);
  buildAllAndAssertUpToDate();

  FileUtil.createIfDoesntExist(new File(dir, "a.txt"));
  buildArtifacts(a);
  assertOutput(a, fs().file("a.txt"));
  buildAllAndAssertUpToDate();

  delete(dir);
  buildArtifacts(a);
  assertEmptyOutput(a);
  buildAllAndAssertUpToDate();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:IncrementalArtifactBuildingTest.java

示例6: restoreFileFromCachedContent

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static boolean restoreFileFromCachedContent(final VirtualFile parent,
                                                   final String name,
                                                   final String revision,
                                                   boolean makeReadOnly) {
  try {
    final File cachedContentFile = getCachedContentFile(parent, name, revision);
    if (cachedContentFile == null) return false;
    final byte[] content = FileUtil.loadFileBytes(cachedContentFile);
    final File file = new File(parent.getPath(), name);
    FileUtil.createIfDoesntExist(file);
    if (!file.canWrite() && !file.setWritable(true)) return false;
    FileUtil.writeToFile(file, content);
    if (makeReadOnly && !file.setWritable(false)) return false;
    return file.setLastModified(cachedContentFile.lastModified());
  }
  catch (IOException e) {
    LOG.error(e);
    return false;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:CvsUtil.java

示例7: storeLines

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static void storeLines(List<String> lines, File file) throws IOException {
  String separator = getLineSeparatorFor(file);
  FileUtil.createIfDoesntExist(file);
  if (!file.canWrite()) {
    new FileReadOnlyHandler().setFileReadOnly(file, false);
  }

  Writer writer =
    new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), CvsApplicationLevelConfiguration.getCharset());
  try {
    for (final String line : lines) {
      writer.write(line);
      writer.write(separator);
    }
  }
  finally {
    writer.close();
  }

}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:CvsFileUtil.java

示例8: saveRegisteredIndices

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static void saveRegisteredIndices(@NotNull Collection<ID<?, ?>> ids) {
  final File file = getRegisteredIndicesFile();
  try {
    FileUtil.createIfDoesntExist(file);
    final DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
    try {
      os.writeInt(ids.size());
      for (ID<?, ?> id : ids) {
        IOUtil.writeString(id.toString(), os);
      }
    }
    finally {
      os.close();
    }
  }
  catch (IOException ignored) {
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:FileBasedIndexImpl.java

示例9: writeFile

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static void writeFile(File file, int length, InputStream inputStream) throws IOException {
  if (length == 0) {
    FileUtil.createIfDoesntExist(file);
    return;
  }

  final OutputStream fileOutputStream = new FileOutputStream(file);
  try {
    final byte[] chunk = new byte[BUFFER_SIZE];
    int size = length;
    while (size > 0) {
      final int bytesToRead = Math.min(size, chunk.length);
      final int bytesRead = inputStream.read(chunk, 0, bytesToRead);
      if (bytesRead < 0) {
        break;
      }

      size -= bytesRead;
      fileOutputStream.write(chunk, 0, bytesRead);
    }
  }
  finally {
    try {
      fileOutputStream.close();
    }
    catch (IOException ex) {
      // ignore
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:LocalFileWriter.java

示例10: copyFilesFillingEditorInfos

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@NotNull
protected Map<VirtualFile, EditorInfo> copyFilesFillingEditorInfos(@NotNull VirtualFile fromDir,
                                                                   @NotNull VirtualFile toDir,
                                                                   @NotNull String... relativePaths) throws IOException {
  Map<VirtualFile, EditorInfo> editorInfos = new LinkedHashMap<VirtualFile, EditorInfo>();

  List<OutputStream> streamsToClose = new ArrayList<OutputStream>();

  for (String relativePath : relativePaths) {
    if (relativePath.startsWith("/")) {
      relativePath = relativePath.substring(1);
    }
    final VirtualFile fromFile = fromDir.findFileByRelativePath(relativePath);
    assertNotNull(fromDir.getPath() + "/" + relativePath, fromFile);
    VirtualFile toFile = toDir.findFileByRelativePath(relativePath);
    if (toFile == null) {
      final File file = new File(toDir.getPath(), relativePath);
      FileUtil.createIfDoesntExist(file);
      toFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
      assertNotNull(file.getCanonicalPath(), toFile);
    }
    toFile.putUserData(VfsTestUtil.TEST_DATA_FILE_PATH, FileUtil.toSystemDependentName(fromFile.getPath()));
    editorInfos.put(toFile, copyContent(fromFile, toFile, streamsToClose));
  }

  for(int i = streamsToClose.size() -1; i >= 0 ; --i) {
    streamsToClose.get(i).close();
  }
  return editorInfos;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:CodeInsightTestCase.java

示例11: createProjectFile

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
/**
 * Creates a file using the given path.
 *
 * @param path the path of the file to create. It is relative to {@link #getRootDir()}.
 * @return the created file.
 */
@NotNull
public File createProjectFile(@NotNull String path) {
  File file = new File(myRootDir, path);
  FileUtil.createIfDoesntExist(file);
  return file;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:FileStructure.java

示例12: storePassword

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static void storePassword(String stringConfiguration, String scrambledPassword) throws IOException {
  final File passFile = getPassFile();
  FileUtil.createIfDoesntExist(passFile);
  final List<String> lines = CvsFileUtil.readLinesFrom(passFile);
  lines.add(stringConfiguration + " " + scrambledPassword);
  CvsFileUtil.storeLines(lines, passFile);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:PServerLoginProviderImpl.java

示例13: saveDotProjectFile

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static void saveDotProjectFile(@NotNull Module module, @NotNull String storageRoot) throws IOException {
  try {
    Document doc;
    if (ModuleType.get(module) instanceof JavaModuleType) {
      doc = JDOMUtil.loadDocument(DotProjectFileHelper.class.getResource("template.project.xml"));
    }
    else {
      doc = JDOMUtil.loadDocument(DotProjectFileHelper.class.getResource("template.empty.project.xml"));
    }

    doc.getRootElement().getChild(EclipseXml.NAME_TAG).setText(module.getName());

    final File projectFile = new File(storageRoot, EclipseXml.PROJECT_FILE);
    if (!FileUtil.createIfDoesntExist(projectFile)) {
      return;
    }

    EclipseJDOMUtil.output(doc.getRootElement(), projectFile, module.getProject());
    ApplicationManager.getApplication().runWriteAction(new Runnable() {
      public void run() {
        LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(projectFile.getPath()));
      }
    });
  }
  catch (JDOMException e) {
    LOG.error(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:DotProjectFileHelper.java

示例14: generateDictionary

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private void generateDictionary(final Project project, final Collection<VirtualFile> folderPaths, final String outFile,
                                final ProgressIndicator progressIndicator) {
  final HashSet<String> seenNames = new HashSet<String>();
  // Collect stuff
  for (VirtualFile folder : folderPaths) {
    progressIndicator.setText2("Scanning folder: " + folder.getPath());
    final PsiManager manager = PsiManager.getInstance(project);
    processFolder(seenNames, manager, folder);
  }

  if (seenNames.isEmpty()) {
    LOG.info("  No new words was found.");
    return;
  }

  final StringBuilder builder = new StringBuilder();
  // Sort names
  final ArrayList<String> names = new ArrayList<String>(seenNames);
  Collections.sort(names);
  for (String name : names) {
    if (builder.length() > 0){
      builder.append("\n");
    }
    builder.append(name);
  }
  try {
    final File dictionaryFile = new File(outFile);
    FileUtil.createIfDoesntExist(dictionaryFile);
    final FileWriter writer = new FileWriter(dictionaryFile.getPath());
    try {
      writer.write(builder.toString());
    }
    finally {
      writer.close();
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:41,代码来源:SpellCheckerDictionaryGenerator.java

示例15: readLinesFrom

import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static List<String> readLinesFrom(File file, String cvsRootToSkip) throws IOException {
  FileUtil.createIfDoesntExist(file);
  ArrayList<String> result = new ArrayList<String>();
  BufferedReader reader =
    new BufferedReader(new InputStreamReader(new FileInputStream(file), CvsApplicationLevelConfiguration.getCharset()));
  try {
    String line;
    while ((line = reader.readLine()) != null) {
      if (!line.contains(cvsRootToSkip)) result.add(line);
    }
    return result;
  } finally {
    reader.close();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:CvsFileUtil.java


注:本文中的com.intellij.openapi.util.io.FileUtil.createIfDoesntExist方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。