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


Java FileUtil类代码示例

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


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

示例1: getVirtualFile

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
private void getVirtualFile(String sourceName, VirtualFile virtualFile[], String compileRoot)
        throws Exception {
    if (!ArrayUtils.isEmpty(virtualFile)) {
        VirtualFile arr$[] = virtualFile;
        int len$ = arr$.length;
        for (int i$ = 0; i$ < len$; i$++) {
            VirtualFile vf = arr$[i$];
            String srcName;
            if (StringUtils.indexOf(vf.toString(), "$") != -1)
                srcName = StringUtils.substring(vf.toString(), StringUtils.lastIndexOf(vf.toString(), "/") + 1, StringUtils.indexOf(vf.toString(), "$"));
            else
                srcName = StringUtils.substring(vf.toString(), StringUtils.lastIndexOf(vf.toString(), "/") + 1, StringUtils.length(vf.toString()) - 6);
            String dstName = StringUtils.substring(sourceName, 0, StringUtils.length(sourceName) - 5);
            if (StringUtils.equals(srcName, dstName)) {
                String outRoot = (new StringBuilder()).append(StringUtils.substring(compileRoot, 0, StringUtils.lastIndexOf(compileRoot, "/"))).append("/out").toString();
                String packagePath = StringUtils.substring(vf.getPath(), StringUtils.length(compileRoot), StringUtils.length(vf.getPath()));
                File s = new File(vf.getPath());
                File t = new File((new StringBuilder()).append(outRoot).append(packagePath).toString());
                FileUtil.copy(s, t);
            }
            if (!ArrayUtils.isEmpty(virtualFile))
                getVirtualFile(sourceName, vf.getChildren(), compileRoot);
        }

    }
}
 
开发者ID:serical,项目名称:patcher,代码行数:27,代码来源:ClassesExportAction.java

示例2: findProject

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
@Nullable
private Project findProject(String file) {
  LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
  ProjectLocator projectLocator = ProjectLocator.getInstance();
  AtomicReference<Project> ret = new AtomicReference<>();
  FileUtil.processFilesRecursively(
      new File(file),
      (f) -> {
        VirtualFile vf = localFileSystem.findFileByIoFile(f);
        if (vf != null) {
          ret.set(projectLocator.guessProjectForFile(vf));
          return false;
        }
        return true;
      });
  return ret.get();
}
 
开发者ID:google,项目名称:ijaas,代码行数:18,代码来源:JavaGetImportCandidatesHandler.java

示例3: parseScripts

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
public static final List<String> parseScripts(File f) {
    List<String> list = new ArrayList<>();
    if(!f.exists()) {
        return list;
    }

    try {
        JsonObject result = new Gson().fromJson(FileUtil.loadFile(f, "UTF-8"), JsonObject.class);
        JsonObject scripts = result.getAsJsonObject("scripts");
        if(scripts == null) {
            return list;// Fix NPE when there is an empty or no scripts package.json file
        }
        for (Map.Entry<String, JsonElement> obj:
                scripts.entrySet()) {
            list.add(obj.getKey());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return list;
}
 
开发者ID:beansoftapp,项目名称:react-native-console,代码行数:23,代码来源:NPMParser.java

示例4: findAntResult

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
private void findAntResult(final Map<Project, AntGenResult> resultMap) {
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        final HybrisProjectSettings hybrisProjectSettings =
            HybrisProjectSettingsComponent.getInstance(project).getState();

        if (!hybrisProjectSettings.isHybrisProject()) {
            continue;
        }

        final File file = new File(project.getBasePath() + "/" + hybrisProjectSettings.getHybrisDirectory() + "/temp/ant.ser");
        if (file.exists()) {
            AntGenResult result = null;
            try (
                final FileInputStream fileIn = new FileInputStream(file);
                final ObjectInputStream in = new ObjectInputStream(fileIn)
            ) {
                result = (AntGenResult) in.readObject();
            } catch (IOException | ClassNotFoundException e) {
                e.printStackTrace();
            }
            FileUtil.delete(file);
            resultMap.put(project, result);
            return;
        }
    }
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:27,代码来源:HybrisAntBuildListener.java

示例5: removeAllFiles

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
@Override
public void removeAllFiles(@NotNull final Collection<File> files) throws IOException {
    Validate.notNull(files);

    if (files.isEmpty()) {
        return;
    }

    final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();

    for (File file : files) {
        final VirtualFile virtualFile = localFileSystem.findFileByIoFile(file);

        if (null != virtualFile) {
            ApplicationManager.getApplication().runWriteAction(new RemoveFileComputable(virtualFile));
        } else {
            FileUtil.delete(file);
        }
    }
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:21,代码来源:DefaultVirtualFileSystemService.java

示例6: transformTestFile

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
private static void transformTestFile(@NotNull Project project, int toSubtaskIndex, VirtualFile taskDir) {

    String subtaskTestFileName = getTestFileName(project, toSubtaskIndex);
    if (subtaskTestFileName == null) {
      return;
    }
    String nameWithoutExtension = FileUtil.getNameWithoutExtension(subtaskTestFileName);
    String extension = FileUtilRt.getExtension(subtaskTestFileName);
    VirtualFile subtaskTestFile = taskDir.findChild(nameWithoutExtension + ".txt");
    if (subtaskTestFile != null) {
      ApplicationManager.getApplication().runWriteAction(() -> {
        try {
          subtaskTestFile.rename(project, nameWithoutExtension + "." + extension);
        }
        catch (IOException e) {
          LOG.error(e);
        }
      });
    }
  }
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:21,代码来源:StudySubtaskUtils.java

示例7: getTaskDescription

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
/**
 * @param wrap if true, text will be wrapped with ancillary information (e.g. to display latex)
 */
public String getTaskDescription(boolean wrap) {
  String fileName = getTaskDescriptionName();
  //TODO: replace this with simple get after implementing migration for taskTexts
  Map.Entry<String, String> entry =
    EntryStream.of(taskTexts).findFirst(e -> FileUtil.getNameWithoutExtension(e.getKey()).equals(fileName)).orElse(null);
  if (entry == null) {
    return null;
  }
  String taskText = entry.getValue();
  if (!wrap) {
    return taskText;
  }
  taskText = StudyUtils.wrapTextToDisplayLatex(StudyUtils.convertToHtml(taskText));
  if (getLesson().getCourse().isAdaptive()) {
    taskText = EduAdaptiveStepicConnector.wrapAdaptiveCourseText(this, taskText);
  }
  return taskText;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:22,代码来源:Task.java

示例8: updateTestHelper

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
private void updateTestHelper() {
  StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> ApplicationManager.getApplication().runWriteAction(() -> {
    final VirtualFile baseDir = myProject.getBaseDir();
    if (baseDir == null) {
      return;
    }
    final VirtualFile testHelper = baseDir.findChild(EduNames.TEST_HELPER);
    if (testHelper != null) {
      StudyUtils.deleteFile(testHelper);
    }
    final FileTemplate template =
      FileTemplateManager.getInstance(myProject).getInternalTemplate(FileUtil.getNameWithoutExtension(EduNames.TEST_HELPER));
    try {
      final PsiDirectory projectDir = PsiManager.getInstance(myProject).findDirectory(baseDir);
      if (projectDir != null) {
        FileTemplateUtil.createFromTemplate(template, EduNames.TEST_HELPER, null, projectDir);
      }
    }
    catch (Exception e) {
      LOG.warn("Failed to create new test helper");
    }
  }));
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:24,代码来源:StudyTaskManager.java

示例9: getSubtaskIndex

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
public static int getSubtaskIndex(@NotNull Project project, @NotNull VirtualFile file) {
  String fileName = file.getName();
  String name = FileUtil.getNameWithoutExtension(fileName);
  if (!isTestsFile(project, file)) {
    return -1;
  }
  if (!name.contains(EduNames.SUBTASK_MARKER)) {
    return 0;
  }
  int markerIndex = name.indexOf(EduNames.SUBTASK_MARKER);
  String index = name.substring(markerIndex + EduNames.SUBTASK_MARKER.length());
  if (index.isEmpty()) {
    return -1;
  }
  try {
    return Integer.valueOf(index);
  }
  catch (NumberFormatException e) {
    return -1;
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:22,代码来源:CCUtils.java

示例10: transformFiles

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
private static void transformFiles(Course course, Project project) {
  List<VirtualFile> files = getAllAnswerTaskFiles(course, project);
  for (VirtualFile answerFile : files) {
    ApplicationManager.getApplication().runWriteAction(() -> {
      String answerName = answerFile.getName();
      String nameWithoutExtension = FileUtil.getNameWithoutExtension(answerName);
      String name = FileUtil.getNameWithoutExtension(nameWithoutExtension) + "." + FileUtilRt.getExtension(answerName);
      VirtualFile parent = answerFile.getParent();
      VirtualFile file = parent.findChild(name);
      try {
        if (file != null) {
          file.delete(CCProjectComponent.class);
        }
        VirtualFile windowsDescrFile = parent.findChild(FileUtil.getNameWithoutExtension(name) + EduNames.WINDOWS_POSTFIX);
        if (windowsDescrFile != null) {
          windowsDescrFile.delete(CCProjectComponent.class);
        }
        answerFile.rename(CCProjectComponent.class, name);
      }
      catch (IOException e) {
        LOG.error(e);
      }
    });
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:26,代码来源:CCProjectComponent.java

示例11: getAllAnswerTaskFiles

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
private static List<VirtualFile> getAllAnswerTaskFiles(@NotNull Course course, @NotNull Project project) {
  List<VirtualFile> result = new ArrayList<>();
  for (Lesson lesson : course.getLessons()) {
    for (Task task : lesson.getTaskList()) {
      for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
        String name = entry.getKey();
        String answerName = FileUtil.getNameWithoutExtension(name) + CCUtils.ANSWER_EXTENSION_DOTTED + FileUtilRt.getExtension(name);
        String taskPath = FileUtil.join(project.getBasePath(), EduNames.LESSON + lesson.getIndex(), EduNames.TASK + task.getIndex());
        VirtualFile taskFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.join(taskPath, answerName));
        if (taskFile == null) {
          taskFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.join(taskPath, EduNames.SRC, answerName));
        }
        if (taskFile != null) {
          result.add(taskFile);
        }
      }
    }
  }
  return result;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:21,代码来源:CCProjectComponent.java

示例12: CreateCourseArchivePanel

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
public CreateCourseArchivePanel(@NotNull final Project project, CreateCourseArchiveDialog dlg, String name) {
  setLayout(new BorderLayout());
  add(myPanel, BorderLayout.CENTER);
  myErrorIcon.setIcon(AllIcons.Actions.Lightning);
  setState(false);
  myDlg = dlg;
  String sanitizedName = FileUtil.sanitizeFileName(name);
  myNameField.setText(sanitizedName.startsWith("_") ? EduNames.COURSE : sanitizedName);
  myLocationField.setText(project.getBasePath());
  FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
  myLocationField.addBrowseFolderListener("Choose Location Folder", null, project, descriptor);
  myLocationField.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      String location = myLocationField.getText();
      File file = new File(location);
      if (!file.exists() || !file.isDirectory()) {
        myDlg.enableOKAction(false);
        setError("Invalid location");
      }
      myDlg.enableOKAction(true);
    }
  });
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:25,代码来源:CreateCourseArchivePanel.java

示例13: doStepOptionsCreationTest

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
private static StepicWrappers.StepOptions doStepOptionsCreationTest(String fileName) throws IOException {
  String responseString =
    FileUtil.loadFile(new File(getTestDataPath(), fileName));
  StepicWrappers.StepSource stepSource =
    EduStepicClient.deserializeStepicResponse(StepicWrappers.StepContainer.class, responseString).steps.get(0);
  StepicWrappers.StepOptions options = stepSource.block.options;
  List<TaskFile> files = options.files;
  assertTrue("Wrong number of task files", files.size() == 1);
  List<AnswerPlaceholder> placeholders = files.get(0).getAnswerPlaceholders();
  assertTrue("Wrong number of placeholders", placeholders.size() == 1);
  Map<Integer, AnswerPlaceholderSubtaskInfo> infos = placeholders.get(0).getSubtaskInfos();
  assertNotNull(infos);
  assertEquals(Collections.singletonList("Type your name here."), infos.get(0).getHints());
  assertEquals("Liana", infos.get(0).getPossibleAnswer());
  return options;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:17,代码来源:StudyStepicFormatTest.java

示例14: getTestsFile

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
@Nullable
@Override
protected VirtualFile getTestsFile() {
  String testFileName = EduJavaPluginConfigurator.TEST_JAVA;
  if (myTask instanceof TaskWithSubtasks) {
    int activeSubtaskIndex = ((TaskWithSubtasks) myTask).getActiveSubtaskIndex();
    testFileName = FileUtil.getNameWithoutExtension(testFileName) + EduNames.SUBTASK_MARKER + activeSubtaskIndex + "." + FileUtilRt.getExtension(EduJavaPluginConfigurator.TEST_JAVA);
  }
  VirtualFile taskDir = myTask.getTaskDir(myProject);
  if (taskDir == null) {
    return null;
  }
  VirtualFile srcDir = taskDir.findChild(EduNames.SRC);
  if (srcDir != null) {
    taskDir = srcDir;
  }
  VirtualFile virtualFile = taskDir.findChild(testFileName);
  if (virtualFile != null) {
    return virtualFile;
  }
  return null;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:23,代码来源:EduJavaPyCharmTaskChecker.java

示例15: createModule

import com.intellij.openapi.util.io.FileUtil; //导入依赖的package包/类
@NotNull
@Override
public Module createModule(@NotNull ModifiableModuleModel moduleModel) throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException {
  Module baseModule = super.createModule(moduleModel);
  Project project = baseModule.getProject();
  EduProjectGenerator generator = new EduProjectGenerator();
  if (myCourse == null) {
    File courseRoot = StudyUtils.getBundledCourseRoot(DEFAULT_COURSE_NAME, EduKotlinKoansModuleBuilder.class);
    final Course course = generator.addLocalCourse(FileUtil.join(courseRoot.getPath(), DEFAULT_COURSE_NAME));
    if (course == null) {
      LOG.info("Failed to find course " + DEFAULT_COURSE_NAME);
      return baseModule;
    }
  }
  myCourse.setLanguage("kotlin");
  EduModuleBuilderUtils.createCourseFromCourseInfo(moduleModel, project, generator, myCourse, getModuleFileDirectory());
  return baseModule;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:19,代码来源:EduKotlinKoansModuleBuilder.java


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