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


Java IOUtils.toString方法代码示例

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


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

示例1: annotate

import org.apache.logging.log4j.core.util.IOUtils; //导入方法依赖的package包/类
public String annotate(String text) throws URISyntaxException, IOException {
    URI requestURI = new URIBuilder(endpoint).build();
    HttpPost request = new HttpPost(requestURI);

    List<NameValuePair> urlParameters = new ArrayList<>();
    urlParameters.add(new BasicNameValuePair("text", text));
    urlParameters.add(new BasicNameValuePair("disambiguation", "1"));
    urlParameters.add(new BasicNameValuePair("topic", "0.25"));
    urlParameters.add(new BasicNameValuePair("include_text", "1"));
    urlParameters.add(new BasicNameValuePair("min_weight", "0.25"));
    urlParameters.add(new BasicNameValuePair("image", "1"));
    urlParameters.add(new BasicNameValuePair("class", "1"));
    urlParameters.add(new BasicNameValuePair("app_id", "0"));
    urlParameters.add(new BasicNameValuePair("app_key", "0"));

    request.setEntity(new UrlEncodedFormEntity(urlParameters));
    CloseableHttpResponse response = client.execute(request);
    if (response.getStatusLine().getStatusCode() >= 400) {
        response.close();
        throw new IOException("Wikimachine endpoint didn't understand the request");
    }
    String responseText = IOUtils.toString(new InputStreamReader(response.getEntity().getContent()));
    response.close();

    return responseText;
}
 
开发者ID:Remper,项目名称:sociallink,代码行数:27,代码来源:WikimachineService.java

示例2: on

import org.apache.logging.log4j.core.util.IOUtils; //导入方法依赖的package包/类
private SagaResponse on(Request request) {
  try {
    HttpResponse httpResponse = request.execute().returnResponse();
    int statusCode = httpResponse.getStatusLine().getStatusCode();
    String content = IOUtils.toString(new InputStreamReader(httpResponse.getEntity().getContent()));
    if (statusCode >= 200 && statusCode < 300) {
      return new SuccessfulSagaResponse(content);
    }
    throw new TransportFailedException("The remote service returned with status code " + statusCode
        + ", reason " + httpResponse.getStatusLine().getReasonPhrase()
        + ", and content " + content);
  } catch (IOException e) {
    throw new TransportFailedException("Network Error", e);
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:16,代码来源:HttpClientTransport.java

示例3: getStringContent

import org.apache.logging.log4j.core.util.IOUtils; //导入方法依赖的package包/类
private String getStringContent(URL resource) throws IOException {
    try (InputStream resourceAsStream = resource.openStream()) {
        InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream, "UTF-8");
        return IOUtils.toString(inputStreamReader);
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:7,代码来源:MCRServletContextResourceImporter.java

示例4: readResource

import org.apache.logging.log4j.core.util.IOUtils; //导入方法依赖的package包/类
@NotNull
private String readResource(@NotNull final String resource) throws IOException {
    InputStream in = getClass().getResourceAsStream(resource);
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    return IOUtils.toString(reader);
}
 
开发者ID:hartwigmedical,项目名称:hmftools,代码行数:7,代码来源:GenerateCircosData.java

示例5: readResource

import org.apache.logging.log4j.core.util.IOUtils; //导入方法依赖的package包/类
@NotNull
private String readResource() throws IOException {
    InputStream in = VersionInfo.class.getClassLoader().getResourceAsStream(resource);
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    return IOUtils.toString(reader);
}
 
开发者ID:hartwigmedical,项目名称:hmftools,代码行数:7,代码来源:VersionInfo.java

示例6: createScript

import org.apache.logging.log4j.core.util.IOUtils; //导入方法依赖的package包/类
@PluginFactory
public static ScriptFile createScript(
        // @formatter:off
        @PluginAttribute("name") String name,
        @PluginAttribute("language") String language,
        @PluginAttribute("path") final String filePathOrUri,
        @PluginAttribute("isWatched") final Boolean isWatched,
        @PluginAttribute("charset") final Charset charset) {
        // @formatter:on
    if (filePathOrUri == null) {
        LOGGER.error("No script path provided for ScriptFile");
        return null;
    }
    if (name == null) {
        name = filePathOrUri;
    }
    final URI uri = NetUtils.toURI(filePathOrUri);
    final File file = FileUtils.fileFromUri(uri);
    if (language == null && file != null) {
        final String fileExtension = FileUtils.getFileExtension(file);
        if (fileExtension != null) {
            final ExtensionLanguageMapping mapping = ExtensionLanguageMapping.getByExtension(fileExtension);
            if (mapping != null) {
                language = mapping.getLanguage();
            }
        }
    }
    if (language == null) {
        LOGGER.info("No script language supplied, defaulting to {}", DEFAULT_LANGUAGE);
        language = DEFAULT_LANGUAGE;
    }

    final Charset actualCharset = charset == null ? Charset.defaultCharset() : charset;
    String scriptText;
    try (final Reader reader = new InputStreamReader(
            file != null ? new FileInputStream(file) : uri.toURL().openStream(), actualCharset)) {
        scriptText = IOUtils.toString(reader);
    } catch (final IOException e) {
        LOGGER.error("{}: language={}, path={}, actualCharset={}", e.getClass().getSimpleName(),
                language, filePathOrUri, actualCharset);
        return null;
    }
    final Path path = file != null ? Paths.get(file.toURI()) : Paths.get(uri);
    if (path == null) {
        LOGGER.error("Unable to convert {} to a Path", uri.toString());
        return null;
    }
    return new ScriptFile(name, path, language, isWatched == null ? Boolean.FALSE : isWatched, scriptText);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:50,代码来源:ScriptFile.java


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