我正在为有关使用位填充的数据传输的分配进行编程,其中在传输 5 个相同的位时将反转的位添加到数据流中(即在 5 个“0”之后,将添加一个“1”;5“ 1”,将添加一个“0”)。我知道如何从原始文本文档中获取一些信息,以及如何将其写入新的文本文档。但是,由于某种原因,我关于添加反转位的编程部分出错了,这似乎是一个无限循环......
这是我的代码
static void addBitStuffing(Reader r, Writer w) { //Reader is an object class read the data from an original text document, Writer write the read data to a new text document
int length = 0;
for(; r.hasMoreData(); length++){
}
boolean [] feld = new boolean [length];
int i = 0;
while(r.hasMoreData()){ //hasMoreData check if there is more data in a data stream after the pointer, i.e. if there is none, it would have a value of "false"
boolean bit = r.getNextBit();
w.writeNextBit(bit);
feld[i] = bit;
i++;
if (i >= 4){
if ((feld [i] == true) && (feld[i-1] == true) && (feld [i-2] == true) && (feld [i-3] == true) && (feld [i-4] == true)){
w.writeNextBit(false);
}else{
if((feld [i] == false) && (feld[i-1] == false) && (feld [i-2] == false) && (feld [i-3] == false) && (feld [i-4] == false)){
w.writeNextBit(true);
}
}
}
}
}