2013-07-21 42 views
0

我有一个示例邮件文件。我必须将消息从H分解为L | 1 | N作为一条消息。这里将两条消息合并成一个文件我想把每个消息放入一个String []中。 我该怎么做。基于终结者的邮件拆分

我已经尝试了这样的方式,但没有完成。

int beginIndex = eao.getBeginIndex(); 
int endIndex = MsgValidator.getTerminaterIndex(content) + 1; 

logger.info("beginIndex:: "+beginIndex); 
logger.info("endIndex:: "+endIndex); 
if (endIndex > beginIndex) { 
String subContent = content.substring(beginIndex, endIndex-1); 
// need help 

}

样本消息::

H|\^&|||Becton Dickinson|||||||| V1.00 |19981019184200 
P|1||PatId123 
O|1|Acc123||^^^MGIT_960_AST 
R|1|^^^AST_MGIT^4394000^P^0.5^ug/ml| 
INST_COMPLETE^105^^S||||||||19981019153400|19981020145000| 
MGIT960^^42^3^ B/A13 
L|1|N 
H|\^&|||Becton Dickinson|||||||| V1.00 |19981019184200 
P|1||PatId123 
O|1|Acc123||^^^MGIT_960_AST 
R|1|^^^AST_MGIT^4394000^P^0.5^ug/ml| 
INST_COMPLETE^105^^S||||||||19981019153400|19981020145000| 
MGIT960^^42^3^ B/A13 

L|1|N 
+2

也许只是解析这个txt文件,与旧的简单工具(inputstream-> bufferedreader->的FileReader)。然后,如果(第一个字符H | - >开始消息)解析txt,如果行等于L | 1N,那么消息结束... 或者如果你想使用事物(MsgValidator,eo)你提到,我认为你需要更多的代码... – czupe

+0

我需要统计文件中有多少个完整的消息?完整的消息意味着从H开始并结束L | 1 | N –

回答

0

我找到了解决办法:

if (endIndex > beginIndex) { 
    String subContent = content.substring(beginIndex, endIndex - 1); 
    String[] messages = subContent.split("L\\|1\\|N"); 
    logger.info("message :: " + messages.length); 
}