bytearrayoutputstream写入indexoutofboundsexception

rjee0c15  于 2021-07-08  发布在  Java
关注(0)|答案(0)|浏览(240)

我不断得到这个例外,尽管我的偏移/限制是在界限之内,所以我不知道这里发生了什么?
我有一个bytearrayoutputstream当前为空,一个大小为1024的字节数组。调试我可以看到我的偏移量是283,完全在界限之内,我的长度只是输入字节数组的长度(1024)。一切看起来都很好,那么是什么导致这段代码抛出indexoutofboundsexception呢?
任何帮助都将不胜感激,我真的在这里难住了
调试器屏幕截图

public void parseBytes(byte[] bytes, int length, String format) {//Buffer input bitstream until we reach msgSize indicated in header, then send fullfilled bitstream to sendRDM()
        if(!doneReading){
            int bytesOver = msgSize - byteBuffer.size()+28-length; //must be smaller, question is if we need to read socket again to fulfill (how many are we short or over)
            if(bytesOver <= 0){//negative or 0 means we can fulfill msgsize and have left over(start of next msg) (read partial bitstream)
                int off = length+bytesOver;
                byteBuffer.write(bytes, 0, off);
                leftOvers.write(bytes, off+1, length); //if bytesOver = 0, leftOver will be empty
                doneReading = true;
                byte[] inputStream = byteBuffer.toByteArray();
                byteBuffer.reset(); //empty buffer for next message
                sendRDM(inputStream, inputStream.length, format);
            }
            ...

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题