当前位置: 首页>>代码示例>>Java>>正文


Java StreamUtil.readText方法代码示例

本文整理汇总了Java中com.intellij.openapi.util.io.StreamUtil.readText方法的典型用法代码示例。如果您正苦于以下问题:Java StreamUtil.readText方法的具体用法?Java StreamUtil.readText怎么用?Java StreamUtil.readText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.util.io.StreamUtil的用法示例。


在下文中一共展示了StreamUtil.readText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendHtmlResponse

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
private void sendHtmlResponse(@NotNull HttpRequest request, @NotNull ChannelHandlerContext context, String pagePath) throws IOException {
  BufferExposingByteArrayOutputStream byteOut = new BufferExposingByteArrayOutputStream();
  InputStream pageTemplateStream = getClass().getResourceAsStream(pagePath);
  String pageTemplate = StreamUtil.readText(pageTemplateStream, Charset.forName("UTF-8"));
  try {
    String pageWithProductName = pageTemplate.replaceAll("%IDE_NAME", ApplicationNamesInfo.getInstance().getFullProductName());
    byteOut.write(StreamUtil.loadFromStream(new ByteArrayInputStream(pageWithProductName.getBytes(Charset.forName("UTF-8")))));
    HttpResponse response = Responses.response("text/html", Unpooled.wrappedBuffer(byteOut.getInternalBuffer(), 0, byteOut.size()));
    Responses.addNoCache(response);
    response.headers().set("X-Frame-Options", "Deny");
    Responses.send(response, context.channel(), request);
  }
  finally {
    byteOut.close();
    pageTemplateStream.close();
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:18,代码来源:EduStepikRestService.java

示例2: readClasspathResource

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
@Nullable
private String readClasspathResource(String name) {
    try {
        String classpath = System.getProperty("java.class.path");
        LOGGER.debug("Reading " + name + " from classpath=" + classpath);
        ClassLoader classLoader = OptionReference.class.getClassLoader();
        if (classLoader == null) {
            throw new IllegalStateException("Can not obtain classloader instance");
        }
        InputStream resource = classLoader.getResourceAsStream(name);
        if (resource == null) {
            LOGGER.debug("Could not find " + name);
            return null;
        }
        return StreamUtil.readText(resource, StandardCharsets.UTF_8);
    } catch (Exception e) {
        LOGGER.error("Could not read " + name, e);
    }
    return null;
}
 
开发者ID:protostuff,项目名称:protobuf-jetbrains-plugin,代码行数:21,代码来源:BundledFileProviderImpl.java

示例3: readFile

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
/**
 *
 * @param path String
 * @return String
 */
private String readFile(String path)
{
    String content = "";

    try {
        content = StreamUtil.readText(
                PhpClassRenderer.class.getResourceAsStream(path),
                "UTF-8"
        );
    } catch (IOException e) {
        e.printStackTrace();
    }

    return content;
}
 
开发者ID:project-a,项目名称:idea-php-spryker-plugin,代码行数:21,代码来源:PhpClassRenderer.java

示例4: executeMethod

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
private String executeMethod(HttpMethod method) throws Exception {
  String responseBody;
  getHttpClient().executeMethod(method);
  Header contentType = method.getResponseHeader("Content-Type");
  if (contentType != null && contentType.getValue().contains("charset")) {
    // ISO-8859-1 if charset wasn't specified in response
    responseBody = StringUtil.notNullize(method.getResponseBodyAsString());
  }
  else {
    InputStream stream = method.getResponseBodyAsStream();
    responseBody = stream == null ? "" : StreamUtil.readText(stream, CharsetToolkit.UTF8_CHARSET);
  }
  if (method.getStatusCode() != HttpStatus.SC_OK) {
    throw new Exception("Request failed with HTTP error: " + method.getStatusText());
  }
  return responseBody;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GenericRepository.java

示例5: getResponseContentAsString

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
public static String getResponseContentAsString(@NotNull HttpMethod response) throws IOException {
  // Sometimes servers don't specify encoding and HttpMethod#getResponseBodyAsString
  // by default decodes from Latin-1, so we got to read byte stream and decode it from UTF-8
  // manually
  //if (!response.hasBeenUsed()) {
  //  return "";
  //}
  org.apache.commons.httpclient.Header header = response.getResponseHeader(HTTP.CONTENT_TYPE);
  if (header != null && header.getValue().contains("charset")) {
    // ISO-8859-1 if charset wasn't specified in response
    return StringUtil.notNullize(response.getResponseBodyAsString());
  }
  else {
    InputStream stream = response.getResponseBodyAsStream();
    return stream == null ? "" : StreamUtil.readText(stream, DEFAULT_CHARSET);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:TaskResponseUtil.java

示例6: readEntry

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
@Nullable
String readEntry(Condition<ZipEntry> condition) {
  ZipInputStream stream = null;
  try {
    stream = getStream();
    ZipEntry entry;
    while ((entry = stream.getNextEntry()) != null) {
      if (condition.value(entry)) {
        return StreamUtil.readText(stream, TemplateModuleBuilder.UTF_8);
      }
    }
  }
  catch (IOException e) {
    return null;
  }
  finally {
    StreamUtil.closeStream(stream);
  }
  return null;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:LocalArchivedTemplate.java

示例7: getTemplates

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
private static MultiMap<String, ArchivedProjectTemplate> getTemplates() {
  InputStream stream = null;
  HttpURLConnection connection = null;
  String code = ApplicationInfo.getInstance().getBuild().getProductCode();
  try {
    connection = getConnection(code + "_templates.xml");
    stream = connection.getInputStream();
    String text = StreamUtil.readText(stream, TemplateModuleBuilder.UTF_8);
    return createFromText(text);
  }
  catch (IOException ex) {  // timeouts, lost connection etc
    LOG.info(ex);
    return MultiMap.emptyInstance();
  }
  catch (Exception e) {
    LOG.error(e);
    return MultiMap.emptyInstance();
  }
  finally {
    StreamUtil.closeStream(stream);
    if (connection != null) {
      connection.disconnect();
    }
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:26,代码来源:RemoteTemplatesFactory.java

示例8: makeRequest

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
/**
 * Make GET request to specified URL and return HTTP entity of result as Reader object
 */
private String makeRequest(String url) throws IOException {
  HttpClient client = getHttpClient();
  HttpMethod method = new GetMethod(url);
  configureHttpMethod(method);
  String entityContent;
  try {
    client.executeMethod(method);
    // Can't use HttpMethod#getResponseBodyAsString because Trello doesn't specify encoding
    // in Content-Type header and by default this method decodes from Latin-1
    entityContent = StreamUtil.readText(method.getResponseBodyAsStream(), "utf-8");
  }
  finally {
    method.releaseConnection();
  }
  LOG.debug(entityContent);
  //return new InputStreamReader(method.getResponseBodyAsStream(), "utf-8");
  return entityContent;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:22,代码来源:TrelloRepository.java

示例9: build

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
@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;
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:25,代码来源:RoutingRemoteFileStorage.java

示例10: createEntityRepositoryContent

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
@Nullable
public static String createEntityRepositoryContent(Map<String, String> templateVars) {
    String content;

    try {
        content = StreamUtil.readText(CreateEntityRepositoryIntentionAction.class.getResourceAsStream("template/EntityRepository.php"), "UTF-8");
    } catch (IOException e) {
        return null;
    }

    for(Map.Entry<String, String> templateVar: templateVars.entrySet()) {
        content = content.replace("{{" + templateVar.getKey() +"}}", templateVar.getValue());
    }

    return content;
}
 
开发者ID:Haehnchen,项目名称:idea-php-annotation-plugin,代码行数:17,代码来源:CreateEntityRepositoryIntentionAction.java

示例11: runManagerCommand

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
private static boolean runManagerCommand(final String managerUrl) {
  try {
    URL url = new URL(managerUrl);
    long time = System.currentTimeMillis();
    while (System.currentTimeMillis() - time < TIMEOUT) {
      LOG.debug("Running server command: " + managerUrl);
      URLConnection urlConnection = url.openConnection();
      urlConnection.setDoInput(true);
      urlConnection.setDoOutput(false);
      String encoded = Base64.getEncoder().encodeToString(AUTHORIZATION_STRING.getBytes(StandardCharsets.UTF_8));
      urlConnection.setRequestProperty(AUTHORIZATION_PROPERTY, BASIC_AUTHORIZATION_METHOD + encoded);
      urlConnection.connect();
      String msg = StreamUtil.readText(urlConnection.getInputStream());
      LOG.debug("Server returned: " + msg);
      if (msg != null) {
        return !msg.startsWith(FAIL_MESSAGE_PREFIX);
      }
    }
    return false;
  } catch (IOException e) {
    LOG.debug(e);
    return false;
  }
}
 
开发者ID:consulo,项目名称:consulo-javaee,代码行数:25,代码来源:Tomcat4Deployer.java

示例12: getResponseContentAsString

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
public static String getResponseContentAsString(@NotNull HttpMethod response) throws IOException
{
	// Sometimes servers don't specify encoding and HttpMethod#getResponseBodyAsString
	// by default decodes from Latin-1, so we got to read byte stream and decode it from UTF-8
	// manually
	//if (!response.hasBeenUsed()) {
	//  return "";
	//}
	org.apache.commons.httpclient.Header header = response.getResponseHeader(HTTP.CONTENT_TYPE);
	if(header != null && header.getValue().contains("charset"))
	{
		// ISO-8859-1 if charset wasn't specified in response
		return StringUtil.notNullize(response.getResponseBodyAsString());
	}
	else
	{
		InputStream stream = response.getResponseBodyAsStream();
		return stream == null ? "" : StreamUtil.readText(stream, DEFAULT_CHARSET);
	}
}
 
开发者ID:consulo,项目名称:consulo-tasks,代码行数:21,代码来源:TaskResponseUtil.java

示例13: loadSample

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
private String loadSample(String name) {
  try {
    return StreamUtil
        .readText(getClass().getClassLoader().getResourceAsStream("codeSamples/" + name + ".soy"),
            "UTF-8");
  } catch (IOException e) {
    return "";
  }
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:10,代码来源:SoyLanguageCodeStyleSettingsProvider.java

示例14: getAvailableArtifactVersions

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
public static Map<Version, String> getAvailableArtifactVersions(String groupId, String artifactId, Collection<URL> repositories) throws IOException {
    Map<Version, String> availableVersions = new TreeMap<>(Version.descendingOrderComparator());

    final String relativePathToArtifact = groupId.replace(".", "/") + "/" + artifactId.replace(".", "/");

    String artifactLocation;
    for (final URL repository : repositories) {
        artifactLocation = repository.toExternalForm() + "/" + relativePathToArtifact;

        HttpURLConnection artifactRootConnection = HttpConfigurable.getInstance().openHttpConnection(artifactLocation);
        String artifactRootPage = StreamUtil.readText(artifactRootConnection.getInputStream(), StandardCharsets.UTF_8);

        Matcher artifactVersionMatcher = ARTIFACT_ROOT_VERSION_PATTERN.matcher(artifactRootPage);

        while (artifactVersionMatcher.find()) {
            String matchedVersion = artifactVersionMatcher.group(1);

            Version parsedVersion = Version.parseString(matchedVersion);

            if (parsedVersion != Version.INVALID) {
                String versionUrl = repository.toExternalForm() + "/" + relativePathToArtifact + "/" + parsedVersion.toString();
                availableVersions.put(parsedVersion, versionUrl);
            }
        }

        artifactRootConnection.disconnect();

        if (! availableVersions.isEmpty()) {
            break;
        }
    }

    return availableVersions;
}
 
开发者ID:mistodev,项目名称:processing-idea,代码行数:35,代码来源:DependencyUtils.java

示例15: getText

import com.intellij.openapi.util.io.StreamUtil; //导入方法依赖的package包/类
/**
 * Get direct from file because IDEA cache files(see #IDEA-81067)
 */
public static String getText(VirtualFile file) throws IOException {
  FileInputStream inputStream = new FileInputStream(file.getPath());
  try {
    return StreamUtil.readText(inputStream);
  }
  finally {
    inputStream.close();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:ApplicationStarterBase.java


注:本文中的com.intellij.openapi.util.io.StreamUtil.readText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。