Java Code Examples for com.intellij.openapi.util.io.FileUtil#loadTextAndClose()
The following examples show how to use
com.intellij.openapi.util.io.FileUtil#loadTextAndClose() .
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: Log4J2LoggerFactory.java From consulo with Apache License 2.0 | 6 votes |
@Nullable private static LoggerContext init() { try { String fileRef = Boolean.getBoolean(ApplicationProperties.CONSULO_MAVEN_CONSOLE_LOG) ? "/log4j2-console.xml" : "/log4j2-default.xml"; String text = FileUtil.loadTextAndClose(Log4J2LoggerFactory.class.getResourceAsStream(fileRef)); text = StringUtil.replace(text, SYSTEM_MACRO, StringUtil.replace(ContainerPathManager.get().getSystemPath(), "\\", "\\\\")); text = StringUtil.replace(text, APPLICATION_MACRO, StringUtil.replace(ContainerPathManager.get().getHomePath(), "\\", "\\\\")); text = StringUtil.replace(text, LOG_DIR_MACRO, StringUtil.replace(ContainerPathManager.get().getLogPath(), "\\", "\\\\")); File file = new File(ContainerPathManager.get().getLogPath()); if (!file.mkdirs() && !file.exists()) { System.err.println("Cannot create log directory: " + file); } ConfigurationSource source = new ConfigurationSource(new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8))); return Configurator.initialize(Log4J2LoggerFactory.class.getClassLoader(), source); } catch (Exception e) { e.printStackTrace(); StartupUtil.showMessage("Consulo", e); return null; } }
Example 2
Source File: UpdateableZipTest.java From consulo with Apache License 2.0 | 6 votes |
public void testReplaceEntryContent() throws Exception { File zipFile = createTestUtilZip(); 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(); }
Example 3
Source File: AbstractCreateFormAction.java From react-templates-plugin with MIT License | 5 votes |
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(RTBundle.message("error.cannot.read", formName), (Throwable)e); } s = fqn == null ? StringUtil.replace(s, "bind-to-class=\"$CLASS$\"", "") : StringUtil.replace(s, "$CLASS$", fqn); s = StringUtil.replace(s, "$LAYOUT$", layoutManager); return StringUtil.convertLineSeparators(s); }
Example 4
Source File: GeneralColorsPage.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public String getDemoText() { try { return FileUtil.loadTextAndClose(getClass().getResourceAsStream("/colorSettingPage/general.txt"), true) + getCustomSeveritiesDemoText(); } catch (IOException e) { return "demo text not found"; } }
Example 5
Source File: LogUtil.java From consulo with Apache License 2.0 | 5 votes |
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); } }
Example 6
Source File: PhpHeaderDocumentationProvider.java From idea-php-advanced-autocomplete with MIT License | 5 votes |
@NotNull private static Map<String, String> readHeaderDescriptions() { Map<String, String> result = ContainerUtil.newHashMap(); // Re-use docs from JB HTTP Client plugin InputStream stream = PhpHeaderDocumentationProvider.class.getResourceAsStream(HEADERS_DOC_JSON); try { String file = stream != null ? FileUtil.loadTextAndClose(stream) : ""; if (StringUtil.isNotEmpty(file)) { JsonElement root = (new JsonParser()).parse(file); if (root.isJsonArray()) { JsonArray array = root.getAsJsonArray(); for (JsonElement element : array) { if (element.isJsonObject()) { JsonObject obj = element.getAsJsonObject(); String name = getAsString(obj, "name"); if (!StringUtil.isNotEmpty(name)) { continue; } String description = getAsString(obj, "descr"); if (!StringUtil.isNotEmpty(description)) { continue; } result.put(name, description); } } } } } catch (IOException ignored) { } return result; }
Example 7
Source File: CSharpLanguageCodeStyleSettingsProvider.java From consulo-csharp with Apache License 2.0 | 5 votes |
private static String loadPreview(String file) { try { return FileUtil.loadTextAndClose(CSharpLanguageCodeStyleSettingsProvider.class.getResourceAsStream("/codeStyle/" + file)); } catch(IOException e) { throw new Error(e); } }
Example 8
Source File: WinProcessManager.java From consulo with Apache License 2.0 | 5 votes |
private static boolean kill(int pid, Process process, boolean tree) { LOG.assertTrue(pid > 0 || process != null); try { if (process != null) { pid = getProcessId(process); } String[] cmdArray = {"taskkill", "/f", "/pid", String.valueOf(pid), tree ? "/t" : ""}; if (LOG.isDebugEnabled()) { LOG.debug(StringUtil.join(cmdArray, " ")); } Process p = new ProcessBuilder(cmdArray).redirectErrorStream(true).start(); String output = FileUtil.loadTextAndClose(p.getInputStream()); int res = p.waitFor(); if (res != 0 && (process == null || process.isAlive())) { LOG.warn(StringUtil.join(cmdArray, " ") + " failed: " + output); return false; } else if (LOG.isDebugEnabled()) { LOG.debug(output); } return true; } catch (Exception e) { LOG.warn(e); } return false; }
Example 9
Source File: CreateRTAction.java From react-templates-plugin with MIT License | 5 votes |
private static String getTemplate() { String s = ""; try { s = FileUtil.loadTextAndClose(CreateRTAction.class.getResourceAsStream("/fileTemplates/internal/RT File.rt.ft")); } catch (IOException e) { // throw new IncorrectOperationException(RTBundle.message("error.cannot.read", formName), (Throwable)e); } return StringUtil.convertLineSeparators(s); }
Example 10
Source File: CreateRTAction.java From react-templates-plugin with MIT License | 5 votes |
private static String getControllerTemplate(String name, String modules) { String s = ""; try { String ext = RTRunner.TYPESCRIPT.equals(modules) ? "ts" : "js"; String tplName = "/fileTemplates/internal/RT Controller File " + modules + '.' + ext + ".ft"; s = FileUtil.loadTextAndClose(CreateRTAction.class.getResourceAsStream(tplName)); s = StringUtil.replace(s, "$name$", name); } catch (IOException e) { // throw new IncorrectOperationException(RTBundle.message("error.cannot.read", formName), (Throwable)e); } return StringUtil.convertLineSeparators(s); }
Example 11
Source File: RTDocumentationProvider.java From react-templates-plugin with MIT License | 5 votes |
private static String getDoc(String tag) { // return RTBundle.message("doc." + name); try { String s = FileUtil.loadTextAndClose(RTDocumentationProvider.class.getResourceAsStream("/tagDescriptions/" + tag + ".html")); return StringUtil.convertLineSeparators(s); } catch (IOException e) { // throw new IncorrectOperationException(RTBundle.message("error.cannot.read", formName), (Throwable)e); return "null"; } }
Example 12
Source File: CreateRTAction.java From react-templates-plugin with MIT License | 5 votes |
private static String getTemplate() { String s = ""; try { s = FileUtil.loadTextAndClose(CreateRTAction.class.getResourceAsStream("/fileTemplates/internal/RT File.rt.ft")); } catch (IOException e) { // throw new IncorrectOperationException(RTBundle.message("error.cannot.read", formName), (Throwable)e); } return StringUtil.convertLineSeparators(s); }
Example 13
Source File: CreateRTAction.java From react-templates-plugin with MIT License | 5 votes |
private static String getControllerTemplate(String name, String modules) { String s = ""; try { String ext = RTRunner.TYPESCRIPT.equals(modules) ? "ts" : "js"; String tplName = "/fileTemplates/internal/RT Controller File " + modules + '.' + ext + ".ft"; s = FileUtil.loadTextAndClose(CreateRTAction.class.getResourceAsStream(tplName)); s = StringUtil.replace(s, "$name$", name); } catch (IOException e) { // throw new IncorrectOperationException(RTBundle.message("error.cannot.read", formName), (Throwable)e); } return StringUtil.convertLineSeparators(s); }
Example 14
Source File: RTDocumentationProvider.java From react-templates-plugin with MIT License | 5 votes |
private static String getDoc(String tag) { // return RTBundle.message("doc." + name); try { String s = FileUtil.loadTextAndClose(RTDocumentationProvider.class.getResourceAsStream("/tagDescriptions/" + tag + ".html")); return StringUtil.convertLineSeparators(s); } catch (IOException e) { // throw new IncorrectOperationException(RTBundle.message("error.cannot.read", formName), (Throwable)e); return "null"; } }
Example 15
Source File: LinuxDragAndDropSupport.java From consulo with Apache License 2.0 | 5 votes |
public static boolean isMoveOperation(@Nonnull 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; }
Example 16
Source File: DocGenerateAction.java From CodeMaker with Apache License 2.0 | 5 votes |
/** * Instantiates a new Doc generate action. */ public DocGenerateAction() { super(); try { this.seeDocTemplate = FileUtil.loadTextAndClose(DocGenerateAction.class.getResourceAsStream("/template/See.vm")); } catch (IOException e) { LOGGER.error("load See.vm failed", e); } }
Example 17
Source File: TemplateSettings.java From code-generator with Apache License 2.0 | 4 votes |
@NotNull private Template loadTemplate(String templateName) throws IOException { String templateContent = FileUtil .loadTextAndClose(TemplateSettings.class.getResourceAsStream("/templates/" + templateName + ".vm")); return new Template(templateName, templateContent); }
Example 18
Source File: CodeMakerSettings.java From CodeMaker with Apache License 2.0 | 4 votes |
@NotNull private CodeTemplate createCodeTemplate(String name, String sourceTemplateName, String classNameVm, int classNumber, String targetLanguage) throws IOException { String velocityTemplate = FileUtil.loadTextAndClose(CodeMakerSettings.class.getResourceAsStream("/template/" + sourceTemplateName)); return new CodeTemplate(name, classNameVm, velocityTemplate, classNumber, CodeTemplate.DEFAULT_ENCODING, TemplateLanguage.vm, targetLanguage); }
Example 19
Source File: VariableUI.java From CodeGen with MIT License | 4 votes |
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)); }
Example 20
Source File: FileUtilTest.java From code-generator with Apache License 2.0 | 4 votes |
@Test public void loadText() throws IOException { String content = FileUtil.loadTextAndClose(TemplateSettings.class.getResourceAsStream("/templates/Mapper.vm")); Assert.assertEquals(true, StringUtils.isNotBlank(content)); }