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.hp.ov.sdk.adaptors.StoragePoolSerializationAdapterTest.java

@BeforeClass
public static void setupTest() throws IOException {
    Class<StoragePoolSerializationAdapterTest> clazz = StoragePoolSerializationAdapterTest.class;

    storagePoolJson = IOUtils.toString(clazz.getResourceAsStream("StoragePool.json"), "UTF-8");
    storagePoolV2Json = IOUtils.toString(clazz.getResourceAsStream("StoragePoolV2.json"), "UTF-8");
}

From source file:com.loop81.fxcomparer.AboutDialog.java

protected AboutDialog() {
    super(DIALOG_WIDTH, DIALOG_HEIGHT);

    try {/*w  ww .  ja v  a2  s.  c o  m*/
        String aboutText = IOUtils.toString(getClass().getResourceAsStream("/about.txt"), "UTF-8");
        aboutText += IOUtils.toString(getClass().getResourceAsStream("/license.txt"), "UTF-8");
        ((TextArea) dialogStage.getScene().lookup(".text-area")).setText(aboutText);
    } catch (IOException e) {
        // Will never happen since the about.txt and license.txt should always be there.
    }
}

From source file:net.gazeplay.commons.utils.games.Utils.java

private static String loadLicenseFileAsString(ClassLoader classLoader) {
    try {/*from  w w  w  .  j  a  v a  2 s. c o m*/
        try (InputStream is = classLoader.getResourceAsStream("data/common/licence.txt")) {
            return IOUtils.toString(is, Charset.forName("UTF-8"));
        }
    } catch (IOException e) {
        return "Failed to load the license file";
    }
}

From source file:fr.dutra.confluence2wordpress.util.CodecUtils.java

public static String decodeAndExpand(String encoded) throws IOException {
    GZIPInputStream gzis = new GZIPInputStream(
            new Base64InputStream(new ByteArrayInputStream(encoded.getBytes(UTF_8))));
    try {/*from   ww w.  j  a v  a 2s.c o  m*/
        return IOUtils.toString(gzis, UTF_8);
    } finally {
        gzis.close();
    }
}

From source file:net.fabricmc.installer.util.MavenHandler.java

public static void load(String mavenServerURL, String packageName, String jarName)
        throws IOException, ParserConfigurationException, SAXException, XmlPullParserException {
    String baseMavenMeta = IOUtils.toString(new URL(
            mavenServerURL + "/" + packageName.replace('.', '/') + "/" + jarName + "/maven-metadata.xml"),
            "UTF-8");
    Metadata metadata = new MetadataXpp3Reader().read(new StringReader(baseMavenMeta));
    latestVersion = metadata.getVersioning().getRelease();
    versions = metadata.getVersioning().getVersions();
    Collections.reverse(versions);
}

From source file:com.github.dockerjava.test.serdes.JSONTestHelper.java

/**
 * Reads JSON String from the specified resource
 * // www  .  j a v  a2  s  . c  o  m
 * @param resource
 *            JSON File
 * @return JSON String
 * @throws IOException
 *             JSON Conversion error
 */
public static String readString(JSONResourceRef resource) throws IOException {
    try (InputStream istream = resource.getResourceClass().getResourceAsStream(resource.getFileName())) {
        if (istream == null) {
            throw new IOException("Cannot retrieve resource " + resource.getFileName());
        }
        return IOUtils.toString(istream, "UTF-8");
    }
}

From source file:com.tek271.reverseProxy.servlet.ContentUtils.java

public static String getContentText(HttpEntity entity, String charset) {
    try {// w w w .  j  a  v a 2s .  c  o  m
        return IOUtils.toString(entity.getContent(), charset);
    } catch (IOException e) {
        Throwables.propagate(e);
        return null;
    }
}

From source file:jKlout2.BaseTestKlout.java

protected String getJsonResAsString(String jsonFile) throws IOException {
    // load json file into string
    InputStream is = getClass().getClassLoader().getResourceAsStream("jKlout2/" + jsonFile);
    return IOUtils.toString(is, "UTF-8");
}

From source file:com.zaubersoftware.gnip4j.api.model.ExtendedStatusTest.java

static Activity loadFile(final String s) throws IOException {
    try (final InputStream is = ExtendedStatusTest.class.getClassLoader().getResourceAsStream(s)) {
        return x.unmarshall(IOUtils.toString(is, "utf-8"));
    }//from w  w w  .  j  av  a  2  s  . c om
}

From source file:de.tudarmstadt.ukp.clarin.webanno.api.dao.JsonImportUtil.java

public static TagSet importTagSetFromJsonWithOverwrite(Project project, User user, InputStream tagInputStream,
        AnnotationService aAnnotationService) throws IOException, JsonParseException, JsonMappingException {
    String text = IOUtils.toString(tagInputStream, "UTF-8");

    de.tudarmstadt.ukp.clarin.webanno.model.export.TagSet importedTagSet = JSONUtil.getJsonConverter()
            .getObjectMapper().readValue(text, de.tudarmstadt.ukp.clarin.webanno.model.export.TagSet.class);

    if (aAnnotationService.existsTagSet(importedTagSet.getName(), project)) {
        // A tagset exists so we'll have to replace it
        return replaceTagSet(project, user, importedTagSet, aAnnotationService);
    } else {//from   w w  w .  j  a va 2  s . com
        // Proceed normally
        return createTagSet(project, user, importedTagSet, aAnnotationService);
    }
}