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:io.sledge.core.impl.servlets.SledgeConfigServlet.java

@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {
    RequestParameter envNameParam = request.getRequestParameter(SledgeConstants.ENVIRONMENT_NAME_PARAM);
    Resource packageResource = request.getResource();

    if (envNameParam != null) {
        String envName = envNameParam.getString();

        ApplicationPackage appPackage = packageResource.adaptTo(ApplicationPackage.class);
        ApplicationPackageExtractor appPackageExtractor = new SledgeApplicationPackageExtractor();
        DeploymentConfiguration deploymentConfiguration = appPackageExtractor
                .getDeploymentConfiguration(appPackage.getPackageFile());
        final DeploymentDef deploymentDef = deploymentConfiguration.getDeploymentDefByEnvironment(envName);
        final List<String> packageNamesForConfiguration = deploymentDef.getPackageNamesForConfiguration();

        String fileContent = appPackageExtractor.getEnvironmentFile(envName, appPackage);

        String output = new Gson().toJson(new ConfigurationDetails(packageNamesForConfiguration, fileContent));

        response.setCharacterEncoding(Charsets.UTF_8.toString());
        response.getWriter().write(output);
    }// w  ww  .j  a va  2s  .  c  o m
}

From source file:co.cask.cdap.security.store.FileSecureStoreTest.java

@Test
public void testGet() throws Exception {
    populateStore();//from  www .  j  a v a2s . c om
    SecureStoreMetadata metadata = SecureStoreMetadata.of(KEY1, DESCRIPTION1, PROPERTIES_1);
    SecureStoreData secureStoreData = new SecureStoreData(metadata, VALUE1.getBytes(Charsets.UTF_8));
    Assert.assertArrayEquals(secureStoreData.get(), secureStore.getSecureData(NAMESPACE1, KEY1).get());
    Assert.assertEquals(metadata.getDescription(),
            secureStore.getSecureData(NAMESPACE1, KEY1).getMetadata().getDescription());
    Assert.assertEquals(metadata.getName(),
            secureStore.getSecureData(NAMESPACE1, KEY1).getMetadata().getName());
}

From source file:com.netflix.spinnaker.clouddriver.artifacts.github.GithubArtifactCredentialsTest.java

private void runTestCase(WireMockServer server, GitHubArtifactAccount account,
        Function<MappingBuilder, MappingBuilder> expectedAuth) throws IOException {
    GitHubArtifactCredentials credentials = new GitHubArtifactCredentials(account, okHttpClient, objectMapper);

    Artifact artifact = Artifact.builder().reference(server.baseUrl() + METADATA_PATH).version("master")
            .type("github/file").build();

    prepareServer(server, expectedAuth);

    assertThat(credentials.download(artifact))
            .hasSameContentAs(new ByteArrayInputStream(FILE_CONTENTS.getBytes(Charsets.UTF_8)));
    assertThat(server.findUnmatchedRequests().getRequests()).isEmpty();
}

From source file:com.netflix.recipes.rss.manager.RSSManager.java

/**
 * Fetch the RSS feed content using Ribbon
 *//*from  w  ww . jav  a 2  s  .  co m*/
private RSS fetchRSSFeed(String url) {

    RestClient client = (RestClient) ClientFactory.getNamedClient(RSSConstants.MIDDLETIER_REST_CLIENT);
    HttpClientResponse response;
    String rssData = null;

    try {
        HttpClientRequest request = HttpClientRequest.newBuilder().setUri(new URI(url)).build();
        response = client.execute(request);

        if (response != null) {
            rssData = IOUtils.toString(response.getRawEntity(), Charsets.UTF_8);
            logger.info("Status code for " + response.getRequestedURI() + " : " + response.getStatus());
        }
    } catch (URISyntaxException e) {
        logger.error("Exception occurred when setting the URI", e);
    } catch (Exception e) {
        logger.error("Exception occurred when executing the HTTP request", e);
    }

    return parseRSS(url, rssData);
}

From source file:de.tu_dortmund.ub.data.util.TPUUtil.java

private static void checkResultForError(final String fileName) throws IOException, TPUException {

    final Path filePath = Paths.get(fileName);
    final char[] buffer = new char[MAX_BUFFER_LENGTH];
    BufferedReader bufferedReader = Files.newBufferedReader(filePath, Charsets.UTF_8);
    final int readCharacters = bufferedReader.read(buffer, 0, MAX_BUFFER_LENGTH);

    if (readCharacters <= -1) {

        LOG.debug("couldn't check file for errors; no file content in file '{}'", fileName);

        bufferedReader.close();/*from   w ww . j  ava 2  s . c om*/

        return;
    }

    final String bufferString = String.valueOf(buffer);

    if (bufferString.startsWith(ERROR_MESSAGE_START)) {

        bufferedReader.close();

        throw new TPUException(bufferString);
    }
}

From source file:com.mpobjects.rtcalltree.report.xml.XmlReporter.java

/**
 * @param aCreationDate//from ww w  .  java  2  s  .c  om
 * @param aThreadName
 * @return
 */
protected Writer createWriter(Date aCreationDate, String aThreadName) {
    String filename = MessageFormat.format(filenamePattern, aCreationDate, aThreadName);
    filename = filename.replaceAll("[: _]+", "_");
    File outfile = new File(destination, filename);
    try {
        FileUtils.forceMkdir(outfile.getParentFile());
        LOG.debug("Writing XML report to {}", outfile.toString());
        return new OutputStreamWriter(new FileOutputStream(outfile), Charsets.UTF_8);
    } catch (IOException e) {
        LOG.error("Unable to create file output stream for: " + outfile.toString() + ". " + e.getMessage(), e);
        return null;
    }
}

From source file:com.giacomodrago.immediatecrypt.aes.AESFacadeImpl.java

protected ParametersWithIV createEncryptionParameters(String password, String salt) {

    byte[] passwordBytes = password.getBytes(Charsets.UTF_8);
    byte[] saltBytes = salt.getBytes(Charsets.UTF_8);

    PKCS5S1ParametersGenerator keyGenerator = new PKCS5S1ParametersGenerator(new SHA512Digest());
    keyGenerator.init(passwordBytes, saltBytes, PBE_ITERATION_COUNT);

    ParametersWithIV params = (ParametersWithIV) keyGenerator.generateDerivedParameters(KEY_SIZE, IV_SIZE);

    return params;

}

From source file:hudson.console.AnnotatedLargeTextTest.java

@Issue("SECURITY-382")
@Test//from   w  w  w.  j a v  a  2  s .  c  om
public void badMac() throws Exception {
    ByteBuffer buf = new ByteBuffer();
    buf.write(("Go back to " + ConsoleNote.PREAMBLE_STR
            + "////4ByIhqPpAc43AbrEtyDUDc1/UEOXsoY6LeoHSeSlb1d7AAAAlR+LCAAAAAAAAP9b85aBtbiIQS+jNKU4P08vOT+vOD8nVc8xLy+/JLEkNcUnsSg9NSS1oiQktbhEBUT45ZekCpys9xWo8J3KxMDkycCWk5qXXpLhw8BcWpRTwiDkk5VYlqifk5iXrh9cUpSZl25dUcQghWaBM4QGGcYAAYxMDAwVBUAGZwkDq35Rfn4JABmN28qcAAAA"
            + ConsoleNote.POSTAMBLE_STR + "your home.\n").getBytes());
    AnnotatedLargeText<Void> text = new AnnotatedLargeText<>(buf, Charsets.UTF_8, true, null);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    text.writeLogTo(0, baos);
    assertEquals("Go back to your home.\n", baos.toString());
    StringWriter w = new StringWriter();
    text.writeHtmlTo(0, w);
    assertEquals("Go back to your home.\n", w.toString());
    assertThat(logging.getMessages(), hasItem("Failed to resurrect annotation")); // TODO assert that this is IOException: MAC mismatch
}

From source file:com.buaa.cfs.common.oncrpc.XDR.java

public String readString() {
    return new String(readVariableOpaque(), Charsets.UTF_8);
}

From source file:de.fhg.iais.asc.oai.localwriter.RepositoryWriter.java

private void writeToc(String metadataPrefix, int totalRecords) {
    StringBuilder xml = new StringBuilder(200);
    xml.append("<toc");
    xml.append(" event=\"").append(this.eventId).append("\"");
    xml.append(" metadataPrefix=\"").append(metadataPrefix).append("\"");
    xml.append(" totalrecordsHarvested=\"").append(totalRecords).append("\"");
    xml.append(">\n");
    for (String set : this.sets) {
        xml.append("\t<set>").append(set).append("</set>\n");
    }/*from w  w  w. j a v a2 s. c  o m*/
    xml.append("</toc>");
    try {
        FileUtils.write(new File(this.rootDir, "toc_" + this.eventId + ".xml"), xml.toString(), Charsets.UTF_8);
    } catch (IOException e) {
        throw new DbcException(e);
    }
}