本文整理汇总了Java中com.intellij.openapi.util.io.FileUtil.loadTextAndClose方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.loadTextAndClose方法的具体用法?Java FileUtil.loadTextAndClose怎么用?Java FileUtil.loadTextAndClose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.util.io.FileUtil
的用法示例。
在下文中一共展示了FileUtil.loadTextAndClose方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadTemplate
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@NotNull
public static String loadTemplate(@NotNull ClassLoader loader, @NotNull String templateName, @Nullable Map<String, String> variables) throws IOException {
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed") InputStream stream = loader.getResourceAsStream(templateName);
if (stream == null) {
throw new IOException("Template '" + templateName + "' not found by " + loader);
}
String template = FileUtil.loadTextAndClose(new InputStreamReader(stream, CharsetToolkit.UTF8));
if (variables == null || variables.size() == 0) {
return template;
}
StringBuilder buffer = new StringBuilder(template);
for (Map.Entry<String, String> var : variables.entrySet()) {
String name = var.getKey();
int pos = buffer.indexOf(name);
if (pos >= 0) {
buffer.replace(pos, pos + name.length(), var.getValue());
}
}
return buffer.toString();
}
示例2: testAppendEntry
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testAppendEntry() throws Exception {
JBZipFile jbZip = new JBZipFile(zipFile);
assertEntryWithContentExists(jbZip, "/first", "first");
assertEntryWithContentExists(jbZip, "/second", "second");
JBZipEntry newEntry = jbZip.getOrCreateEntry("/third");
newEntry.setData("third".getBytes());
jbZip.close();
ZipFile utilZip = new ZipFile(zipFile);
ZipEntry thirdEntry = utilZip.getEntry("/third");
assertNotNull(thirdEntry);
String thirdText = FileUtil.loadTextAndClose(new InputStreamReader(utilZip.getInputStream(thirdEntry)));
assertEquals("third", thirdText);
utilZip.close();
}
示例3: testReplaceEntryContent
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void testReplaceEntryContent() throws Exception {
JBZipFile jbZip = new JBZipFile(zipFile);
assertEntryWithContentExists(jbZip, "/first", "first");
assertEntryWithContentExists(jbZip, "/second", "second");
JBZipEntry newEntry = jbZip.getOrCreateEntry("/second");
newEntry.setData("Content Replaced".getBytes());
jbZip.close();
ZipFile utilZip = new ZipFile(zipFile);
ZipEntry updatedEntry = utilZip.getEntry("/second");
assertNotNull(updatedEntry);
String thirdText = FileUtil.loadTextAndClose(new InputStreamReader(utilZip.getInputStream(updatedEntry)));
assertEquals("Content Replaced", thirdText);
utilZip.close();
}
示例4: getTaskText
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@Nullable
private static String getTaskText(@Nullable final Task task, @Nullable final VirtualFile taskDirectory) {
if (task == null) {
return null;
}
String text = task.getText();
if (text != null) {
return text;
}
if (taskDirectory != null) {
VirtualFile taskTextFile = taskDirectory.findChild(EduNames.TASK_HTML);
if (taskTextFile != null) {
try {
return FileUtil.loadTextAndClose(taskTextFile.getInputStream());
}
catch (IOException e) {
LOG.info(e);
}
}
}
return null;
}
示例5: readMediaTypes
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static void readMediaTypes(TreeSet<String> result, final String category) {
final InputStream stream = MimeTypeDictionary.class.getResourceAsStream("mimeTypes/" + category + ".csv");
String csv = "";
try {
csv = stream != null ? FileUtil.loadTextAndClose(stream) : "";
}
catch (IOException e) {
Logger.getInstance(MimeTypeDictionary.class).error(e);
}
final String[] lines = StringUtil.splitByLines(csv);
for (String line : lines) {
if (line == lines[0]) continue;
final String[] split = line.split(",");
if (split.length > 1) {
result.add(!split[1].isEmpty() ? split[1] : withCategory(category, split[0]));
}
}
}
示例6: createFormBody
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
protected String createFormBody(@Nullable String fqn, @NonNls String formName, String layoutManager) throws IncorrectOperationException {
String s;
try {
s = FileUtil.loadTextAndClose(getClass().getResourceAsStream(formName));
}
catch (IOException e) {
throw new IncorrectOperationException(UIDesignerBundle.message("error.cannot.read", formName), (Throwable)e);
}
if (fqn != null) {
s = StringUtil.replace(s, "$CLASS$", fqn);
}
else {
s = StringUtil.replace(s, "bind-to-class=\"$CLASS$\"", "");
}
s = StringUtil.replace(s, "$LAYOUT$", layoutManager);
return StringUtil.convertLineSeparators(s);
}
示例7: isMoveOperation
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static boolean isMoveOperation(@NotNull final Transferable transferable) {
if (transferable.isDataFlavorSupported(gnomeFileListFlavor)) {
try {
final Object transferData = transferable.getTransferData(gnomeFileListFlavor);
final String content = FileUtil.loadTextAndClose((InputStream)transferData);
return content.startsWith("cut\n");
}
catch (Exception ignored) { }
}
else if (transferable.isDataFlavorSupported(kdeCutMarkFlavor)) {
return true;
}
return false;
}
示例8: getProcessList
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static String getProcessList() {
try {
@SuppressWarnings("SpellCheckingInspection") Process process = new ProcessBuilder()
.command(SystemInfo.isWindows ? new String[]{System.getenv("windir") + "\\system32\\tasklist.exe", "/v"} : new String[]{"ps", "a"})
.redirectErrorStream(true)
.start();
return FileUtil.loadTextAndClose(process.getInputStream());
}
catch (IOException e) {
return ExceptionUtil.getThrowableText(e);
}
}
示例9: getSystemMemoryInfo
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static String getSystemMemoryInfo() {
try {
@SuppressWarnings("SpellCheckingInspection") Process process = new ProcessBuilder()
.command(new String[]{SystemInfo.isWindows ? "systeminfo" : SystemInfo.isMac ? "vm_stat" : "free"})
.redirectErrorStream(true)
.start();
return FileUtil.loadTextAndClose(process.getInputStream());
}
catch (IOException e) {
return ExceptionUtil.getThrowableText(e);
}
}
示例10: getBuildSrcDefaultInitScript
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@Nullable
public static String getBuildSrcDefaultInitScript() {
InputStream stream = Init.class.getResourceAsStream("/org/jetbrains/plugins/gradle/tooling/internal/init/buildSrcInit.gradle");
try {
if (stream == null) return null;
return FileUtil.loadTextAndClose(stream);
}
catch (Exception e) {
LOG.warn("Can't use IJ gradle init script", e);
return null;
}
finally {
StreamUtil.closeStream(stream);
}
}
示例11: createUIComponents
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private void createUIComponents() {
// TODO: place custom component creation code here
splitPanel = new JPanel();
splitPanel.setPreferredSize(JBUI.size(300, 400));
jSplitPane = new JSplitPane();
jSplitPane.setOrientation(0);
jSplitPane.setContinuousLayout(true);
jSplitPane.setBorder(BorderFactory.createEmptyBorder());
varPanel = new JPanel(new BorderLayout());
varPanel.setBorder(IdeBorderFactory.createTitledBorder("Predefined Variables", false));
varTable = new JBTable();
varTable.getEmptyText().setText("No Variables");
//不可整列移动
varTable.getTableHeader().setReorderingAllowed(false);
//不可拉动表格
varTable.getTableHeader().setResizingAllowed(false);
JPanel panel = ToolbarDecorator.createDecorator(varTable)
.setAddAction(it -> addAction())
.setRemoveAction(it -> removeAction())
.setEditAction(it -> editAction()).createPanel();
varPanel.add(panel, BorderLayout.CENTER);
descPanel = new JPanel(new BorderLayout());
descPanel.setBorder(IdeBorderFactory.createTitledBorder("Default Variables & Directives", false));
String inHouseVariables;
try {
inHouseVariables = FileUtil.loadTextAndClose(VariableUI.class.getResourceAsStream("/variables.md"));
} catch (Exception e) {
inHouseVariables = "something error";
}
descArea = new JTextArea();
descArea.setText(inHouseVariables);
descArea.setEditable(false);
descPanel.add(ScrollPaneFactory.createScrollPane(descArea), BorderLayout.CENTER);
// ignore fields
ignorePane = new JPanel();
ignorePane.setBorder(IdeBorderFactory.createTitledBorder("The Ignore Fields", false));
}