1 56 package org.opencrx.mail.servlet; 57 58 import java.io.ByteArrayInputStream ; 59 import java.io.InputStream ; 60 61 import javax.mail.internet.ContentType ; 62 63 66 public class MessageContent { 67 68 78 public MessageContent ( 79 String id, 80 String mimeType, 81 Object binaryContent 82 ) { 83 this.id = id; 84 this.contentType = mimeType; 85 this.content = binaryContent; 86 } 87 88 95 public InputStream getInputStream() { 96 byte buffer[]; 97 InputStream is = null; 98 if(this.content instanceof byte[]) { 99 buffer = (byte[]) this.content; 100 is = new ByteArrayInputStream (buffer); 101 } 102 return is; 103 } 104 105 111 public Object getContent( 112 ) { 113 return this.content; 114 } 115 116 121 public String getContentType() { 122 return contentType; 123 } 124 125 130 public String getId() { 131 return id; 132 } 133 134 138 public String toString() { 139 ContentType mimeType = null; 140 try { 141 mimeType = new ContentType (this.contentType); 142 } 143 catch (Exception e) { 144 } 145 StringBuffer buffer = new StringBuffer (); 146 buffer.append("[content id '" + this.id + "', "); 147 buffer.append("content type '" + this.contentType + "'"); 148 if(mimeType != null && (mimeType.match("text/plain") || mimeType.match("text/html"))) { 149 buffer.append(", content '" + this.content + "'"); 150 } 151 if(this.content instanceof byte[]) { 152 buffer.append(", contentLength:" + ((byte[]) this.content).length); 153 } 154 buffer.append("]"); 155 return buffer.toString(); 156 } 157 158 private final String id; 162 private final String contentType; 163 private final Object content; 164 } 165 | Popular Tags |