Java Code Examples for org.apache.logging.log4j.core.util.IOUtils#toString()

The following examples show how to use org.apache.logging.log4j.core.util.IOUtils#toString() . 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: HttpClientTransport.java    From servicecomb-saga-actuator with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 2
Source File: CircosConfigWriter.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 3
Source File: ChromosomeRangeExecution.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 4
Source File: MCRServletContextResourceImporter.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
private String getStringContent(URL resource) throws IOException {
    try (InputStream resourceAsStream = resource.openStream()) {
        InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8);
        return IOUtils.toString(inputStreamReader);
    }
}
 
Example 5
Source File: CircosCharts.java    From hmftools with GNU General Public License v3.0 4 votes vote down vote up
@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);
}
 
Example 6
Source File: ScriptFile.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@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);
}