Example usage for org.apache.commons.lang3 CharEncoding UTF_8

List of usage examples for org.apache.commons.lang3 CharEncoding UTF_8

Introduction

In this page you can find the example usage for org.apache.commons.lang3 CharEncoding UTF_8.

Prototype

String UTF_8

To view the source code for org.apache.commons.lang3 CharEncoding UTF_8.

Click Source Link

Document

Eight-bit Unicode Transformation Format.

Every implementation of the Java platform is required to support this character encoding.

Usage

From source file:de.micromata.tpsb.doc.StaticTestDocGenerator.java

public static void main(String[] args) {

    ParserConfig.Builder bCfg = new ParserConfig.Builder();
    ParserConfig.Builder tCfg = new ParserConfig.Builder();
    tCfg.generateIndividualFiles(true);//from   w w w  . j a v  a  2  s.co  m
    bCfg.generateIndividualFiles(true);
    List<String> la = Arrays.asList(args);
    Iterator<String> it = la.iterator();
    boolean baseDirSet = false;
    boolean ignoreLocalSettings = false;
    List<String> addRepos = new ArrayList<String>();
    StringResourceLoader.setRepository(StringResourceLoader.REPOSITORY_NAME_DEFAULT,
            new StringResourceRepositoryImpl());
    try {
        while (it.hasNext()) {
            String arg = it.next();
            String value = null;

            if ((value = getArgumentOption(it, arg, "--project-root", "-pr")) != null) {
                File f = new File(value);
                if (f.exists() == false) {
                    System.err.print("project root doesn't exists: " + f.getAbsolutePath());
                    continue;
                }
                TpsbEnvironment.get().addProjectRoots(f);
                File ts = new File(f, "src/test");
                if (ts.exists() == true) {
                    tCfg.addSourceFileRespository(new FileSystemSourceFileRepository(ts.getAbsolutePath()));
                    bCfg.addSourceFileRespository(new FileSystemSourceFileRepository(ts.getAbsolutePath()));
                }
                continue;
            }
            if ((value = getArgumentOption(it, arg, "--test-input", "-ti")) != null) {
                File f = new File(value);
                if (f.exists() == false) {
                    System.err.print("test-input doesn't exists: " + f.getAbsolutePath());
                }
                tCfg.addSourceFileRespository(new FileSystemSourceFileRepository(value));
                bCfg.addSourceFileRespository(new FileSystemSourceFileRepository(value));
                continue;
            }
            if ((value = getArgumentOption(it, arg, "--output-path", "-op")) != null) {
                if (baseDirSet == false) {
                    tCfg.outputDir(value);
                    bCfg.outputDir(value);
                    TpsbEnvironment.setBaseDir(value);
                    baseDirSet = true;
                } else {
                    addRepos.add(value);
                }
                continue;
            }
            if ((value = getArgumentOption(it, arg, "--index-vmtemplate", "-ivt")) != null) {
                try {
                    String content = FileUtils.readFileToString(new File(value), CharEncoding.UTF_8);
                    StringResourceRepository repo = StringResourceLoader.getRepository();
                    repo.putStringResource("customIndexTemplate", content, CharEncoding.UTF_8);
                    tCfg.indexTemplate("customIndexTemplate");
                } catch (IOException ex) {
                    throw new RuntimeException(
                            "Cannot load file " + new File(value).getAbsolutePath() + ": " + ex.getMessage(),
                            ex);
                }
                continue;
            }
            if ((value = getArgumentOption(it, arg, "--test-vmtemplate", "-tvt")) != null) {
                try {
                    String content = FileUtils.readFileToString(new File(value), CharEncoding.UTF_8);
                    StringResourceRepository repo = StringResourceLoader.getRepository();
                    repo.putStringResource("customTestTemplate", content, CharEncoding.UTF_8);
                    tCfg.testTemplate("customTestTemplate");
                } catch (IOException ex) {
                    throw new RuntimeException(
                            "Cannot load file " + new File(value).getAbsolutePath() + ": " + ex.getMessage(),
                            ex);
                }
                continue;
            }
            if (arg.equals("--singlexml") == true) {
                tCfg.generateIndividualFiles(false);
                bCfg.generateIndividualFiles(false);
            } else if (arg.equals("--ignore-local-settings") == true) {
                ignoreLocalSettings = true;
                continue;
            }
        }
    } catch (RuntimeException ex) {
        System.err.print(ex.getMessage());
        return;
    }
    if (ignoreLocalSettings == false) {
        readLocalSettings(bCfg, tCfg);
    }
    bCfg// .addSourceFileFilter(new MatcherSourceFileFilter("*Builder,*App,*builder")) //
            .addSourceFileFilter(new AnnotationSourceFileFilter(TpsbBuilder.class)) //
            .addSourceFileFilter(new AnnotationSourceFileFilter(TpsbApplication.class)) //
    ;
    tCfg// .addSourceFileFilter(new MatcherSourceFileFilter("*Test,*TestCase")) //
            .addSourceFileFilter(new AnnotationSourceFileFilter(TpsbTestSuite.class)) //
    ;

    StaticTestDocGenerator docGenerator = new StaticTestDocGenerator(bCfg.build(), tCfg.build());
    TpsbEnvironment env = TpsbEnvironment.get();
    if (addRepos.isEmpty() == false) {
        env.setIncludeRepos(addRepos);
    }
    docGenerator.parseTestBuilders();
    docGenerator.parseTestCases();
}

From source file:io.wcm.maven.plugins.i18n.FileUtil.java

public static String getStringFromClasspath(String resourcePath) throws IOException {
    try (InputStream is = FileUtil.class.getClassLoader().getResourceAsStream(resourcePath)) {
        return IOUtils.toString(is, CharEncoding.UTF_8);
    }//ww w . j a v a 2  s.c om
}

From source file:de.rnd7.kata.reversi.logic.ai.AIMatrix.java

public static AIMatrix fromResource(final String name) throws IOException {
    final AIMatrix matrix = new AIMatrix();

    try (InputStream input = AIMatrix.class.getResourceAsStream(name)) {
        final LineIterator iterator = IOUtils.lineIterator(input, CharEncoding.UTF_8);

        int lineNumber = 0;
        while (iterator.hasNext()) {
            processLine(matrix, lineNumber++, iterator.next());
        }/*  w  ww . j av a 2 s. c o m*/
    }

    return matrix;
}

From source file:com.omnigon.aem.handlebars.helpers.UniqueId.java

public static String generateUniqueId(String directoryPath) {
    byte[] bytesDirectoryPath = null;
    MessageDigest md = null;/* www .j av a 2s . co m*/
    try {
        bytesDirectoryPath = directoryPath.getBytes(CharEncoding.UTF_8);
        md = MessageDigest.getInstance(MESSAGE_DIGEST_TYPE);
    } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
        logger.error(e.getMessage(), e);
        return StringUtils.EMPTY;
    }
    md.reset();
    md.update(bytesDirectoryPath);
    String uniqueId = DatatypeConverter.printHexBinary(md.digest());
    return StringUtils.substring(uniqueId, 0, UNIQUE_ID_LENGTH);
}

From source file:io.wcm.sling.commons.util.Escape.java

/**
 * Applies URL-Encoding to the given parameter name or value. Uses {@link URLEncoder#encode(String, String)} with
 * UTF-8 character set, while avoiding the need to catch the UnsupportedEncodingException.
 * @param value the parameter name or value to encode
 * @return URL-encoded string - or empty string if the specified value was null
 * @throws RuntimeException in the very unlikely case that UTF-8 is not supported on the current system
 *///from w  w  w .ja v a 2  s  .c o  m
public static String urlEncode(String value) {
    if (value == null) {
        return "";
    }
    try {
        return URLEncoder.encode(value, CharEncoding.UTF_8);
    } catch (UnsupportedEncodingException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:io.wcm.sling.commons.request.RequestParamNoFormEncodingTest.java

private static String convertUTF8toISO88591(String value) throws UnsupportedEncodingException {
    if (value == null) {
        return null;
    }//from  www  .jav a 2 s .com
    return new String(value.getBytes(CharEncoding.UTF_8), CharEncoding.ISO_8859_1);
}

From source file:io.wcm.sling.commons.util.EscapeTest.java

@Test
public void testUrlEncode() throws UnsupportedEncodingException {
    assertEquals(URLEncoder.encode("abc", CharEncoding.UTF_8), Escape.urlEncode("abc"));
    assertEquals(URLEncoder.encode("Abc_", CharEncoding.UTF_8),
            Escape.urlEncode("Abc_"));
    assertEquals(URLEncoder.encode("Der Jodelkaiser", CharEncoding.UTF_8), Escape.urlEncode("Der Jodelkaiser"));
    assertEquals(URLEncoder.encode("Der  Jodelkaiser", CharEncoding.UTF_8),
            Escape.urlEncode("Der  Jodelkaiser"));
    assertEquals(URLEncoder.encode("lsa$5x !?_", CharEncoding.UTF_8),
            Escape.urlEncode("lsa$5x !?_"));
}

From source file:com.norconex.collector.http.crawler.redirect.impl.GenericRedirectURLProviderTest.java

@Test
public void testWriteRead() throws IOException {
    GenericRedirectURLProvider p = new GenericRedirectURLProvider();
    p.setFallbackCharset(CharEncoding.UTF_8);
    System.out.println("Writing/Reading this: " + p);
    ConfigurationUtil.assertWriteRead(p);
}

From source file:io.wcm.maven.plugins.i18n.readers.JsonI18nReader.java

@Override
public Map<String, String> read(File sourceFile) throws IOException {
    String fileContent = IOUtils.toString(sourceFile.toURI().toURL(), CharEncoding.UTF_8);
    try {/* ww w.  j  a v  a2 s  .  c o  m*/
        JSONObject root = new JSONObject(fileContent);
        Map<String, String> map = new HashMap<String, String>();
        parseJson(root, map, "");
        return map;
    } catch (JSONException ex) {
        throw new IOException("Unable to read JSON from " + sourceFile.getAbsolutePath(), ex);
    }
}

From source file:io.wcm.maven.plugins.i18n.readers.PropertiesI18nReader.java

@Override
public Map<String, String> read(File sourceFile) throws IOException {
    // read properties
    Properties props = new Properties();
    try (FileInputStream is = new FileInputStream(sourceFile);
            InputStreamReader reader = new InputStreamReader(is, CharEncoding.UTF_8)) {
        props.load(reader);//from w  w  w.ja  v  a  2s .com
    }

    // convert to map
    Map<String, String> map = new HashMap<>();
    for (Map.Entry<Object, Object> entry : props.entrySet()) {
        map.put(entry.getKey().toString(), entry.getValue().toString());
    }
    return map;
}