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:com.funambol.rhinounit.RhinoUnitLoader.java

/**
 * Returns a script containing the entire RhinoUnit framework.
 * Single RhinoUnit scripts are loaded from the classpath so that the
 * framework can be easily used simply adding the jar in the classpath
 *
 * @return the RhinoUnit framework in a single script
 *
 * @throws IOException if the framework could not be loaded from classpath
 *//* w ww.j a  v a 2  s .  com*/
public static String getRhinoUnit() throws IOException {
    StringBuffer ret = new StringBuffer();

    InputStream is = null;
    for (int i = 0; i < SCRIPTS.length; ++i) {
        try {
            is = RhinoUnitLoader.class.getResourceAsStream(SCRIPTS[i]);
            if (is == null) {
                throw new FileNotFoundException("Resource " + SCRIPTS[i] + " not found in classpath");
            }

            ret.append(IOUtils.toString(is)).append("\n\n");
        } finally {
            if (is != null) {
                is.close();
            }
        }
    }

    return ret.toString();
}

From source file:ch.sbb.releasetrain.action.jenkins.JenkinsActionTest.java

@org.junit.Before
public void setUp() throws Exception {

    String in = IOUtils.toString(getClass().getResourceAsStream("/test-jenkins-action-state.yml"));
    YamlModelAccessor<ActionState> yaml = new YamlModelAccessor<>();
    jenkinsState = yaml.convertEntry(in);
    action = new JenkinsAction();

}

From source file:lux.functions.TransformTest.java

@Test
public void testOutputURIResolution() throws Exception {
    // test a transform that writes a document using result-document
    assertXQueryFile(null, "transform-result-document.xqy",
            "Attempted to write document /doc/1 to a read-only Evaluator");
    RAMDirectory dir = new RAMDirectory();
    Evaluator writable = Evaluator.createEvaluator(dir);
    String query = IOUtils.toString(TransformTest.class.getResourceAsStream("transform-result-document.xqy"));
    writable.evaluate(query);/*from   w  w  w .j  a  va  2 s. co  m*/
    // TODO: make this more convenient.  Have an auto-commit at the end of each evaluation
    // (only when there have been any writes?) and re-open the reader so we can see the results
    // in subsequent queries
    writable.getDocWriter().commit(writable);
    // re-open so that we see the results here
    writable.reopenSearcher();
    XdmResultSet result = writable.evaluate("collection()[1]");
    assertEquals("1", result.getXdmValue().itemAt(0).getStringValue());
    result = writable.evaluate("doc('/doc/1')");
    assertEquals("1", result.getXdmValue().itemAt(0).getStringValue());
}

From source file:com.allogy.io.NoNewEditsInputStreamTest.java

@Test
public void stream_should_return_inner_stream_followed_by_comma_new_edits_false() throws IOException {
    String innerString = "[" + UUID.randomUUID().toString() + "]";
    InputStream innerInputStream = IOUtils.toInputStream(innerString);

    String stringFromObjectUnderTest = IOUtils.toString(new NoNewEditsInputStream(innerInputStream));

    assertThat(stringFromObjectUnderTest, notNullValue());

    assertThat(stringFromObjectUnderTest.startsWith(innerString), is(true));
    String prependedString = stringFromObjectUnderTest.substring(innerString.length());
    assertThat(prependedString, is(", \"new_edits\": false"));
}

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

@Test
public void bodyAppliesItselfToRequest() throws Exception {
    HttpPost request = new HttpPost();
    RequestBody body = new RequestBody("content", "content/type");
    body.applyTo(new ServerDriverHttpUriRequest(request));
    assertThat(IOUtils.toString(request.getEntity().getContent()), is("content"));
    assertThat(request.getEntity().getContentType().getValue(), is("content/type; charset=UTF-8"));
    assertThat(request.getFirstHeader("Content-type").getValue(), is("content/type"));
}

From source file:com.navercorp.volleyextensions.cache.universalimageloader.disc.CountingInputStreamTest.java

@Test
public void bytesReadShouldBeSameAsContentLength() throws IOException {
    // Given/*from   ww w. j av a  2 s .  com*/
    InputStream is = openFromClassPath("test.txt");
    CountingInputStream cis = new CountingInputStream(is);
    // When
    String content = IOUtils.toString(cis);
    IOUtils.closeQuietly(cis);
    //Then
    assertThat(content, is("Cached Data"));
    assertThat(cis.bytesRead, is(11));
}

From source file:com.netflix.hollow.jsonadapter.chunker.JsonArrayChunkerTest.java

@Test
public void test() throws Exception {
    String jsonArray = "[ { \"f1\\\"\" : \"value1\", \"f2\" : { \"f1.1\" : \"hel}}{{{{lo \\\"w{orld\\\"\" } } , { \"obj2\" : \"f2.1\" } ]";

    JsonArrayChunker chunker = new JsonArrayChunker(new StringReader(jsonArray), new SimultaneousExecutor(), 4);
    chunker.initialize();//from  ww w.  ja v a2  s  .c om

    String obj1 = IOUtils.toString(chunker.nextChunk());
    String obj2 = IOUtils.toString(chunker.nextChunk());

    Assert.assertEquals("{ \"f1\\\"\" : \"value1\", \"f2\" : { \"f1.1\" : \"hel}}{{{{lo \\\"w{orld\\\"\" } }",
            obj1);
    Assert.assertEquals("{ \"obj2\" : \"f2.1\" }", obj2);
}

From source file:mongosensors_client.JsonFile.java

public JsonFile read() throws Exception {
    File f = new File(this.path);
    if (f.exists()) {
        InputStream is = new FileInputStream(this.path);
        String jsonTxt = IOUtils.toString(is);
        super.json = new JSONObject(jsonTxt);
    }/*from  www  .  j  a  va 2  s  .  c o  m*/
    return this;
}

From source file:bboss.org.artofsolving.jodconverter.document.JsonDocumentFormatRegistry.java

public JsonDocumentFormatRegistry(InputStream input) throws JSONException, IOException {
    readJsonArray(IOUtils.toString(input));
}

From source file:com.alibaba.json.test.JSONParser2Test.java

protected void setUp() throws Exception {
    // String resource = "json/Bug_0_Test.json";
    String resource = "json/Bug_0_Test.json";
    InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
    text = IOUtils.toString(is);
    is.close();//  ww  w . j  a  va2  s .  c  o m

    // text =
    // "[{\"S\":321061,\"T\":\"GetAttributeResp\"},{\"ERROR\":null,\"TS\":0,\"VAL\":{\"SqlList\":[{\"BatchSizeMax\":0,\"BatchSizeTotal\":0,\"ConcurrentMax\":1,\"DataSource\":\"jdbc:wrap-jdbc:filters=default,encoding:name=ds-offer:jdbc:mysql://100.10.10.10:8066/xxx\",\"EffectedRowCount\":0,\"ErrorCount\":0,\"ExecuteCount\":5,\"FetchRowCount\":5,\"File\":null,\"ID\":2001,\"LastError\":null,\"LastTime\":1292742908178,\"MaxTimespan\":16,\"MaxTimespanOccurTime\":1292742668191,\"Name\":null,\"RunningCount\":0,\"SQL\":\"SELECT @@SQL_MODE\",\"TotalTime\":83}]}}]";
    // text = "{\"name\":null,\"flag\":true}";
    // text = "-6470204979932713723";
    // text = "[-5.041598256063065E-20,-7210028408342716000]";
    // text = "[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]";
    // text = "{\"S\":321061,\"T\":\"GetAttributeResp\"}";
    // text = "{\"?Z,??\": true,\"?>wj\\\"\\\\_c~M?SN?!?k$|HEK'\": -1377757625945773954}";
}