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:eu.scapeproject.fcrepo.integration.XmlDeclarationStrippingInputstreamTest.java

@Test
public void testStripXmlDeclaration1() throws Exception {
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><srw:searchRetrieveResponse xmlns:srw=\"http://scapeproject.eu/srw/\"><srw:numberOfRecords>0</srw:numberOfRecords><srw:records></srw:records></srw:searchRetrieveResponse>";
    XmlDeclarationStrippingInputstream src = new XmlDeclarationStrippingInputstream(
            new ByteArrayInputStream(xml.getBytes()));
    String stripped = IOUtils.toString(src);
    assertEquals(-1, stripped.indexOf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"));
    assertEquals(/*w w  w  .  j av  a2  s.c  om*/
            "<srw:searchRetrieveResponse xmlns:srw=\"http://scapeproject.eu/srw/\"><srw:numberOfRecords>0</srw:numberOfRecords><srw:records></srw:records></srw:searchRetrieveResponse>",
            stripped);
}

From source file:com.smartitengineering.event.hub.core.ContentHelper.java

private void convert() {
    if (content != null && StringUtils.isBlank(contentAsString)) {
        try {/*from  w  w w  .  j av a 2s.c om*/
            contentAsString = IOUtils.toString(content.getContent());
        } catch (Exception ex) {
        }
    }
}

From source file:com.indoqa.maven.wadldoc.transformation.Wadl2HtmlPipelineTest.java

private static Diff createDiff(URL expected, ByteArrayOutputStream actual) throws Exception {
    String string1 = IOUtils.toString(expected.openStream());
    String string2 = actual.toString();

    return new Diff(string1, string2);
}

From source file:com.opencarte.db.Parser.java

public Parser(String fileName) {

    try {/*w ww .j a  v a  2 s  . c  o m*/
        this.fileContent = IOUtils.toString(new URL(fileName).openStream());
        builder = new GsonBuilder();
    } catch (IOException ex) {
        System.out.println(ex);
        //Logger.getLogger(Parser.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:cn.lambdalib.util.client.shader.ShaderProgram.java

public void linkShader(ResourceLocation location, int type) {
    if (!checkCapability())
        return;/*from  w ww. j av  a2s . c  o  m*/

    try {
        boolean loaded;
        String str = IOUtils.toString(RegistryUtils.getResourceStream(location));
        int shaderID = glCreateShader(type);
        glShaderSource(shaderID, str);
        glCompileShader(shaderID);

        int successful = glGetShaderi(shaderID, GL_COMPILE_STATUS);
        if (successful == GL_FALSE) {
            String log = glGetShaderInfoLog(shaderID, glGetShaderi(shaderID, GL_INFO_LOG_LENGTH));
            LambdaLib.log.error("Error when linking shader '" + location + "'. code: " + successful
                    + ", Error string: \n" + log);
            loaded = false;
        } else {
            loaded = true;
        }

        if (loaded) {
            attachedShaders.add(shaderID);
            glAttachShader(programID, shaderID);
        }
    } catch (IOException e) {
        LambdaLib.log.error("Didn't find shader " + location, e);
        Throwables.propagate(e);
    }
}

From source file:io.cloudslang.lang.cli.SlangBanner.java

@Override
public String getBanner() {
    StringBuilder sb = new StringBuilder();
    try (InputStream in = ClassLoader.getSystemResourceAsStream(BANNER)) {
        sb.append(IOUtils.toString(in));
    } catch (IOException e) {
        sb.append("CloudSlang");
    }/*w  w  w. ja v  a2s  .c o m*/
    sb.append(System.lineSeparator());
    sb.append(getVersion());
    return sb.toString();
}

From source file:com.google.mr4c.content.AbstractContentFactory.java

public String readContentAsString(URI uri) throws IOException {
    Reader reader = readContentAsReader(uri);
    try {/*w w  w .  ja  v  a 2 s . c o  m*/
        return IOUtils.toString(reader);
    } finally {
        reader.close();
    }
}

From source file:net.hamnaberg.rest.URIListHandler.java

public List<URI> handle(Payload payload) {
    List<URI> uris = new ArrayList<URI>();
    InputStream stream = payload.getInputStream();
    try {/*w  w w.j a v  a2s . co m*/
        String value = IOUtils.toString(stream);
        String[] list = value.split("\r\n");
        for (String uri : list) {
            if (uri.charAt(0) == '#') {
                continue;
            }
            uris.add(URI.create(uri));
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(stream);
    }
    return uris;
}

From source file:com.seleritycorp.common.base.http.client.HttpResponseStreamTest.java

@Test
public void testGetBodyAsciiChars() throws Exception {
    HttpResponseStream response = createHttpResponseStream(200, "bodyFoo");
    String actual = IOUtils.toString(response.getBodyAsStream());

    assertThat(actual).isEqualTo("bodyFoo");
}

From source file:br.com.danielferber.ilogtoys.modelo.ProvedorModeloURL.java

@Override
public String getConteudo() throws IOException {
    InputStream is = url.openStream();
    Invariant.notNull(is);/*from w  ww.jav  a 2  s . c  om*/

    try {
        String s = IOUtils.toString(is);
        return s;
    } finally {
        is.close();
    }
}