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.arvatosystems.us.yaas.api.generated.DefaultObjectidResourceTest.java

@Test
public void testGet() throws IOException {
    final WebTarget target = getRootTarget(ROOT_RESOURCE_PATH).path("");

    final Response response = target.request().get();

    Assert.assertNotNull("Response must not be null", response);
    Assert.assertTrue("Response should have a body", response.hasEntity());

    String body = IOUtils.toString((InputStream) response.getEntity());

    Assert.assertEquals(39, body.length());

    Assert.assertEquals("Response does not have expected response code", Status.OK.getStatusCode(),
            response.getStatus());//  ww  w .  ja  va 2 s . c  o m
}

From source file:ca.gobits.bnf.parser.PropertyParser.java

/**
 * @param is -/*from www.j a v a 2 s  . co m*/
 * @return Map<String, String>
 * @throws IOException -
 */
public Map<String, String> parse(final InputStream is) throws IOException {
    String str = IOUtils.toString(is);
    return parse(str);
}

From source file:com.temenos.useragent.generic.mediatype.AtomFeedHandlerTest.java

@Test
public void testIsCollectionForTrue() throws Exception {
    transformer.setPayload(/*from  w w w. j av  a2  s .c om*/
            IOUtils.toString(AtomPayloadHandler.class.getResourceAsStream("/atom_feed_with_single_entry.txt")));
    assertTrue(transformer.isCollection());
}

From source file:com.esminis.server.library.model.manager.ProductLicenseManager.java

public ProductLicense[] getLicenses() {
    if (licenses == null) {
        final List<ProductLicense> licenses = new ArrayList<>();
        try {//w  ww .j av  a  2 s  . c  o  m
            JSONObject json = new JSONObject(
                    IOUtils.toString(context.getAssets().open("licenses/licenses.json")));
            Iterator<String> keys = json.keys();
            while (keys.hasNext()) {
                final String file = keys.next();
                final JSONObject licenseData = json.getJSONObject(file);
                final JSONArray items = licenseData.getJSONArray("items");
                for (int i = 0; i < items.length(); i++) {
                    licenses.add(new ProductLicense(items.getString(i), licenseData.getString("title"), file));
                }
            }
        } catch (IOException | JSONException ignored) {
        }
        this.licenses = licenses.toArray(new ProductLicense[licenses.size()]);
    }
    return licenses;
}

From source file:com.hortonworks.registries.schemaregistry.streams.StreamsSchemaProviderTest.java

@Test
public void testStreamsSchema() throws Exception {
    StreamsSchemaProvider streamsSchemaProvider = new StreamsSchemaProvider();
    try (InputStream trucksSchemaStream = StreamsSchemaProviderTest.class
            .getResourceAsStream("/streams/trucks.stsc");) {
        List<SchemaFieldInfo> schemaFieldInfos = streamsSchemaProvider
                .generateFields(IOUtils.toString(trucksSchemaStream));
        LOG.info("schemaFieldInfos = " + schemaFieldInfos);
        Assert.assertEquals(11, schemaFieldInfos.size());
    }/* ww  w.jav  a2  s . c  o m*/
}

From source file:io.wcm.tooling.netbeans.sightly.completion.BaseTest.java

public String getTestDocumentContent(String filename) throws IOException {
    return IOUtils.toString(getClass().getResourceAsStream("/" + filename));
}

From source file:com.autonomy.aci.client.transport.impl.EncryptedTextContentProcessorTest.java

@Test
public void testProcess() throws XMLStreamException, IOException {
    final ByteArrayInputStream byteArrayInputStream = new EncryptedTextContentProcessor(
            new TestEncryptionCodec(), "UTF-8")
                    .process(XmlTestUtils.getResourceAsXMLStreamReader(
                            "/com/autonomy/aci/client/transport/impl/EncryptedResponse.xml"));

    assertThat(IOUtils.toString(byteArrayInputStream), is(equalTo(IOUtils.toString(getClass()
            .getResourceAsStream("/com/autonomy/aci/client/transport/impl/UnencryptedResponse.xml")))));
}

From source file:com.photon.phresco.eshop.rest.ConfigResource.java

@GET
@Produces(MediaType.APPLICATION_JSON)//from   w w  w  .  j  a v  a  2 s . com
public String getConfig(@HeaderParam("user-agent") String userAgent, @QueryParam("callback") String callback) {
    String jsonString = "";
    try {
        InputStream is = this.getClass().getClassLoader().getResourceAsStream("json/app-config.json");
        jsonString = IOUtils.toString(is);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return Utility.getJSONP(callback, jsonString);
}

From source file:com.cazcade.billabong.store.impl.MapBasedBinaryStoreTest.java

@Test
public void testMapBasedBinaryStore() throws IOException {
    BinaryStore store = new MapBasedBinaryStore();

    InputStream storeEntry = IOUtils.toInputStream("TESTY");
    Assert.assertTrue(store.placeInStore(STORE_KEY, storeEntry, false));
    storeEntry = IOUtils.toInputStream("TESTY2");
    Assert.assertTrue(store.placeInStore(STORE_KEY2, storeEntry, true));

    Assert.assertEquals("TESTY", IOUtils.toString(store.retrieveFromStore(STORE_KEY).getContent()));

    storeEntry = IOUtils.toInputStream("TESTY3");
    Assert.assertFalse(store.placeInStore(STORE_KEY, storeEntry, false));
    Assert.assertEquals("TESTY", IOUtils.toString(store.retrieveFromStore(STORE_KEY).getContent()));
    Assert.assertTrue(store.placeInStore(STORE_KEY, storeEntry, true));
    Assert.assertEquals("TESTY2", IOUtils.toString(store.retrieveFromStore(STORE_KEY2).getContent()));
    Assert.assertEquals("TESTY3", IOUtils.toString(store.retrieveFromStore(STORE_KEY).getContent()));

}

From source file:com.ning.billing.invoice.dao.InvoiceDaoTestBase.java

@BeforeClass()
protected void setup() throws IOException {
    // Health check test to make sure MySQL is setup properly
    try {// w w w.j  av  a 2  s.  c  o  m
        InvoiceModuleMock module = new InvoiceModuleMock();
        final String ddl = IOUtils
                .toString(DefaultInvoiceDao.class.getResourceAsStream("/com/ning/billing/invoice/ddl.sql"));
        module.createDb(ddl);

        final Injector injector = Guice.createInjector(Stage.DEVELOPMENT, module);

        invoiceDao = injector.getInstance(InvoiceDao.class);
        invoiceDao.test();

        invoiceItemDao = module.getInvoiceItemDao();

        EventBusService busService = injector.getInstance(EventBusService.class);
        ((DefaultEventBusService) busService).startBus();
    } catch (Throwable t) {
        fail(t.toString());
    }
}