Example usage for org.apache.commons.io Charsets UTF_8

List of usage examples for org.apache.commons.io Charsets UTF_8

Introduction

In this page you can find the example usage for org.apache.commons.io Charsets UTF_8.

Prototype

Charset UTF_8

To view the source code for org.apache.commons.io Charsets UTF_8.

Click Source Link

Document

Eight-bit Unicode Transformation Format.

Usage

From source file:org.nuxeo.common.utils.TextTemplate.java

/**
 * @param processText if true, text is processed for parameters replacement
 * @deprecated Since 7.4. Use {@link #processText(InputStream, OutputStream)} (if {@code processText}) or
 *             {@link IOUtils#copy(InputStream, OutputStream)}
 *///from w w  w . j a  v a2 s. c  om
@Deprecated
public void process(InputStream is, OutputStream os, boolean processText) throws IOException {
    if (processText) {
        String text = IOUtils.toString(is, Charsets.UTF_8);
        text = processText(text);
        os.write(text.getBytes());
    } else {
        IOUtils.copy(is, os);
    }
}

From source file:org.nuxeo.common.utils.TextTemplate.java

public String processText(InputStream in) throws IOException {
    String text = IOUtils.toString(in, Charsets.UTF_8);
    return processText(text);
}

From source file:org.nuxeo.common.utils.TextTemplate.java

public void processText(InputStream is, OutputStream os) throws IOException {
    String text = IOUtils.toString(is, Charsets.UTF_8);
    text = processText(text);/*w w w.j ava2  s  .  c  o  m*/
    os.write(text.getBytes(Charsets.UTF_8));
}

From source file:org.nuxeo.common.utils.ZipUtils.java

/**
 * Unzip directly the entry./*from  w w w  .jav a  2 s .  c  o  m*/
 *
 * @return the String content of the entry with name entryName
 * @param file the source file
 * @param entryName the entry name that has to be extracted
 */
public static String getEntryContentAsString(File file, String entryName) throws IOException {
    try (InputStream resultStream = getEntryContentAsStream(file, entryName)) {
        return IOUtils.toString(resultStream, Charsets.UTF_8);
    }
}

From source file:org.nuxeo.common.utils.ZipUtils.java

public static String getEntryContentAsString(InputStream stream, String searchedEntryName) throws IOException {
    try (InputStream resultStream = getEntryContentAsStream(stream, searchedEntryName)) {
        return IOUtils.toString(resultStream, Charsets.UTF_8);
    }//  w w  w  .  ja va  2  s  .  c  om
}

From source file:org.nuxeo.common.utils.ZipUtils.java

public static String getEntryContentAsString(URL url, String entryName) throws IOException {
    try (InputStream resultStream = getEntryContentAsStream(url, entryName)) {
        return IOUtils.toString(resultStream, Charsets.UTF_8);
    }//from w w  w.jav  a2s .c  o  m
}

From source file:org.nuxeo.ecm.automation.core.rendering.MvelRender.java

@Override
public String render(String uriOrContent, Map<String, Object> root) throws OperationException, IOException {
    CompiledTemplate compiled;/* w w w .ja  v  a  2s .co m*/
    String content;
    if (uriOrContent.startsWith(Renderer.TEMPLATE_PREFIX)) {
        String name = uriOrContent.substring(Renderer.TEMPLATE_PREFIX.length());
        compiled = cache.get(name);
        if (compiled == null) {
            URL url = Framework.getService(ResourceService.class).getResource(name);
            if (url == null) {
                throw new OperationException("Rendering resource not found: " + name);
            }
            try (InputStream in = url.openStream()) {
                content = IOUtils.toString(in, Charsets.UTF_8);
            }
            compiled = TemplateCompiler.compileTemplate(content);
            cache.put(name, compiled);
        }
    } else {
        content = uriOrContent;
        compiled = TemplateCompiler.compileTemplate(content);
    }

    Object obj = TemplateRuntime.execute(compiled, root);
    return obj == null ? "" : obj.toString();
}

From source file:org.nuxeo.ecm.automation.core.scripting.Scripting.java

public static void run(OperationContext ctx, URL script) throws OperationException, IOException {
    String key = script.toExternalForm();
    Script cs = cache.get(key);//from   w  ww .j  a v  a2s.c o m
    if (cs != null) {
        cs.eval(ctx);
        return;
    }
    String path = script.getPath();
    int p = path.lastIndexOf('.');
    if (p == -1) {
        throw new OperationException("Script files must have an extension: " + script);
    }
    String ext = path.substring(p + 1).toLowerCase();
    try (InputStream in = script.openStream()) {
        if ("mvel".equals(ext)) {
            Serializable c = MVEL.compileExpression(IOUtils.toString(in, Charsets.UTF_8));
            cs = new MvelScript(c);
        } else if ("groovy".equals(ext)) {
            cs = new GroovyScript(IOUtils.toString(in, Charsets.UTF_8));
        } else {
            throw new OperationException(
                    "Unsupported script file: " + script + ". Only MVEL and Groovy scripts are supported");
        }
        cache.put(key, cs);
        cs.eval(ctx);
    }
}

From source file:org.nuxeo.ecm.core.api.model.impl.primitives.BinaryProperty.java

@SuppressWarnings("unchecked")
@Override//  ww  w  .  j ava2  s  .c  o m
public <T> T convertTo(Serializable value, Class<T> toType) throws PropertyConversionException {
    if (value == null) {
        return null;
    }
    if (InputStream.class.isAssignableFrom(toType)) {
        return (T) value;
    }
    if (toType == String.class && value instanceof InputStream) {
        try (InputStream in = (InputStream) value) {
            return (T) IOUtils.toString(in, Charsets.UTF_8);
        } catch (IOException e) {
            throw new InvalidPropertyValueException("Failed to read given input stream", e);
        }
    }
    if (toType == byte[].class && value instanceof InputStream) {
        try {
            return (T) IOUtils.toByteArray((InputStream) value);
        } catch (IOException e) {
            throw new InvalidPropertyValueException("Failed to read given input stream", e);
        }
    }
    throw new PropertyConversionException(value.getClass(), toType);
}

From source file:org.nuxeo.ecm.platform.forms.layout.io.plugins.test.TestLayoutExport.java

protected void check(LayoutDefinition layoutDef, String lang) throws Exception {
    LayoutConversionContext ctx = new LayoutConversionContext(lang, null);
    List<LayoutDefinitionConverter> layoutConverters = service.getLayoutConverters(TEST_CATEGORY);
    for (LayoutDefinitionConverter conv : layoutConverters) {
        layoutDef = conv.getLayoutDefinition(layoutDef, ctx);
    }// ww  w.  j a v a  2  s .  com
    List<WidgetDefinitionConverter> widgetConverters = service.getWidgetConverters(TEST_CATEGORY);

    String langFilePath = lang;
    if (langFilePath == null) {
        langFilePath = "nolang";
    }
    File file = Framework.createTempFile("layout-export-" + langFilePath, ".json");
    FileOutputStream out = new FileOutputStream(file);
    JSONLayoutExporter.export(WebLayoutManager.JSF_CATEGORY, layoutDef, ctx, widgetConverters, out);
    out.close();

    InputStream written = new FileInputStream(file);
    InputStream expected = new FileInputStream(
            FileUtils.getResourcePathFromContext("layout-export-" + langFilePath + ".json"));

    String expectedString = IOUtils.toString(expected, Charsets.UTF_8);
    String writtenString = IOUtils.toString(written, Charsets.UTF_8);
    // order of select options may depend on directory database => do not
    // check order of element by using the NON_EXTENSIBLE mode
    JSONAssert.assertEquals(expectedString, writtenString, JSONCompareMode.NON_EXTENSIBLE);
}