Example usage for org.apache.commons.io IOUtils toString

List of usage examples for org.apache.commons.io IOUtils toString

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils toString.

Prototype

public static String toString(byte[] input) throws IOException 

Source Link

Document

Get the contents of a byte[] as a String using the default character encoding of the platform.

Usage

From source file:io.helixservice.feature.configuration.locator.AbstractResourceLocator.java

/**
 * {@inheritDoc}/* w w  w.ja v  a  2  s.  com*/
 */
@Override
public Optional<String> getString(String resourcePath) {
    Optional<String> result = Optional.empty();

    try {
        InputStream in = getStream(resourcePath).get();
        result = Optional.of(IOUtils.toString(in));
    } catch (Throwable t) {
        // Possibly expected
    }

    return result;
}

From source file:PluginDescriptorValidityTest.java

/**
 * Tests that the summary template location tag (which is a little long) was not line-wrapped. Sometimes the
 * auto-formatting wraps the line and breaks the descriptor.
 *//* w  w w .  j a v  a 2  s .c o m*/
public void testSummaryTemplateLocationIsNotWrapped() throws IOException {
    InputStream pluginDescriptorStream = getClass().getResourceAsStream("atlassian-plugin.xml");
    String pluginDescriptorContent = IOUtils.toString(pluginDescriptorStream);
    Assert.assertTrue(
            pluginDescriptorContent.contains("<result name=\"input\" type=\"freemarker\">/"
                    + "templates/plugins/result/buildInfoAction.ftl</result>"),
            "Could not find expected summary template declaration. Was the line wrapped again?");
}

From source file:fcl.rest.UploadResource.java

@POST
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@Path("detailedFile")
public String uploadFileDetails(@BeanParam UploadDetails details) throws IOException {
    return details.formParameters.toString() + IOUtils.toString(details.data);
}

From source file:edu.toronto.cs.xml2rdf.freebase.FreebaseUtil.java

public static JSONArray search(String query, String mql_query_file, int limit) {
    try {//  w ww. j ava2  s  .c om
        properties.load(new FileInputStream(FREEBASE_PROPERTIES_LOC));
        HttpTransport httpTransport = new NetHttpTransport();
        HttpRequestFactory requestFactory = httpTransport.createRequestFactory();

        GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/search");
        url.put("query", query);
        //            url.put("filter", "(all type:/music/artist created:\"The Lady Killer\")");
        url.put("limit", limit);
        String mql_query = IOUtils.toString(new FileInputStream(mql_query_file));

        url.put("mql_output", mql_query);
        url.put("key", properties.get("API_KEY"));
        HttpRequest request = requestFactory.buildGetRequest(url);
        HttpResponse httpResponse = null;
        try {
            httpResponse = request.execute();
        } catch (Exception e) {

        }
        if (httpResponse == null) {
            return null;
        }
        JSON obj = JSONSerializer.toJSON(httpResponse.parseAsString());
        if (obj.isEmpty()) {
            return null;
        }
        JSONObject jsonObject = (JSONObject) obj;
        JSONArray results = jsonObject.getJSONArray("result");
        LogUtils.info(FreebaseUtil.class, results.toString());
        return results;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:com.anrisoftware.simplerest.owncloudocs.NopParseResponse.java

@Override
public Message parse(HttpResponse response) throws IOException {
    HttpEntity entity = response.getEntity();
    String content = IOUtils.toString(entity.getContent());
    System.out.println(content);// TODO
                                // println
    return null;//w w  w.  j  a  v  a2 s .com
}

From source file:com.opengamma.util.db.script.ClasspathDbScript.java

@Override
public String getScript() throws IOException {
    return IOUtils.toString(_scriptResource);
}

From source file:com.github.restdriver.serverdriver.http.ByteArrayRequestBodyTest.java

@Test
public void bodyAppliesItselfToRequest() throws Exception {
    byte[] bytes = "MY STRING OF DOOM!".getBytes();
    HttpPost request = new HttpPost();
    ByteArrayRequestBody body = new ByteArrayRequestBody(bytes, "contentType");
    body.applyTo(new ServerDriverHttpUriRequest(request));
    assertThat(IOUtils.toString(request.getEntity().getContent()), is("MY STRING OF DOOM!"));
    assertThat(request.getEntity().getContentType().getValue(), is("contentType"));
    assertThat(request.getFirstHeader("Content-type").getValue(), is("contentType"));
}

From source file:com.github.born2snipe.project.setup.scm.GitRepoInitializer.java

private void executeCommandIn(File projectDir, String... commands) {
    try {/*  www .j  av  a 2  s. c o m*/
        ProcessBuilder processBuilder = new ProcessBuilder(commands);
        processBuilder.directory(projectDir);
        processBuilder.redirectErrorStream(true);
        Process process = processBuilder.start();
        System.out.println(IOUtils.toString(process.getInputStream()));
        process.waitFor();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:nbxml.Base.java

public void validate(String resource) throws Exception {
    ContentHandlerVerifier handlerVerifier = new ContentHandlerVerifier();

    parseXml(resource, handlerVerifier);

    handlerVerifier.reset();/*from   w  w w  . ja v a2 s.c  o m*/

    Parser parser = new Parser(handlerVerifier);
    parser.parse(IOUtils.toString(getResourceAsStream(resource)));
    parser.close();

    handlerVerifier.done();
}

From source file:com.hazelcast.qasonar.utils.WhiteListBuilder.java

private static JsonArray getJsonArrayFromUrl(String propertyFileName) {
    InputStream inputStream = null;
    try {//from w  ww. j a v a 2 s  . c o m
        inputStream = new URL(propertyFileName).openStream();
        String json = IOUtils.toString(inputStream);

        Gson gson = new Gson();
        return gson.fromJson(json, JsonArray.class);
    } catch (IOException e) {
        throw new IllegalArgumentException("Could not read whitelist from url " + propertyFileName,
                e.getCause());
    } finally {
        closeQuietly(inputStream);
    }
}