Java Code Examples for com.intellij.openapi.vfs.VfsUtilCore#loadText()

The following examples show how to use com.intellij.openapi.vfs.VfsUtilCore#loadText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MatchPatchPaths.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static int getMatchingLines(final AbstractFilePatchInProgress<TextFilePatch> patch) {
  final VirtualFile base = patch.getCurrentBase();
  if (base == null) return -1;
  String text;
  try {
    if (base.getLength() > BIG_FILE_BOUND) {
      // partially
      text = VfsUtilCore.loadText(base, BIG_FILE_BOUND);
    }
    else {
      text = VfsUtilCore.loadText(base);
    }
  }
  catch (IOException e) {
    return 0;
  }
  return new GenericPatchApplier(text, patch.getPatch().getHunks()).weightContextMatch(100, 5);
}
 
Example 2
Source File: PsiTypeUtils.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
public static String findPropertiesResource(VirtualFile packageRoot, String propertiesFileName) {
    VirtualFile metaInfDir = packageRoot.findChild("META-INF");
    if (metaInfDir != null) {
        VirtualFile file = metaInfDir.findChild(propertiesFileName);
        if (file != null) {
            try {
                return VfsUtilCore.loadText(file);
            } catch (IOException e) {
                LOGGER.error(e.getLocalizedMessage(), e);
            }
        }
    }
    return null;
}
 
Example 3
Source File: PantsUtil.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private static Optional<String> findVersionInFile(@NotNull VirtualFile file) {
  try {
    final String fileContent = VfsUtilCore.loadText(file);
    final List<String> matches = StringUtil.findMatches(
      fileContent, Pattern.compile(PANTS_VERSION_REGEXP)
    );
    return matches.stream().findFirst();
  }
  catch (IOException e) {
    return Optional.empty();
  }
}