Example usage for org.apache.commons.codec.net QCodec setEncodeBlanks

List of usage examples for org.apache.commons.codec.net QCodec setEncodeBlanks

Introduction

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

Prototype

public void setEncodeBlanks(boolean b) 

Source Link

Document

Defines whether optional tranformation of SPACE characters is to be used

Usage

From source file:com.zimbra.cs.imap.ImapMessage.java

static Pair<Long, InputStream> getContent(MailItem item) throws ServiceException {
    if (item instanceof Message) {
        return new Pair<Long, InputStream>(item.getSize(), item.getContentStream());
    } else if (item instanceof Contact) {
        try {/*from ww  w .jav  a 2 s.  com*/
            VCard vcard = VCard.formatContact((Contact) item);
            QCodec qcodec = new QCodec();
            qcodec.setEncodeBlanks(true);
            StringBuilder header = new StringBuilder();
            header.append("Subject: ").append(qcodec.encode(vcard.fn, MimeConstants.P_CHARSET_UTF8))
                    .append(ImapHandler.LINE_SEPARATOR);
            synchronized (GMT_DATE_FORMAT) {
                header.append("Date: ").append(GMT_DATE_FORMAT.format(new Date(item.getDate())))
                        .append(ImapHandler.LINE_SEPARATOR);
            }
            header.append("Content-Type: text/x-vcard; charset=\"utf-8\"").append(ImapHandler.LINE_SEPARATOR);
            header.append("Content-Transfer-Encoding: 8bit").append(ImapHandler.LINE_SEPARATOR);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            baos.write(header.toString().getBytes(MimeConstants.P_CHARSET_ASCII));
            baos.write(ImapHandler.LINE_SEPARATOR_BYTES);
            baos.write(vcard.getFormatted().getBytes(MimeConstants.P_CHARSET_UTF8));
            return new Pair<Long, InputStream>((long) baos.size(),
                    new SharedByteArrayInputStream(baos.toByteArray()));
        } catch (Exception e) {
            throw ServiceException.FAILURE("problems serializing contact " + item.getId(), e);
        }
    } else {
        return EMPTY_CONTENT;
    }
}