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

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

Introduction

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

Prototype

String UTF_8

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

Click Source Link

Document

Eight-bit Unicode Transformation Format.

Usage

From source file:com.aurora.mail.service.MailService.java

/**
 * @param to/*from ww w  .  jav  a  2 s.c o  m*/
 * @param subject
 * @param content
 * @param isMultipart
 * @param isHtml
 */
@Async
public void sendEmailWithAttachment(String to, String subject, String content, final String attachmentFileName,
        final byte[] attachmentBytes, final String attachmentContentType, boolean isMultipart, boolean isHtml) {
    log.debug("Send e-mail to user '{}'!", to);

    final InputStreamSource attachmentSource = new ByteArrayResource(attachmentBytes);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(from);
        message.setSubject(subject);
        message.setText(content, isHtml);

        // Add the attachment
        message.addAttachment(attachmentFileName, attachmentSource, attachmentContentType);
        javaMailSender.send(mimeMessage);
        log.debug("Sent e-mail to User '{}'!", to);
    } catch (Exception e) {
        log.error("E-mail could not be sent to user '{}', exception is: {}", to, e.getMessage());
    }
}

From source file:com.fujitsu.dc.common.auth.token.LocalToken.java

/**
 * ??.//from ww w  .ja v a 2 s . c  om
 * @param in 
 * @param ivBytes 
 * @return ???
 */
public static String encode(final String in, final byte[] ivBytes) {
    // IV??CELL?URL??????
    Cipher cipher;
    try {
        cipher = Cipher.getInstance(AES_CBC_PKCS5_PADDING);
        cipher.init(Cipher.ENCRYPT_MODE, aesKey, new IvParameterSpec(ivBytes));
        byte[] cipherBytes = cipher.doFinal(in.getBytes(CharEncoding.UTF_8));
        return DcCoreUtils.encodeBase64Url(cipherBytes);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

From source file:io.personium.common.auth.token.LocalToken.java

/**
 * ??./* ww  w.j ava  2 s. com*/
 * @param in 
 * @param ivBytes 
 * @return ???
 */
public static String encode(final String in, final byte[] ivBytes) {
    // IV??CELL?URL??????
    Cipher cipher;
    try {
        cipher = Cipher.getInstance(AES_CBC_PKCS5_PADDING);
        cipher.init(Cipher.ENCRYPT_MODE, aesKey, new IvParameterSpec(ivBytes));
        byte[] cipherBytes = cipher.doFinal(in.getBytes(CharEncoding.UTF_8));
        return PersoniumCoreUtils.encodeBase64Url(cipherBytes);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

From source file:com.steeleforge.aem.ironsites.wcm.WCMUtil.java

/**
 * URL encode a given String, assuming UTF-8
 * /*from w ww.j  a  v a2 s. c om*/
 * @param token
 * @return URL encoded String
 * @throws UnsupportedEncodingException 
 */
public static String getURLEncoded(String token) throws UnsupportedEncodingException {
    return getURLEncoded(token, CharEncoding.UTF_8);
}

From source file:com.adobe.acs.commons.hc.impl.SMTPMailServiceHealthCheck.java

@Override
@SuppressWarnings("squid:S1141")
public Result execute() {
    final FormattingResultLog resultLog = new FormattingResultLog();

    if (messageGatewayService == null) {
        resultLog.critical("MessageGatewayService OSGi service could not be found.");
        resultLog.info(/*ww w. j  a va2 s.c  o m*/
                "Verify the Default Mail Service is active: http://<host>:<port>/system/console/components/com.day.cq.mailer.impl.CqMailingService");
    } else {
        final MessageGateway<SimpleEmail> messageGateway = messageGatewayService.getGateway(SimpleEmail.class);
        if (messageGateway == null) {
            resultLog.critical("The AEM Default Mail Service is INACTIVE, thus e-mails cannot be sent.");
            resultLog.info(
                    "Verify the Default Mail Service is active and configured: http://<host>:<port>/system/console/components/com.day.cq.mailer.DefaultMailService");
            log.warn("Could not retrieve a SimpleEmail Message Gateway");

        } else {
            try {
                List<InternetAddress> emailAddresses = new ArrayList<InternetAddress>();
                emailAddresses.add(new InternetAddress(this.toEmail));
                MailTemplate mailTemplate = new MailTemplate(IOUtils.toInputStream(MAIL_TEMPLATE),
                        CharEncoding.UTF_8);
                SimpleEmail email = mailTemplate.getEmail(StrLookup.mapLookup(Collections.emptyMap()),
                        SimpleEmail.class);

                email.setSubject("AEM E-mail Service Health Check");
                email.setTo(emailAddresses);

                email.setSocketConnectionTimeout(TIMEOUT);
                email.setSocketTimeout(TIMEOUT);
                try {
                    messageGateway.send(email);
                    resultLog.info(
                            "The E-mail Service appears to be working properly. Verify the health check e-mail was sent to [ {} ]",
                            this.toEmail);
                } catch (Exception e) {
                    resultLog.critical(
                            "Failed sending e-mail. Unable to send a test toEmail via the configured E-mail server: "
                                    + e.getMessage(),
                            e);
                    log.warn("Failed to send E-mail for E-mail Service health check", e);
                }

                logMailServiceConfig(resultLog, email);
            } catch (Exception e) {
                resultLog.healthCheckError(
                        "Sling Health check could not formulate a test toEmail: " + e.getMessage(), e);
                log.error("Unable to execute E-mail health check", e);
            }
        }
    }

    return new Result(resultLog);
}

From source file:ddf.catalog.resource.actions.DownloadResourceActionProviderTest.java

private URL getUrl(String metacardId) throws MalformedURLException, UnsupportedEncodingException {
    String encodedMetacardId = URLEncoder.encode(metacardId, CharEncoding.UTF_8);
    String urlString = String.format("%s?source=%s&metacard=%s", CONTEXT_PATH, REMOTE_SOURCE_ID,
            encodedMetacardId);/*w  w w .j a  va2s.c o  m*/
    return new URL(SystemBaseUrl.constructUrl(urlString, true));
}

From source file:com.cmcc.util.StringUtils.java

/**
 * Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte
 * array./*from   w  w  w .j  ava 2 s .  c  om*/
 * 
 * @param string
 *            the String to encode, may be <code>null</code>
 * @return encoded bytes, or <code>null</code> if the input string was <code>null</code>
 * @throws IllegalStateException
 *             Thrown when the charset is missing, which should be never according the the Java specification.
 * @see <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
 * @see #getBytesUnchecked(String, String)
 */
public static byte[] getBytesUtf8(String string) {
    return StringUtils.getBytesUnchecked(string, CharEncoding.UTF_8);
}

From source file:net.bulletin.pdi.xero.step.support.XMLChunkerTest.java

/**
 * <p>This test is checking to see that, without any container elements, the chunking will produce one
 * document and that single document should be the whole of the input.</p>
 *//*from w w  w.j  a va  2  s .  c  o m*/

@Test
public void testPullNextXmlChunk_withoutContainerElements() throws Exception {
    byte[] sampleXml = readSampleXml();

    XMLChunker chunker = new XMLChunkerImpl(
            XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(sampleXml)), // all in-memory
            new Stack<String>());

    // ---------------------------------
    String actuals[] = new String[] { chunker.pullNextXmlChunk(), chunker.pullNextXmlChunk() };
    // ---------------------------------

    // This will work through the chunks and check specific information it knows in the sample.

    {
        DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        XPath xPath = XPathFactory.newInstance().newXPath();

        org.w3c.dom.Document doc = documentBuilder
                .parse(new ByteArrayInputStream(actuals[0].getBytes(CharEncoding.UTF_8)));
        NodeList artistNodeList = (NodeList) xPath.evaluate("/Response/Artists/Artist", doc,
                XPathConstants.NODESET);

        Assert.assertEquals(3, artistNodeList.getLength());
    }

    Assert.assertNull("expected the last chunk to be null", actuals[1]);

}

From source file:mitm.common.extractor.impl.XHTMLTextExtractorTest.java

@Test
public void testHTMLBigPreamble() throws Exception {
    XHTMLTextExtractor extractor = new XHTMLTextExtractor(1, Integer.MAX_VALUE);

    TextExtractorContext context = new TextExtractorContextImpl();

    context.setName("big-preamble.html");

    extractor.extract(readDocument("big-preamble.html"), context, handler);

    assertEquals(1, textParts.size());/*www.jav  a 2 s  .c o  m*/
    assertEquals(0, attachmentParts.size());

    ExtractedPart part = textParts.get(0);
    assertEquals("big-preamble.html", part.getContext().getName());

    String text = IOUtils.toString(part.getContent(), CharEncoding.UTF_8);

    assertTrue(text.contains("function fillListToGet"));
    assertTrue(text.contains(
            " ?: ?    ? "));
}

From source file:com.fujitsu.dc.common.auth.token.LocalToken.java

/**
 * ??./* w  ww . j  av a  2  s .  com*/
 * @param in ?
 * @param ivBytes 
 * @return ???
 * @throws AbstractOAuth2Token.TokenParseException 
 */
public static String decode(final String in, final byte[] ivBytes)
        throws AbstractOAuth2Token.TokenParseException {
    byte[] inBytes = DcCoreUtils.decodeBase64Url(in);
    Cipher cipher;
    try {
        cipher = Cipher.getInstance(AES_CBC_PKCS5_PADDING);
    } catch (NoSuchAlgorithmException e) {
        throw AbstractOAuth2Token.PARSE_EXCEPTION;
    } catch (NoSuchPaddingException e) {
        throw AbstractOAuth2Token.PARSE_EXCEPTION;
    }
    try {
        cipher.init(Cipher.DECRYPT_MODE, aesKey, new IvParameterSpec(ivBytes));
    } catch (InvalidKeyException e) {
        throw AbstractOAuth2Token.PARSE_EXCEPTION;
    } catch (InvalidAlgorithmParameterException e) {
        throw AbstractOAuth2Token.PARSE_EXCEPTION;
    }
    byte[] plainBytes;
    try {
        plainBytes = cipher.doFinal(inBytes);
    } catch (IllegalBlockSizeException e) {
        throw AbstractOAuth2Token.PARSE_EXCEPTION;
    } catch (BadPaddingException e) {
        throw AbstractOAuth2Token.PARSE_EXCEPTION;
    }
    try {
        return new String(plainBytes, CharEncoding.UTF_8);
    } catch (UnsupportedEncodingException e) {
        throw AbstractOAuth2Token.PARSE_EXCEPTION;
    }
}