Package org.apache.james.mailbox.hbase.mail

Examples of org.apache.james.mailbox.hbase.mail.HBaseMessage


     * @param conf configuration object for HBase cluster
     * @param result the result object containing message data
     * @return a HBaseMessage instance with message metadata.
     */
    public static Message<UUID> messageMetaFromResult(Configuration conf, Result result) {
        HBaseMessage message = null;
        Flags flags = new Flags();
        List<Property> propList = new ArrayList<Property>();
        KeyValue[] keys = result.raw();
        String mediaType = null, subType = null;
        Long modSeq = null, uid, bodyOctets = null, contentOctets = null, textualLineCount = null;
        Date internalDate = null;

        int i = 0;
        /** it is VERY IMPORTANT that the byte arrays are kept ascending */
        if (Bytes.equals(keys[i].getQualifier(), MESSAGE_BODY_OCTETS)) {
            bodyOctets = Bytes.toLong(keys[i].getValue());
            i++;
        }
        if (Bytes.equals(keys[i].getQualifier(), MESSAGE_CONTENT_OCTETS)) {
            contentOctets = Bytes.toLong(keys[i].getValue());
            i++;
        }
        if (Bytes.equals(keys[i].getQualifier(), MESSAGE_INTERNALDATE)) {
            internalDate = new Date(Bytes.toLong(keys[i].getValue()));
            i++;
        }
        // may be null so it will probably skip
        if (Bytes.equals(keys[i].getQualifier(), MESSAGE_TEXT_LINE_COUNT)) {
            textualLineCount = Bytes.toLong(keys[i].getValue());
            i++;
        }

        if (Bytes.equals(keys[i].getQualifier(), MESSAGE_MODSEQ)) {
            modSeq = Bytes.toLong(keys[i].getValue());
            i++;
        }
        if (Bytes.equals(keys[i].getQualifier(), MESSAGE_MEDIA_TYPE)) {
            mediaType = Bytes.toString(keys[i].getValue());
            i++;
        }
        if (Bytes.equals(keys[i].getQualifier(), MESSAGE_SUB_TYPE)) {
            subType = Bytes.toString(keys[i].getValue());
            i++;
        }
        // only TEXT_LINE_COUNT can be missing if message is binary
        if (i < 5) {
            throw new RuntimeException("HBase message column names not sorted.");
        }
        while (i < keys.length) {
            //get message properties
            if (Bytes.startsWith(keys[i].getQualifier(), PREFIX_PROP_B)) {
                propList.add(getProperty(keys[i].getValue()));
            } else if (Bytes.startsWith(keys[i].getQualifier(), PREFIX_SFLAGS_B)) {
                // get system flags, stored as qualifiers
                if (Bytes.equals(MARKER_PRESENT, keys[i].getValue())) {
                    flags.add(systemFlagFromBytes(keys[i].getQualifier()));
                }
            } else if (Bytes.startsWith(keys[i].getQualifier(), PREFIX_UFLAGS_B)) {
                // get user flags, stored as value qualifier
                flags.add(userFlagFromBytes(keys[i].getQualifier()));
            }
            i++;
        }
        UUID uuid = UUIDFromRowKey(result.getRow());
        uid = Long.MAX_VALUE - Bytes.toLong(result.getRow(), 16);
        PropertyBuilder props = new PropertyBuilder(propList);
        props.setMediaType(mediaType);
        props.setSubType(subType);
        message = new HBaseMessage(conf, uuid, internalDate, flags, contentOctets, (int) (contentOctets - bodyOctets), props);
        message.setUid(uid);
        message.setModSeq(modSeq);
        message.setTextualLineCount(textualLineCount);
        return message;
    }
View Full Code Here

TOP

Related Classes of org.apache.james.mailbox.hbase.mail.HBaseMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.