请教 StringBuffer 使用问题,在线等,请指导
freey 2007-07-21 12:50:56 背景:通过TCP连接接收,要把收到的串根据指定的分割标志(H#H)分开,然后一条一条进行处理。每条消息的长度不会少于150,最长6000。
代码也下:
try{
int iLen = 0;
int iPos1 = 0;
int iPos2 = 0;
String sTmp = null;
while(true && chkFlg){
iLen = IS.read(bData);
if ( iLen > 0) {
sTmp = new String( bData);
sTmp = sTmp.trim();
strBuf.append(sTmp);
iPos1 = strBuf.indexOf("H#H");
iPos2 = strBuf.indexOf("H#P",iPos1+100);
while( iPos1>-1 && iPos2>iPos1 ){
sTmp = strBuf.substring(iPos1,iPos2);
strBuf.delete(iPos1, iPos2);
dealMsg(sTmp);
iPos1 = strBuf.indexOf("H#P");
iPos2 = strBuf.indexOf("H#P",iPos1+100);
}
System.arraycopy(bDump,0,bData,0,iBufSize);
}
if ( iLen==-1 ) {
break;
}
}
}
catch(IOException e){
}
问题:这段代码在Windows跑,不论分割符间的串有多长都正常,但放到Linux上就不行了,短些串没有问题,对于长些的串(比如大于1200的)就会出错,请帮忙看看问题在哪儿?
谢谢!!!