本文整理汇总了Java中com.intellij.openapi.vfs.VirtualFile.contentsToByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java VirtualFile.contentsToByteArray方法的具体用法?Java VirtualFile.contentsToByteArray怎么用?Java VirtualFile.contentsToByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.vfs.VirtualFile
的用法示例。
在下文中一共展示了VirtualFile.contentsToByteArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: determineBranchName
import com.intellij.openapi.vfs.VirtualFile; //导入方法依赖的package包/类
private String determineBranchName(VirtualFile headFile) {
if (headFile != null) {
try {
String headLinkAsString = new String(headFile.contentsToByteArray());
Matcher matcher = FIRST_LINE_PATTERN.matcher(headLinkAsString);
if (matcher.find() && matcher.groupCount() >= 2) {
String branchName = matcher.group(2).trim();
branchName = removePrefix("refs/", branchName);
branchName = removePrefix("heads/", branchName);
return branchName;
}
} catch (Exception e) {
// ignore
}
}
// could not determine branch name, returning null
return null;
}
示例2: actionPerformed
import com.intellij.openapi.vfs.VirtualFile; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE);
if (file == null) {
showError("找不到目标文件");
return;
}
if (!file.isDirectory()) {
showError("请选择layout文件夹");
return;
} else if (!file.getName().startsWith("layout")) {
showError("请选择layout文件夹");
return;
}
VirtualFile[] children = file.getChildren();
StringBuilder sb = new StringBuilder();
for (VirtualFile child : children) {
layoutChild(child, sb);
}
VirtualFile resDir = file.getParent();
if (resDir.getName().equalsIgnoreCase("res")) {
VirtualFile[] chids = resDir.getChildren();
for (VirtualFile chid : chids) {
if (chid.getName().startsWith("values")) {
if (chid.isDirectory()) {
VirtualFile[] values = chid.getChildren();
for (VirtualFile value : values) {
if (value.getName().startsWith("strings")) {
try {
String content = new String(value.contentsToByteArray(), "utf-8");
System.out.println("utf-8=" + content);
String result = content.replace("</resources>", sb.toString() + "\n</resources>");
FileUtils.replaceContentToFile(value.getPath(), result);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
}
}
}
e.getActionManager().getAction(IdeActions.ACTION_SYNCHRONIZE).actionPerformed(e);
}