Introducing mimepull - Streaming API for MIME messages
Posted by jitu on October 12, 2007 at 03:54 PM | Comments (1)
New project mimepull
allows applications to access MIME attachments in a streaming
fashion. Often times, larger MIME messages cannot
be loaded
into
memory. Hence the whole message or attachment parts are written to a
file system and access to the attachment parts is provided using those
files.
But in some cases, the MIME attachment parts can be accessed
by
applications in a streaming fashion, provided:
- The parts are accessed
orderly(as they appear in the stream)
- The parts are accessed only
once.
In such situations, the parts need not be written to file
system(however large message it is !). How is it implemented
? MIME
message parsing is done using pull-parsing, much similar to StAX
in XML world. Using the parser one can pull chunk after chunk of the
MIME message.
for e.g.: public void parse() { MIMEParser parser = new MIMEParser(InputStream, boundary, ...); Iterator<MIMEEvent> it = parser.iterator(); while(it.hasNext()) { MIMEEvent event = it.next(); switch(event.getEventType()) { case START_MESSAGE : case START_PART : case HEADERS : case CONTENT : // called multiple times for a attachment case END_PART : case END_MESSAGE : } } }
But an application developer doesn't have to worry about this
low-level parsing details. There is a nice high-level API to get
different attachment parts in a streaming fashion. The
MIMEParts are constructed lazily, and parsing is
triggered by applications while reading the attachment parts.
MIMEConfig provides various configuration options to control parsing
and storing MIME parts. It is also possible to read MIME parts in any
order and multiple times, but doing so may create attachment parts on
the file system.
// Parts are accessed in order. The data is accessed in a streaming fashion // using readOnce() and data is not stored in temp files. public void parse() { InputStream in = ... String boundary = ... MIMEConfig config = ... MIMEMessage mm = new MIMEMessage(in, boundary, config);
MIMEPart partA = mm.getPart("partA"); InputStream ais = partA.readOnce(); // read ais
MIMEPart partB = mm.getPart("partB"); InputStream bis = partB.readOnce(); // read bis
}
The implementation would be easier if the parts are accessed
in an order. Since parts can be accessed in any order, it required more
careful approach. Also while the first part's stream is read
half way, the application could access the second part. We wanted to
have an efficient implementation and avoid writing to file system
whereever we can(some situations, we cannot avoid writing those large
MIME parts to temp files). Thanks to Kohsuke
who helped me in implementing this in an efficient way.
In a future blog, I would write how mimepull is used in JAX-WS
RI 2.1.3 and JAX-WS RI applications take advantage of this to
send/receive larger attachments.
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
银屑病
治疗银屑病
银屑病治疗
乙肝
治疗乙肝
乙肝治疗
乙型肝炎
癌症
肿瘤
胃癌
肺癌
肝癌
门诊
癌症
肿瘤
胃癌
肺癌
肝癌
白血病
鼻咽癌
大肠癌
宫颈癌
膀胱肿瘤
食管癌
乳腺癌
抗癌新药
肾癌
胰腺癌
胆囊癌
甲状腺癌
脑瘤
恶性黑色素瘤
恶性淋巴瘤
阴道恶性肿瘤
卵巢恶性肿瘤
绒毛膜癌
子宫内膜癌
阴茎癌
睾丸肿瘤
前列腺癌
癌症
肿瘤
胃癌
肺癌
肝癌
白血病
鼻咽癌
大肠癌
宫颈癌
膀胱癌
食管癌
食道癌
乳腺癌
抗癌新药
肾癌
胰腺癌
胆囊癌
直肠癌
甲状腺癌
脑膜瘤
恶性黑色素瘤
恶性淋巴瘤
阴道恶性肿瘤
卵巢癌
绒毛膜癌
子宫内膜癌
阴茎癌
睾丸肿瘤
前列腺癌
肝病
肝病治疗
乙肝
治疗乙肝
乙肝治疗
乙型肝炎
丙肝
脂肪肝
肝纤维化
肝硬化
肝性脑病
紫杉醇注射液
开普拓
美罗华
赫赛汀
天地欣
香菇多糖
艾普升
宁得朗
康士得
诺雷得
瑞宁得
芙瑞
瑞婷
法乐通
易瑞沙
多吉美
特罗凯
泰勒宁
路盖克
皮肤病
银屑病
治疗银屑病
银屑病治疗
牛皮癣
白癜风
尖锐湿疣
脱发
青春痘
痤疮
皮炎
灰指甲
疤痕
瘢痕
疱疹
系统性红斑狼疮
色斑
艾滋病
丽科杰
里亚美
明欣利迪
疣迪
明竹欣
无为白癜风胶囊
维阿露
白癜净
达霏欣
狼疮丸
适今可
克银丸
云香十五味丸
化瘀祛斑胶囊
疤痕敌
每宜
新药网
肺癌
鼻咽癌
食道癌
胃癌
肝癌
大肠癌
乳腺癌
卵巢癌
膀胱癌
白血病
胰腺癌
宫颈癌
神经内科
癫痫
帕金森病
老年性痴呆
脑血管病
多发性硬化症
偏头痛
小儿脑瘫
心血管
高血压
高血脂症
心血管疾病
精神心理
精神分裂症
抑郁症|焦虑症|躁抑症
强迫症
睡眠障碍
多动症
神经衰弱
糖尿病
类风湿
瑞美隆
肉蔻五味丸
喜普妙
怡诺思
优克
恩经复
申捷
重塑杰
施捷因
神经妥乐平
七十味珍珠丸
珊瑚七十味丸
郝智片
参蛇偏瘫胶囊
扎冲十三味丸
洛斯宝
安理申
金思平
泰舒达
珂丹
利鲁唑
力如太
静灵口服液
地牡宁神口服液
健儿贴
哈伯因
肺癌
小细胞肺癌
非小细胞肺癌
肺膦癌
肺腺癌
香菇多糖
瑞宁得
复方斑蝥胶囊
金复康口服液
叶黄素
黄斑病变
视网膜病变
青光眼
干眼症
近视弱视
玻璃体混浊
白内障
葡萄膜炎
角膜炎
结膜病
癫痫
偏头痛
精神分裂症
抑郁症
帕金森病
老年性痴呆
强迫症
脑血管病
睡眠障碍
多动症
神经损伤
小儿脑瘫
神经衰弱
多发性硬化症
倍泰龙
利比
利鲁唑
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
中国癌症之家
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客之家
癌症博客
癌症博客
癌症博客
癌症博客
中国癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症信息博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客网
癌症博客
癌症博客中国人
癌症博客
癌症博客
癌症博客
癌症博客
中国癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
Posted by: gzganbing on October 16, 2007 at 01:50 AM
|