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, String encoding) throws IOException 

Source Link

Document

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

Usage

From source file:com.netsteadfast.greenstep.util.Pivot4JUtils.java

public static String getHtmlCss() throws Exception {
    if (!StringUtils.isBlank(_htmlCss)) {
        return _htmlCss;
    }//from w ww .  j av  a2s .  c  o  m
    InputStream is = Pivot4JUtils.class.getClassLoader().getResource(PIVOT4J_HTML_CSS).openStream();
    _htmlCss = IOUtils.toString(is, Constants.BASE_ENCODING);
    is.close();
    is = null;
    return _htmlCss;
}

From source file:de.shadowhunt.subversion.internal.ResourcePropertyUtilsTest.java

@Test
public void testEscapedInputStream_emptyTag() throws Exception {
    final String xml = "<C:foo:bar/>";
    final String expected = "<C:foo" + MARKER + "bar/>";
    final InputStream stream = IOUtils.toInputStream(xml, ResourcePropertyUtils.UTF8);

    final InputStream escapedStream = ResourcePropertyUtils.escapedInputStream(stream);
    final String escapedXml = IOUtils.toString(escapedStream, ResourcePropertyUtils.UTF8);

    Assert.assertEquals(expected, escapedXml);
}

From source file:com.edp.admin.rest.StencilsetRestResource.java

@RequestMapping(value = "xxx/editor/stencilset", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public @ResponseBody String getStencilset() {
    InputStream stencilsetStream = this.getClass().getClassLoader().getResourceAsStream("stencilset.json");
    try {//from  w  ww  .ja  va  2s .  c o m
        return IOUtils.toString(stencilsetStream, "utf-8");
    } catch (Exception e) {
        throw new ActivitiException("Error while loading stencil set", e);
    }
}

From source file:com.admin.bpm.rest.editor.main.StencilsetRestResource.java

@RequestMapping(value = "/editor/stencilset", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public @ResponseBody String getStencilset() {
    InputStream stencilsetStream = this.getClass().getClassLoader().getResourceAsStream("stencilset.json");
    try {// ww w.j a va2 s  .com
        return IOUtils.toString(stencilsetStream, "utf-8");
    } catch (Exception e) {
        throw new ActivitiException("Error while loading stencil set", e);
    }
}

From source file:com.haulmont.cuba.gui.xml.layout.LayoutLoader.java

public static Document parseDescriptor(InputStream stream) {
    checkNotNullArgument(stream, "Input stream is null");

    String template;//ww w.j  a v  a  2  s  .  co  m
    try {
        template = IOUtils.toString(stream, StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

    return parseDescriptor(template);
}

From source file:com.ms.commons.test.classloader.util.AntxconfigUtil.java

private static void writeUrlToFile(URL url, File file) throws Exception {
    InputStream in = url.openStream();
    String str = IOUtils.toString(in, ENDODING);
    str = str.replaceAll("description=\".*\"", "description=\"\"");
    IOUtils.closeQuietly(in);/*from   w w w  .j  ava 2  s  .c  om*/
    FileUtils.writeStringToFile(file, str, ENDODING);
}

From source file:cn.advu.workflow.web.common.workflow.StencilsetRestResource.java

@RequestMapping(value = "/service/editor/stencilset", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public @ResponseBody String getStencilset() {
    InputStream stencilsetStream = this.getClass().getClassLoader().getResourceAsStream("stencilset.json");
    try {//from  w ww .  j  a  v  a2 s .  co  m
        return IOUtils.toString(stencilsetStream, "utf-8");
    } catch (Exception e) {
        throw new ActivitiException("Error while loading stencil set", e);
    }
}

From source file:capital.scalable.restdocs.jsondoclet.ExtractDocumentationAsJsonDocletTest.java

/**
 * The test requires that the Doclet is executed before. This is ensured by
 * the Maven configuration, but not when the test is executed on its own.
 *//* ww  w .  j  ava  2  s . c om*/
@Test
public void testDocumentedClass() throws IOException, JSONException {
    String generated = IOUtils
            .toString(new FileInputStream(new File("target/generated-javadoc-json/" + JSON_PATH)), UTF_8);
    String expected = IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream(JSON_PATH), UTF_8);
    JSONAssert.assertEquals(expected, generated, false);
}

From source file:edu.ucuenca.authorsdisambiguation.nwd.Cache.java

private Cache() {
    InputStream resourceAsStream = this.getClass().getResourceAsStream("/config.cnf");
    String theString = null;//w ww.j  a va 2  s . co m
    try {
        theString = IOUtils.toString(resourceAsStream, Charset.defaultCharset().toString());
    } catch (IOException ex) {
        Logger.getLogger(Cache.class.getName()).log(Level.SEVERE, null, ex);
    }
    config = JSON.parse(theString).getAsObject();
    db = DBMaker.fileDB(config.get("CacheFile").getAsString().value()).make();
    create = db.hashMap("cache", Serializer.STRING, new SerializerCompressionWrapper(Serializer.STRING))
            .expireAfterCreate(30, TimeUnit.DAYS).createOrOpen();

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        public void run() {
            try {
                System.out.println("Killing ");
                Kill();
            } catch (SQLException ex) {
                Logger.getLogger(Cache.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }));
}

From source file:com.msopentech.odatajclient.testauthproxy.staticmetadata.StaticMetadataServlet.java

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {

    resp.setContentType("application/xml;charset=UTF-8");
    resp.getWriter().write(IOUtils.toString(getClass().getResourceAsStream("/static-metadata.xml"), "UTF-8"));
}