001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.geronimo.javamail.store.imap.connection;
019    
020    import java.io.ByteArrayInputStream;
021    import java.io.InputStream;
022    
023    import javax.mail.MessagingException;
024    
025    
026    /**
027     * The full body content of a message.
028     */
029    public class IMAPBody extends IMAPFetchBodyPart {
030        // the body content data
031        byte[] content = null;
032    
033        /**
034         * Construct a top-level MessageText data item. 
035         * 
036         * @param data   The data for the Message Text     
037         * 
038         * @exception MessagingException
039         */
040        public IMAPBody(byte[] data) throws MessagingException {
041            this(new IMAPBodySection(IMAPBodySection.BODY), data);
042        }
043        
044        /**
045         * Create a Message Text instance. 
046         * 
047         * @param section The section information.  This may include substring information if this
048         *                was just a partical fetch.
049         * @param data    The message content data.
050         * 
051         * @exception MessagingException
052         */
053        public IMAPBody(IMAPBodySection section, byte[] data) throws MessagingException {
054            super(BODY, section);
055            // save the content 
056            content = data; 
057        }
058    
059    
060        /**
061         * Get the part content as a byte array.
062         *
063         * @return The part content as a byte array.
064         */
065        public byte[] getContent() {
066            return content;
067        }
068    
069        /**
070         * Get an input stream for reading the part content.
071         *
072         * @return An ByteArrayInputStream sourced to the part content.
073         */
074        public InputStream getInputStream() {
075            return new ByteArrayInputStream(content);
076        }
077    }
078