List of usage examples for org.apache.commons.codec.net QCodec encode
public Object encode(Object pObject) throws EncoderException
From source file:io.datenwelt.cargo.rest.utils.Rfc2047.java
public static String encodeHeader(String input) { StringTokenizer tokenizer = new StringTokenizer(input, "\t ,;:-/=+#*", true); CharsetEncoder charsetEncoder = Charset.forName(CharEncoding.ISO_8859_1).newEncoder(); QCodec qcodec = new QCodec(Charset.forName(CharEncoding.UTF_8)); StringBuilder encoded = new StringBuilder(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (!charsetEncoder.canEncode(token)) { try { encoded.append(qcodec.encode(token)); } catch (EncoderException ex) { LOG.debug("Skipping the Q encoding of header value for non ISO-8859-1 string: {}", input, ex); encoded.append(token);// www . ja v a 2s . com } } else { encoded.append(token); } } return encoded.toString(); }
From source file:com.haulmont.cuba.core.app.EmailSender.java
protected String encodeAttachmentName(SendingAttachment attachment) { String encodedFileName;/*from ww w . j a v a 2 s. c o m*/ try { QCodec qCodec = new QCodec(); encodedFileName = qCodec.encode(attachment.getName()); } catch (EncoderException e) { encodedFileName = attachment.getName(); } return encodedFileName; }