Java Code Examples for com.intellij.openapi.util.io.StreamUtil#readText()
The following examples show how to use
com.intellij.openapi.util.io.StreamUtil#readText() .
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: RoutingRemoteFileStorage.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Override public void build(@NotNull Project project, @NotNull Collection<FileObject> fileObjects) { Map<String, Route> routeMap = new HashMap<>(); for (FileObject file : fileObjects) { String content; try { content = StreamUtil.readText(file.getContent().getInputStream(), "UTF-8"); } catch (IOException e) { continue; } if(StringUtils.isBlank(content)) { continue; } routeMap.putAll(RouteHelper.getRoutesInsideUrlGeneratorFile( PhpPsiElementFactory.createPsiFileFromText(project, content) )); } this.routeMap = routeMap; }
Example 2
Source File: PluginErrorReportSubmitter.java From BashSupport with Apache License 2.0 | 6 votes |
@Nullable private String readUrlContent(String urlString) { HttpConfigurable httpConfigurable = HttpConfigurable.getInstance(); HttpURLConnection connection = null; try { connection = httpConfigurable.openHttpConnection(urlString); String text = StreamUtil.readText(connection.getInputStream(), "UTF-8"); return text.trim(); } catch (IOException e) { //ignored } finally { if (connection != null) { connection.disconnect(); } } return null; }
Example 3
Source File: ClasspathDocSource.java From BashSupport with Apache License 2.0 | 6 votes |
/** * Reads documenation from a url, mostly this is a file source. * * @param path The prefix path to use. * @param command The command name, e.g. "echo" * @return The documentation content or null. */ private String readFromClasspath(String path, String command) { if (StringUtil.isEmpty(path) || StringUtil.isEmpty(command)) { return null; } final String fullPath = path + "/" + command + ".html"; try { URL url = getClass().getResource(fullPath); if (url == null) { return null; } final InputStream inputStream = new BufferedInputStream(url.openStream()); return StreamUtil.readText(inputStream, "UTF-8"); } catch (IOException e) { log.debug("Failed to read documentation.", e); } return null; }
Example 4
Source File: ExtensionProviderUtil.java From idea-php-toolbox with MIT License | 5 votes |
@NotNull private static Collection<JsonConfigFile> getResourceFiles() { synchronized (STREAM_RESOURCES_LOCK) { if(RESOURCE_FILES != null) { return RESOURCE_FILES; } Collection<JsonConfigFile> files = new ArrayList<>(); for (JsonStreamResource resource : STREAM_RESOURCES.getExtensions()) { for (InputStream stream : resource.getInputStreams()) { String contents; try { contents = StreamUtil.readText(stream, "UTF-8"); } catch (IOException e) { continue; } JsonConfigFile config = JsonParseUtil.getDeserializeConfig(contents); if(config != null) { files.add(config); } } } return RESOURCE_FILES = files; } }
Example 5
Source File: ProjectProviderPostHttpAction.java From idea-php-toolbox with MIT License | 5 votes |
@Override protected Response handle(@NotNull Project project, @NotNull RequestMatcher requestMatcher) { String providerName = requestMatcher.getVar("provider"); if(providerName == null) { return new Response("invalid request"); } ProviderInterface provider = RemoteUtil.getProvider(providerName); if(provider == null) { return new JsonResponse(ErrorDic.create("provider not found: " + providerName)); } String content; try { content = StreamUtil.readText(requestMatcher.getHttpExchange().getRequestBody(), "UTF-8"); } catch (IOException ignored) { return new JsonResponse("error"); } RemoteStorage instance = RemoteStorage.getInstance(project); try { instance.set(provider, content); } catch (Exception e) { return new JsonResponse(ErrorDic.create(e.getMessage()), 400); } return new JsonResponse(SuccessDic.create("items added")); }
Example 6
Source File: ExtensionProviderUtil.java From idea-php-toolbox with MIT License | 5 votes |
@NotNull private static Collection<JsonConfigFile> getResourceFiles() { synchronized (STREAM_RESOURCES_LOCK) { if(RESOURCE_FILES != null) { return RESOURCE_FILES; } Collection<JsonConfigFile> files = new ArrayList<>(); for (JsonStreamResource resource : STREAM_RESOURCES.getExtensions()) { for (InputStream stream : resource.getInputStreams()) { String contents; try { contents = StreamUtil.readText(stream, "UTF-8"); } catch (IOException e) { continue; } JsonConfigFile config = JsonParseUtil.getDeserializeConfig(contents); if(config != null) { files.add(config); } } } return RESOURCE_FILES = files; } }
Example 7
Source File: BashColorsAndFontsPage.java From BashSupport with Apache License 2.0 | 5 votes |
@NonNls @NotNull public String getDemoText() { InputStream resource = getClass().getClassLoader().getResourceAsStream("/highlighterDemoText.sh"); String demoText; try { demoText = StreamUtil.readText(resource, "UTF-8"); } catch (IOException e) { throw new RuntimeException("BashSupport could not load the syntax highlighter demo text.", e); } return demoText; }
Example 8
Source File: ProjectProviderPostHttpAction.java From idea-php-toolbox with MIT License | 5 votes |
@Override protected Response handle(@NotNull Project project, @NotNull RequestMatcher requestMatcher) { String providerName = requestMatcher.getVar("provider"); if(providerName == null) { return new Response("invalid request"); } ProviderInterface provider = RemoteUtil.getProvider(providerName); if(provider == null) { return new JsonResponse(ErrorDic.create("provider not found: " + providerName)); } String content; try { content = StreamUtil.readText(requestMatcher.getHttpExchange().getRequestBody(), "UTF-8"); } catch (IOException ignored) { return new JsonResponse("error"); } RemoteStorage instance = RemoteStorage.getInstance(project); try { instance.set(provider, content); } catch (Exception e) { return new JsonResponse(ErrorDic.create(e.getMessage()), 400); } return new JsonResponse(SuccessDic.create("items added")); }
Example 9
Source File: SoyLanguageCodeStyleSettingsProvider.java From bamboo-soy with Apache License 2.0 | 5 votes |
private String loadSample(String name) { try { return StreamUtil .readText(getClass().getClassLoader().getResourceAsStream("codeSamples/" + name + ".soy"), "UTF-8"); } catch (IOException e) { return ""; } }
Example 10
Source File: GitIntegration.java From DarkyenusTimeTracker with The Unlicense | 5 votes |
private static String prepareCommitMessageHookContent (Path timeTrackerFile, Path gitHooksDirectory) throws IOException { String content = GitIntegration.prepareCommitMessageHookContent_cache; if (content == null) { content = GitIntegration.prepareCommitMessageHookContent_cache = StreamUtil.readText(GitIntegration.class.getResourceAsStream( "/hooks/"+ PREPARE_COMMIT_MESSAGE_HOOK_NAME), StandardCharsets.UTF_8); } return content.replace(DTT_TIME_RELATIVE_PATH_PLACEHOLDER, gitHooksDirectory.relativize(timeTrackerFile).toString()); }
Example 11
Source File: HttpUtils.java From AndroidStringsOneTabTranslation with Apache License 2.0 | 5 votes |
public static String doHttpPost(String url, String xmlBody, Header[] headers) { try { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setHeaders(headers); httpPost.setEntity(new StringEntity(xmlBody, "UTF-8")); HttpResponse resp = httpClient.execute(httpPost); return StreamUtil.readText(resp.getEntity().getContent(), "UTF-8"); } catch (Exception e) { e.printStackTrace(); } return null; }
Example 12
Source File: HttpUtils.java From AndroidStringsOneTabTranslation with Apache License 2.0 | 5 votes |
public static String doHttpPost(String url, List<NameValuePair> params) { try { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpResponse resp = httpClient.execute(httpPost); return StreamUtil.readText(resp.getEntity().getContent(), "UTF-8"); } catch (Exception e) { e.printStackTrace(); } return null; }
Example 13
Source File: HttpUtils.java From AndroidStringsOneTabTranslation with Apache License 2.0 | 5 votes |
public static String doHttpGet(String url, Header[] headers) { try { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); httpGet.setHeaders(headers); HttpResponse resp = httpClient.execute(httpGet); return StreamUtil.readText(resp.getEntity().getContent(), "UTF-8"); } catch (Exception e) { e.printStackTrace(); } return null; }
Example 14
Source File: HttpUtils.java From AndroidStringsOneTabTranslation with Apache License 2.0 | 5 votes |
public static String doHttpGet(String url) { try { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); HttpResponse resp = httpClient.execute(httpGet); return StreamUtil.readText(resp.getEntity().getContent(), "UTF-8"); } catch (Exception e) { e.printStackTrace(); } return null; }
Example 15
Source File: CargoBuildProcessAdapterHttpsTest.java From teamcity-deployer-plugin with Apache License 2.0 | 4 votes |
private void assertUrlReturns(URL url, String expected2) throws IOException { final InputStream stream2 = url.openStream(); final String text2 = StreamUtil.readText(stream2); assertTrue(text2.contains(expected2)); }
Example 16
Source File: CargoBuildProcessAdapterTest.java From teamcity-deployer-plugin with Apache License 2.0 | 4 votes |
private void assertUrlReturns(URL url, String expected2) throws IOException { final InputStream stream2 = url.openStream(); final String text2 = StreamUtil.readText(stream2); assertTrue(text2.contains(expected2)); }
Example 17
Source File: ServiceActionUtil.java From idea-php-shopware-plugin with MIT License | 4 votes |
public static void buildFile(AnActionEvent event, final Project project, String templatePath, String fileName) { DataContext dataContext = event.getDataContext(); IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); if (view == null) { return; } PsiDirectory[] directories = view.getDirectories(); if(directories.length == 0) { return; } final PsiDirectory initialBaseDir = directories[0]; if (initialBaseDir == null) { return; } if(initialBaseDir.findFile(fileName) != null) { Messages.showInfoMessage("File exists", "Error"); return; } String content; try { content = StreamUtil.readText(ServiceActionUtil.class.getResourceAsStream(templatePath), "UTF-8"); } catch (IOException e) { e.printStackTrace(); return; } final PsiFileFactory factory = PsiFileFactory.getInstance(project); final PsiFile file = factory.createFileFromText(fileName, XmlFileType.INSTANCE, content); ApplicationManager.getApplication().runWriteAction(() -> { CodeStyleManager.getInstance(project).reformat(file); initialBaseDir.add(file); }); PsiFile psiFile = initialBaseDir.findFile(fileName); if(psiFile != null) { view.selectElement(psiFile); } }