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.berico.clavin.util.TextUtils.java

/**
 * Wrapper for calling Apache Commons IO toString(BufferedReader)
 * on a File, essentially providing a File.toString() method for
 * the contents of a text file./*from  www  . j  av  a2 s  . c om*/
 * 
 * @param file         File to be string-ified
 * @return            String representing contents of file
 * @throws IOException
 */
public static String fileToString(File file) throws IOException {
    return IOUtils.toString(new BufferedReader(new FileReader(file)));
}

From source file:io.servicecomb.swagger.SwaggerUtils.java

public static Swagger parseSwagger(URL url) {
    try {/*from   w  w  w  .j a va2s.co m*/
        String swaggerContent = IOUtils.toString(url);
        return internalParseSwagger(swaggerContent);
    } catch (Throwable e) {
        throw new ServiceCombException("Parse swagger from url failed, ", e);
    }
}

From source file:com.htmlhifive.tools.codeassist.core.proposal.wrapper.ProposalWrapperUtils.java

/**
 * ?CSS??./*from w  w  w.  j a va2 s .c  o  m*/
 * 
 * @return CSS.
 */
public static String getCSSStyles() {

    Bundle bundle = Platform.getBundle(JavaScriptPlugin.getPluginId());
    URL url = bundle.getEntry("/JavadocHoverStyleSheet.css"); //$NON-NLS-1$
    if (url != null) {
        BufferedReader reader = null;
        try {
            url = FileLocator.toFileURL(url);
            return IOUtils.toString(url.openStream());
        } catch (IOException ex) {
            JavaScriptPlugin.log(ex);
        } finally {
            IOUtils.closeQuietly(reader);
        }
    }
    return null;
}

From source file:lux.functions.XQueryTest.java

protected void assertXQueryFile(String result, String queryFile, String firstError) throws IOException {
    String query = IOUtils.toString(TransformTest.class.getResourceAsStream(queryFile));
    assertXQuery(result, query, firstError);
}

From source file:fi.johannes.kata.ocr.utils.ResourceGetter.java

public static String getContents(String fileName) {
    String result = "";
    Reader r = getReader(fileName);
    try {/*from   w w  w  .j  a v a 2s  .  c om*/
        result = IOUtils.toString(r);
    } catch (IOException e) {
        // TODO Logger
        e.printStackTrace();
    }
    return result;
}

From source file:com.opentangerine.clean.Res.java

/**
 * Load resource under specific path.//from  ww w  .  j  a v a 2 s  . c o  m
 *
 * @param path Resource path.
 * @return Content.
 */
static String resource(final String path) {
    try {
        final InputStream stream = Res.class.getResourceAsStream(path);
        Validate.isTrue(stream != null, "File not found");
        return IOUtils.toString(stream);
    } catch (final IllegalArgumentException | IOException exc) {
        Logger.error(Res.class, "Unable to read '%s'", path);
        throw new IllegalArgumentException(String.format("Unable to read resource: %s", path), exc);
    }
}

From source file:ch.ralscha.extdirectspring.generator.GeneratorTestUtil.java

public static void compareTouch2Code(String model, String value, boolean debug, boolean apiWithQuotes) {
    try {// w w w  .  ja v a2s. c om
        String expectedValue = IOUtils.toString(GeneratorTestUtil.class
                .getResourceAsStream("/generator/" + model + "Touch2" + (apiWithQuotes ? "Q" : "") + ".json"));
        compareModelString(expectedValue, value, debug);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.atlassian.jira.rest.client.internal.json.ResourceUtil.java

public static String getStringFromResource(String resourcePath) {
    final String s;
    try {//www  . j ava  2 s .c  om
        final InputStream is = ResourceUtil.class.getResourceAsStream(resourcePath);
        if (is == null) {
            throw new IOException("Cannot open resource [" + resourcePath + "]");
        }
        s = IOUtils.toString(is);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return s;
}

From source file:com.rhc.dynamic.pipeline.utils.TestUtils.java

public static String getPipelineScriptFromFile(String fileName) throws IOException {
    return IOUtils.toString(TestUtils.class.getClassLoader()
            .getResourceAsStream("com/rhc/dynamic/pipeline/scripts/" + fileName));
}

From source file:com.github.ffremont.microservices.springboot.node.services.PsCommand.java

public PsCommandResult exec() {
    try {//from  ww  w  .  j av  a 2 s  .  c o  m
        Process process = this.ps.start();

        return new PsCommandResult(IOUtils.toString(process.getInputStream()));
    } catch (IOException io) {
        LOG.error("Impossible de lancer la command 'ps'", io);
    }
    return null;
}