Example usage for org.apache.commons.codec.net BCodec decode

List of usage examples for org.apache.commons.codec.net BCodec decode

Introduction

In this page you can find the example usage for org.apache.commons.codec.net BCodec decode.

Prototype

public Object decode(Object value) throws DecoderException 

Source Link

Document

Decodes a Base64 object into its original form.

Usage

From source file:com.kwoksys.framework.util.StringUtils.java

/**
 * Decode base64-encoded string. Supports UTF8.
 * @return/*from  w ww .j a  v a 2s. com*/
 */
public static String decodeBase64Codec(String input) {
    if (input.isEmpty()) {
        return "";
    }
    BCodec codec = new BCodec();
    try {
        return codec.decode(input);

    } catch (DecoderException e) {
        logger.warning("Problem with base64 decoding.");
        return "";
    }
}

From source file:io.datenwelt.cargo.rest.utils.Rfc2047.java

public static String decodeHeader(String input) {
    StringTokenizer tokenizer = new StringTokenizer(input, " \t", true);
    StringBuilder decoded = new StringBuilder();
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        if (!token.startsWith("=?") || !token.endsWith("?=")) {
            decoded.append(token);/* w  w w .jav a 2  s  .c  om*/
            continue;
        }
        String encodedWord = token;
        String[] parts = encodedWord.substring(2, encodedWord.length() - 2).split("\\?", 3);
        if (parts.length != 3) {
            decoded.append(token);
            continue;
        }
        Charset charset;
        try {
            charset = Charset.forName(parts[0]);
        } catch (Exception ex) {
            LOG.debug("Skipping the decoding of a header value due to an unknown charset \"{}\" found in: ",
                    parts[1], input, ex);
            decoded.append(token);
            continue;
        }
        String encoding = parts[1].toUpperCase();
        switch (encoding) {
        case "B":
            BCodec bcodec = new BCodec(charset);
            try {
                decoded.append(bcodec.decode(encodedWord));
            } catch (Exception ex) {
                LOG.debug("Skipping the decoding of BASE64 value from string \"{}\" found in: ", encodedWord,
                        input, ex);
                decoded.append(token);
            }
            break;
        case "Q":
            QCodec qcodec = new QCodec(charset);
            try {
                decoded.append(qcodec.decode(encodedWord));
            } catch (Exception ex) {
                LOG.debug("Skipping the decoding of Q encoded value from string \"{}\" found in: ", encodedWord,
                        input, ex);
                decoded.append(token);
            }
            break;
        default:
            LOG.debug("Skipping the decoding of value from unknown encoding \"{}\" found in: ", encodedWord,
                    input);
            decoded.append(token);
        }
    }
    return decoded.toString();
}

From source file:nor.util.Codec.java

public static String base64Decode(final String str) {

    String ret = str;/* w w w  . j  ava  2  s.c om*/
    try {

        ret = BCodec.decode(str);

    } catch (DecoderException e) {

        LOGGER.severe(e.getLocalizedMessage());

    }

    return ret;

}

From source file:org.chenillekit.tapestry.core.components.Kaptcha.java

@OnEvent(value = EVENT_NAME)
public StreamResponse onKaptchaImage(String kaptchaValue) {
    BCodec bCodec = new BCodec();
    try {//www.  j a  v  a2  s . co  m
        this.kaptchaValue = bCodec.decode(kaptchaValue);
    } catch (DecoderException e) {
        throw new RuntimeException(e);
    }
    BufferedImage kapatchImage = kaptchaProducer.createImage(this.kaptchaValue);

    try {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ImageIO.write(kapatchImage, "jpg", byteArrayOutputStream);
        ByteArrayInputStream bais = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        return new JPEGInline(bais, (String[]) null);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}