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:com.vmware.o11n.plugin.crypto.service.CryptoEncodingService.java

/**
 *
 * @param b64data//from   w  w w  . j a  v a  2s .  co  m
 * @return
 */
public String base64Decode(String b64data) {
    String decoded = new String(Base64.decodeBase64(b64data), StandardCharsets.UTF_8);
    return decoded;
}

From source file:com.greensopinion.finance.services.encryption.Encryptor.java

public String encrypt(String data) {
    if (data == null) {
        return null;
    }//from   w  ww .j a va 2 s . c  om
    return new String(Hex.encode(encryptor.encrypt(data.getBytes(StandardCharsets.UTF_8))));
}

From source file:org.flywaydb.core.internal.util.plus.MysqlToH2ConverterTests.java

/**
 * Read file in class path//from w w w .j a  v a 2 s .  c  o m
 * 
 * @param path path
 * @param joiner joiner
 * @return string in file
 */
private String readFileInClassPath(String path, String joiner) {

    try {

        return Files.lines(Paths.get(new ClassPathResource(path).getURI()), StandardCharsets.UTF_8)
                .collect(Collectors.joining(joiner));
    } catch (IOException e) {

        throw new IllegalStateException("Failed to read file", e);
    }
}

From source file:com.diffplug.gradle.GradleIntegrationTest.java

protected void write(String path, String... lines) throws IOException {
    String content = Arrays.asList(lines).stream().collect(Collectors.joining("\n")) + "\n";
    Path target = folder.getRoot().toPath().resolve(path);
    Files.createDirectories(target.getParent());
    Files.write(target, content.getBytes(StandardCharsets.UTF_8));
}

From source file:com.linecorp.bot.client.LineSignatureValidatorTest.java

@Test
public void generateSignature() throws Exception {
    LineSignatureValidator lineSignatureValidator = new LineSignatureValidator(
            channelSecret.getBytes(StandardCharsets.UTF_8));

    String httpRequestBody = "{}";
    byte[] headerSignature = lineSignatureValidator
            .generateSignature(httpRequestBody.getBytes(StandardCharsets.UTF_8));

    assertThat(Base64Utils.encodeToString(headerSignature))
            .isEqualTo("3q8QXTAGaey18yL8FWTqdVlbMr6hcuNvM4tefa0o9nA=");
}

From source file:com.haulmont.cuba.gui.xml.layout.ScreenXmlParser.java

public Document parseDescriptor(InputStream stream) {
    checkNotNullArgument(stream, "Input stream is null");

    String template;/* w ww . j  a  v a  2s . co  m*/
    try {
        template = IOUtils.toString(stream, StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

    return parseDescriptor(template);
}

From source file:com.liferay.mobile.android.DLAppServiceTest.java

public JSONObject addFileEntry() throws Exception {
    DLAppService service = new DLAppService(session);
    long repositoryId = props.getGroupId();

    byte[] bytes = "Hello".getBytes(StandardCharsets.UTF_8);

    return service.addFileEntry(repositoryId, PARENT_FOLDER_ID, SOURCE_FILE_NAME, MIME_TYPE, SOURCE_FILE_NAME,
            "", "", bytes, null);
}

From source file:com.sonoport.freesound.response.mapping.MapperTest.java

/**
 * Read a given JSON file into a {@link JSONObject}. Files should be stored under <code>/src/test/resources</code>.
 *
 * @param resourcePath The path to the file
 * @return {@link JSONObject} representation of the file contents
 *
 * @throws Exception Any exceptions thrown when reading the file
 *//*from w  w  w  .ja v  a 2s  .  com*/
protected JSONObject readJSONFile(final String resourcePath) throws Exception {
    final URI soundFileURI = getClass().getResource(resourcePath).toURI();
    final Path filePath = Paths.get(soundFileURI);
    final String jsonString = new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8);

    return new JSONObject(jsonString);
}

From source file:rxweb.RxJavaServerTests.java

@Test
public void writeBuffer() throws IOException {
    server.get("/test", (request, response) -> response.status(Status.OK)
            .content(Observable.just(ByteBuffer.wrap("This is a test!".getBytes(StandardCharsets.UTF_8)))));
    String content = Request.Get("http://localhost:8080/test").execute().returnContent().asString();
    Assert.assertEquals("This is a test!", content);
}

From source file:com.blackducksoftware.integration.hub.detect.detector.packagist.ComposerLockExtractor.java

public Extraction extract(final File directory, final File composerJson, final File composerLock) {
    try {/*from  w  w  w .  ja  v a 2s . com*/
        final String composerJsonText = FileUtils.readFileToString(composerJson, StandardCharsets.UTF_8);
        final String composerLockText = FileUtils.readFileToString(composerLock, StandardCharsets.UTF_8);

        logger.debug(composerJsonText);
        logger.debug(composerLockText);

        final PackagistParseResult result = packagistParser.getDependencyGraphFromProject(directory.toString(),
                composerJsonText, composerLockText);

        return new Extraction.Builder().success(result.codeLocation).projectName(result.projectName)
                .projectVersion(result.projectVersion).build();
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}