⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bodypart.java

📁 手机邮箱撒的方式方式方式的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                getHeader().getName().toLowerCase().endsWith("png"))) {            return MailForm.BPViewingModes.MULTIMEDIA;        }        if (getHeader().getBodyPartContentType() == BodyPart.TYPE_OTHER            && getHeader().getName().toLowerCase().endsWith("pdf") ) {         	return MailForm.BPViewingModes.CONVERTED;    	}        // default viewing mode        return MailForm.BPViewingModes.NO_VIEW;    }        /**     * Switches to converted content. This means that method     * {@link BodyPart#getStorage()} will return storage of     * converted content.     *      * @see BodyPart#switchToNotConvertedContent()     * @see BodyPart#convertedContentMode     * @see BodyPart#getStorage()     */    public void switchToConvertedContent() {        convertedContentMode = true;    }        /**     * If converted mode is active - {@link #getStorage()} returns storage     * of converted content - returns true.     *      * @return true if converted mode is active.     *      * @see BodyPart#switchToNotConvertedContent()     * @see BodyPart#switchToConvertedContent()     * @see BodyPart#getStorage()     */    public boolean convertedContentMode() {        return convertedContentMode;    }        /**     * Switches to not converted content. This means that method     * {@link BodyPart#getStorage()} will return storage of non     * converted content.     *      * @see BodyPart#switchToConvertedContent()     * @see BodyPart#convertedContentMode     * @see BodyPart#getStorage()     */    public void switchToNotConvertedContent() {        convertedContentMode = false;    }    /**     * Gets the storage of this body part.     * Note that it would be returned the storage of converted     * or not converted content accordingly to whether method     * {@link #switchToConvertedContent()} or {@link #switchToNotConvertedContent()}     * was called last time.     *      * @return the storage of this body part.     *      * @see #switchToConvertedContent()     * @see #switchToNotConvertedContent()     */    public ContentStorage getStorage() {        return (convertedContentMode) ? getConvertedStorage() : contentStorage;    }        /**     * Gets the storage of converted content of this body part.     * @return the storage of this body part.     */    private ContentStorage getConvertedStorage() {        return convertedContentStorage;    }        public void createConvertedContentStorage() {    	convertedContentStorage = new RMSStorage(this);    }    /**     * Gets the information stored in body part header.     * @return the information in body part header     */    public Header getHeader() { return bodyPartHeader; }    /**     * Gets the size of the body part.     * @return the size of this body part     */    public long getSize() {        //System.out.println("Here 1 " + contentStorage);        return contentStorage.getSize();    }    /**     * Sets the size of this body part.     * @param size the new size of this body part     */    public void setSize(long size) {        contentStorage.setSize(size);    }        /**     * Saves information about body part to output stream (RMS database)     * Does not save the content of the body part, saves only information about     * this body part.     * @param outputStream the output stream to which the information about     *  this body part will be saved     * @throws java.lang.Exception can occur while writing to the outputStream     */    public void saveBodyPart(DataOutputStream outputStream) throws Exception {        outputStream.writeByte(bodyState);        outputStream.writeByte(order);                bodyPartHeader.save(outputStream);                outputStream.writeByte(getStorage().getStorageType().getStorageTypeNumber());        getStorage().saveStorageHeader(outputStream);        if (convertedContentStorage == null)        	outputStream.writeBoolean(false);        else {        	outputStream.writeBoolean(true);        	getConvertedStorage().saveStorageHeader(outputStream);        }    }        /**     * Loads information about body part from input stream (of RMS database).     * Does not load the content of body part, loads only information about     * body part.     * @param inputStream the input stream in which are stored information     *  about this body part.     * @throws java.lang.Exception can occur while reading inputStream     */    public void loadBodyPart(DataInputStream inputStream) throws Exception {        setBodyState(inputStream.readByte());        order = inputStream.readByte();                bodyPartHeader = new Header();        bodyPartHeader.load(inputStream);                // create the instance of storage of given type        byte storageType = inputStream.readByte();        contentStorage = ContentStorage.createStorageInstance(this, storageType);        // load the storage        contentStorage.loadStorage(inputStream);        if (inputStream.readBoolean()) {			convertedContentStorage = ContentStorage.createStorageInstance(this, storageType);        	convertedContentStorage.loadStorage(inputStream);        }    }    /**     * The header of the body part     */    public static class Header {        public Header() {}        public Header(String name, byte bodyPartContentType, byte charset, byte encoding) {            this.name = name;            this.bodypartContentType = bodyPartContentType;            this.charSet = charset;            this.encoding = encoding;        }                public Header(Header copy) {            this.name = copy.name;            this.bodypartContentType = copy.bodypartContentType;            this.charSet = copy.charSet;            this.encoding = copy.encoding;        }                private String name = "default_mail_body"; // bodypart's name or attachment's filename		                         /**         * Bodypart transfer encoding. Possible values         * ENC_NORMAL         * ENC_BASE64         * ENC_QUOTEDPRINTABLE         * ENC_8BIT         */        private byte encoding = ENC_NORMAL;        /**         * Type of body part. Possible values:         * TYPE_TEXT         * TYPE_HTML         * TYPE_MULTIMEDIA         * TYPE_APPLICATION         * TYPE_OTHER         */        private byte bodypartContentType = TYPE_TEXT;        /**         * Bodypart text charset. Possible values:         * CH_NORMAL         * CH_ISO88591         * CH_ISO88592         * CH_WIN1250         * CH_UTF8         * CH_USASCII         */        private byte charSet = CH_NORMAL;                        public byte getEncoding() {            return encoding;        }        public void setEncoding(byte encoding) {            this.encoding = encoding;        }                        public byte getBodyPartContentType() { return bodypartContentType; }        public void setBodyPartContentType(byte bodyPartContentType) { this.bodypartContentType = bodyPartContentType; }                public byte getCharSet() { return charSet; }        public void setCharSet(byte charSet) {this.charSet = charSet; }                public String getName() { return name; }        public void setName(String name) { this.name = name; }                /**         * Gets the file extension.         * @return the extension of the file in which the content is stored.         */        public String getExtension() {            return getName().substring(getName().lastIndexOf('.') + 1);        }                /**         * Saves this body part header to RMS database         * @param outputStream         * @throws java.lang.Exception         */        void save(DataOutputStream outputStream) throws Exception {            outputStream.writeUTF(name);            outputStream.writeByte(bodypartContentType);            outputStream.writeByte(getCharSet());            outputStream.writeByte(getEncoding());        }                /**         * Loads this body part header to input stream (typically rms database)         * @param inputStream         * @throws java.lang.Exception         */        void load(DataInputStream inputStream) throws Exception {            this.name = inputStream.readUTF();            this.bodypartContentType = inputStream.readByte();            this.charSet =inputStream.readByte();            this.encoding =inputStream.readByte();                    }                public String toString() {            return super.toString() + "; name = " + name + "; encoding = " + encoding + "; bodypartContentType = " + bodypartContentType + "; charSet = " + charSet;        }            }    /**     * Enumeration class of all possible types of body part.     */    public static class BodyPartTypes {        private final String name;        private BodyPartTypes(String name) {this.name = name;}        public String toString() { return name; }        public static final BodyPartTypes BODY = new BodyPartTypes("body");        public static final BodyPartTypes ATTACHMENT = new BodyPartTypes("attachment");    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -