Example usage for java.nio.charset StandardCharsets UTF_8

List of usage examples for java.nio.charset StandardCharsets UTF_8

Introduction

In this page you can find the example usage for java.nio.charset StandardCharsets UTF_8.

Prototype

Charset UTF_8

To view the source code for java.nio.charset StandardCharsets UTF_8.

Click Source Link

Document

Eight-bit UCS Transformation Format.

Usage

From source file:concrete.ingesters.gigaword.GigawordIngesterTest.java

@Test
public void sgmlStringTest() throws IOException, ConcreteException {
    try (InputStream is = Files.newInputStream(p); BufferedInputStream bis = new BufferedInputStream(is)) {
        String sgml = IOUtils.toString(bis, StandardCharsets.UTF_8);
        Communication pdc = new GigawordDocumentConverter().fromSgmlString(sgml);
        CompactCommunicationSerializer cs = new TarGzCompactCommunicationSerializer();
        cs.toBytes(pdc);/*from  w w w. j a  va2 s  . co m*/
        this.testAgainstDogVsMan(pdc);
    }
}

From source file:com.acciente.oacc.sql.internal.StrongCleanablePasswordEncryptor.java

private byte[] getCleanedBytes(char[] password) {
    final ByteBuffer byteBuffer = StandardCharsets.UTF_8
            .encode(CharBuffer.wrap(Normalizer.normalizeToNfc(password)));
    final byte[] byteArray = new byte[byteBuffer.remaining()];
    byteBuffer.get(byteArray);//from www. jav  a  2s  . c o  m
    Arrays.fill(byteBuffer.array(), (byte) 0);
    return byteArray;
}

From source file:de.axelfaust.alfresco.nashorn.repo.loaders.CallerProvidedURLConnection.java

public CallerProvidedURLConnection(final URL url, final String script) {
    super(url);//from   w  w w.  ja v  a  2  s. c om

    // we use MD5 hashing to store some metadata about inline scripts
    // this avoids repeated compilation of same script (and injection of use strict)
    try {
        final String digest = MD5.Digest(script.getBytes(StandardCharsets.UTF_8.name()));
        final Pair<Long, Long> cachedMeta = STRING_SCRIPT_META_CACHE.get(digest);
        if (cachedMeta != null) {
            this.contentLength = cachedMeta.getFirst().longValue();
            this.lastModified = cachedMeta.getSecond().longValue();
            this.script = script;
        } else {
            this.cacheScriptFile(script);

            // simply use "now" (first occurrence) as lastModified
            this.lastModified = System.currentTimeMillis();
            this.contentLength = this.byteBuffer.length;

            this.cacheMetaData(digest);
        }
    } catch (final UnsupportedEncodingException e) {
        this.cacheScriptFile(script);

        this.lastModified = System.currentTimeMillis();
        this.contentLength = this.byteBuffer.length;

        final String digest = MD5.Digest(this.byteBuffer);
        this.cacheMetaData(digest);
    }
}

From source file:com.grantingersoll.opengrok.analysis.php.TestPhpSymbolTokenizer.java

@Test
public void test() throws Exception {
    String input;//w  w w.  jav  a 2 s. com
    try (InputStream stream = TestPhpSymbolTokenizer.class.getResourceAsStream("my_php.inc");
            Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
        input = IOUtils.toString(in);
    }
    String[] output = new String[] {
            //// <?php
            //// /**
            ////  *
            ////  * @file
            ////  * @brief
            ////  *
            ////  * @responsible
            ////  * @author
            ////  * @version
            ////  * @copyright
            ////  */
            ////
            "ConnectivityAssistant", "ManagerRpc", //// class ConnectivityAssistant extends ManagerRpc {
            "p_result", ////    public $p_result = '';
            "p_parameters", ////    protected $p_parameters = array(
            ////             'set' => array(
            ////                'config'  => 'array',
            ////                'revertTimeout' => 'integer'
            ////             )
            ////    );
            ////
            "p_manager", ////   protected $p_manager = 'myproduct::ConnectivityAssistant';
            ////
            "set", "p_config", "p_revertTimeout", ////    public function set($p_config, $p_revertTimeout) {
            "this", "p_handleResponse", "p_errors", "this", "p_call", "set", "p_result", "p_config",
            "p_revertTimeout", "p_result" ////       return $this->p_handleResponse(&$p_errors, $this->p_call()->set(&$p_result, $p_config, $p_revertTimeout), $p_result);
                                                                                                                                   ////    }
                                                                                                                                   //// }; // Configuration
                                                                                                                                   //// ?>
                                                                                                                                   ////
    };
    assertAnalyzesTo(analyzer, input, output);
}

From source file:com.grantingersoll.opengrok.analysis.lisp.TestLispSymbolTokenizer.java

@Test
public void test() throws Exception {
    String input;/*from  w  w  w  . j av  a 2  s.co m*/
    try (InputStream stream = TestLispSymbolTokenizer.class.getResourceAsStream("test.el");
            Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
        input = IOUtils.toString(in);
    }
    String[] output = new String[] {
            //// ;
            //// ; CDDL HEADER START
            //// ;
            //// ; The contents of this file are subject to the terms of the
            //// ; Common Development and Distribution License (the "License").
            //// ; You may not use this file except in compliance with the License.
            //// ;
            //// ; See LICENSE.txt included in this distribution for the specific
            //// ; language governing permissions and limitations under the License.
            //// ;
            //// ; When distributing Covered Code, include this CDDL HEADER in each
            //// ; file and include the License file at LICENSE.txt.
            //// ; If applicable, add the following below this CDDL HEADER, with the
            //// ; fields enclosed by brackets "[]" replaced with your own identifying
            //// ; information: Portions Copyright [yyyy] [name of copyright owner]
            //// ;
            //// ; CDDL HEADER END
            //// ;
            "foo-bar", "setq", "variable", //// (defun foo-bar () ( setq variable 5 ))
            "foo-bar", "setq", "str_variable", //// (defun foo-bar () ( setq str_variable "string value" ))
            "foo-bar", //// (foo-bar)
                       //// ; Multi line comment, with embedded strange characters: < > &,
                       //// ; email address: testuser@example.com and even an URL:
                       //// ; http://www.example.com/index.html and a file name and a path:
                       //// ; <example.cpp> and </usr/local/example.h>.
                       //// ; Ending with an email address: username@example.com
                       ////
    };
    assertAnalyzesTo(analyzer, input, output);
}

From source file:io.wcm.devops.conga.plugins.aem.tooling.crypto.cli.AnsibleVaultTest.java

@Test
public void testEncryptDecryptWithCarriageReturns() throws Exception {
    FileUtils.write(testFile, TEST_CONTENT, StandardCharsets.UTF_8);

    // encrypt file
    AnsibleVault.encrypt(testFile);/*from w ww.  j  av a2 s. c  o m*/
    String content = FileUtils.readFileToString(testFile, StandardCharsets.UTF_8);
    assertNotEquals(TEST_CONTENT, content);

    // replace \n with \r\n to simulate new lines on windows file systems
    content = StringUtils.replace(content, "\n", "\r\n");
    FileUtils.write(testFile, content, StandardCharsets.UTF_8);

    // decrypt file
    AnsibleVault.decrypt(testFile);
    content = FileUtils.readFileToString(testFile, StandardCharsets.UTF_8);
    assertEquals(TEST_CONTENT, content);
}

From source file:mtsar.api.csv.TaskCSV.java

public static void write(Collection<Task> tasks, OutputStream output) throws IOException {
    try (final Writer writer = new OutputStreamWriter(output, StandardCharsets.UTF_8)) {
        final Iterable<String[]> iterable = () -> tasks.stream().sorted(ORDER)
                .map(task -> new String[] { Integer.toString(task.getId()), // id
                        task.getStage(), // stage
                        Long.toString(task.getDateTime().toInstant().getEpochSecond()), // datetime
                        String.join("|", task.getTags()), // tags
                        task.getType(), // type
                        task.getDescription(), // description
                        String.join("|", task.getAnswers()), // answers
                }).iterator();/*from  w  w w  .  j a v a  2  s  . com*/

        FORMAT.withHeader(HEADER).print(writer).printRecords(iterable);
    }
}

From source file:com.geekzone.search.tools.Utils.java

/**
 * @description Cette fonction permet de rcuprer le document complet
 * de l'objet  indexer sous forme de tableau de byte (type accept 
 * par elasticSearch pour indexer un document JSON obtenu par conversion
 * d'un objet grce une librairie commme Jackson)
 * @param obj/*from  ww  w.  jav  a2s. co m*/
 * @return
 * @throws JsonProcessingException
 * @throws IOException 
 */
public static byte[] getDocument(Object obj) throws JsonProcessingException, IOException {
    byte[] document = addHashCode(obj).getBytes(StandardCharsets.UTF_8);
    return document;
}

From source file:clientserver.ServerThread.java

final void initClientData() {
    try {//from w  ww.j  a va  2s. c o  m
        OutputStreamWriter os = new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8);
        JSONObject jWriteobj = new JSONObject();
        jWriteobj.put("name1", "sp_on");
        jWriteobj.put("value1", 245);
        jWriteobj.put("name2", "sp_off");
        jWriteobj.put("value2", 45);
        jWriteobj.put("name3", "mc_on");
        jWriteobj.put("value3", 3455);
        jWriteobj.put("name4", "mc_off");
        jWriteobj.put("value4", 2045);
        os.write(jWriteobj.toString());
        os.flush();
    } catch (IOException e) {
        System.out.println("Write socket closing" + e.getMessage());
    }
}

From source file:com.ontheserverside.batch.bank.tx.SimpleElixir0Generator.java

private List<String> loadLinesFromFile(final Resource resource) throws IOException {
    return Files.readAllLines(resource.getFile().toPath(), StandardCharsets.UTF_8);
}