org.apache.logging.log4j.core.util.IOUtils#toString ( )源码实例Demo

下面列出了org.apache.logging.log4j.core.util.IOUtils#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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);
  }
}
 
源代码2 项目: hmftools   文件: CircosConfigWriter.java
@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);
}
 
源代码3 项目: hmftools   文件: ChromosomeRangeExecution.java
@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);
}
 
private String getStringContent(URL resource) throws IOException {
    try (InputStream resourceAsStream = resource.openStream()) {
        InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8);
        return IOUtils.toString(inputStreamReader);
    }
}
 
源代码5 项目: hmftools   文件: CircosCharts.java
@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);
}
 
源代码6 项目: logging-log4j2   文件: ScriptFile.java
@PluginFactory
public static ScriptFile createScript(
        // @formatter:off
        @PluginAttribute String name,
        @PluginAttribute String language,
        @PluginAttribute("path") final String filePathOrUri,
        @PluginAttribute final Boolean isWatched,
        @PluginAttribute 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);
}
 
 同类方法