本文整理汇总了Java中com.intellij.openapi.vfs.VfsUtil.loadText方法的典型用法代码示例。如果您正苦于以下问题:Java VfsUtil.loadText方法的具体用法?Java VfsUtil.loadText怎么用?Java VfsUtil.loadText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.vfs.VfsUtil
的用法示例。
在下文中一共展示了VfsUtil.loadText方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getReaderByUrl
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
@Nullable
public static Reader getReaderByUrl(final String surl, final HttpConfigurable httpConfigurable, final ProgressIndicator pi) throws IOException {
if (surl.startsWith(JAR_PROTOCOL)) {
VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(BrowserUtil.getDocURL(surl));
if (file == null) {
return null;
}
return new StringReader(VfsUtil.loadText(file));
}
URL url = BrowserUtil.getURL(surl);
if (url == null) {
return null;
}
httpConfigurable.prepareURL(url.toString());
final URLConnection urlConnection = url.openConnection();
final String contentEncoding = urlConnection.getContentEncoding();
final InputStream inputStream =
pi != null ? UrlConnectionUtil.getConnectionInputStreamWithException(urlConnection, pi) : urlConnection.getInputStream();
//noinspection IOResourceOpenedButNotSafelyClosed
return contentEncoding != null ? new InputStreamReader(inputStream, contentEncoding) : new InputStreamReader(inputStream);
}
示例2: configureByFile
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
/**
* Like <a href="#configureByFileText(String, String, String)">configureByFileText</a>, but with a file to be read.
* @param filePath file to read and parse
* @param markerRegexp regexp for markers
* @return a mapping of markers to PSI elements
* @throws Exception
*/
protected Map<String, PsiElement> configureByFile(@TestDataFile @NonNls String filePath, @NonNls String markerRegexp) {
final String fullPath = getTestDataPath() + filePath;
final VirtualFile vFile = getVirtualFileByName(fullPath);
assertNotNull("file " + fullPath + " not found", vFile);
final String text;
try {
text = VfsUtil.loadText(vFile);
}
catch (IOException e) {
throw new RuntimeException(e);
}
String fileText = StringUtil.convertLineSeparators(text, "\n");
final String fileName = vFile.getName();
return configureByFileText(fileText, fileName, markerRegexp);
}
示例3: read
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
@Nullable
public static Element read(final VirtualFile file, @Nullable final ErrorHandler handler) {
String text;
AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
try {
if (!file.isValid()) return null;
try {
text = VfsUtil.loadText(file);
}
catch (IOException e) {
if (handler != null) handler.onReadError(e);
return null;
}
}
finally {
accessToken.finish();
}
return doRead(text, handler);
}
示例4: calcPropertyValue
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
protected String calcPropertyValue(String propertyName) {
String text = myCachedText;
if (text != null) {
return text;
}
final PsiFileSystemItem file = getSrcFile().getValue();
if (!(file instanceof PsiFile)) {
return "";
}
final VirtualFile vFile = ((PsiFile)file).getOriginalFile().getVirtualFile();
if (vFile == null) {
return "";
}
try {
text = VfsUtil.loadText(vFile);
myCachedText = text;
}
catch (IOException e) {
LOG.info(e);
text = "";
}
return text;
}
示例5: configureByFileWithMarker
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
protected PsiElement configureByFileWithMarker(String filePath, String marker) throws Exception{
final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(filePath.replace(File.separatorChar, '/'));
assertNotNull("file " + filePath + " not found", vFile);
String fileText = VfsUtil.loadText(vFile);
fileText = StringUtil.convertLineSeparators(fileText);
int offset = fileText.indexOf(marker);
assertTrue(offset >= 0);
fileText = fileText.substring(0, offset) + fileText.substring(offset + marker.length());
myFile = createFile(vFile.getName(), fileText);
return myFile.findElementAt(offset);
}
示例6: getInstalledPluginNameByPath
import com.intellij.openapi.vfs.VfsUtil; //导入方法依赖的package包/类
@Override
public String getInstalledPluginNameByPath(Project project, @NotNull VirtualFile pluginPath) {
String nameFromPluginXml = super.getInstalledPluginNameByPath(project, pluginPath);
if (nameFromPluginXml != null) {
return nameFromPluginXml;
}
VirtualFile pluginJson = pluginPath.findChild("plugin.json");
if (pluginJson != null) {
String pluginAndVersion = pluginPath.getName(); // pluginName-version
TIntArrayList separatorIndexes = new TIntArrayList();
int start = -1;
while (true) {
start = pluginAndVersion.indexOf('-', start + 1);
if (start == -1) break;
separatorIndexes.add(start);
}
if (separatorIndexes.size() == 1) {
return pluginAndVersion.substring(0, separatorIndexes.get(0));
}
if (!separatorIndexes.isEmpty()) {
String json;
try {
json = VfsUtil.loadText(pluginJson);
}
catch (IOException e) {
return null;
}
for (int i = 0; i < separatorIndexes.size(); i++) {
int idx = separatorIndexes.get(i);
String name = pluginAndVersion.substring(0, idx);
String version = pluginAndVersion.substring(idx + 1);
if (hasValue(PLUGIN_NAME_JSON_PATTERN, json, name) && hasValue(PLUGIN_VERSION_JSON_PATTERN, json, version)) {
return name;
}
}
}
}
return null;
}