日期:2014-05-20  浏览次数:20847 次

请教 StringBuffer 使用问题,在线等,请指导
背景:通过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的)就会出错,请帮忙看看问题在哪儿?
谢谢!!!

------解决方案--------------------
出什么错呢?
------解决方案--------------------
照理说JAVA程序的可移植性很高 write once,run anywhere 不会出现这种问题啊 也不回事JRE版本不同产生的问题吧 最大的可能就是JRE的死角 可以直接提交给SUN了 哈哈