shuijian-xu / bitcoin

0 stars 0 forks source link

从节点拿到Headers,放入 ArrayList<Block> list 中,为什么有些element 的字节都为0x00? #263

Open shuijian-xu opened 4 years ago

shuijian-xu commented 4 years ago
int payLoadLengthInt = payloadLength.intValue();
byte[] payloadBin = new byte[payLoadLengthInt];
int readReadLength = s.read(payloadBin,0,payLoadLengthInt);

readReadLength 不会等于payLoadLengthInt,因而没有读取到的byte 默认为0X00。所以出现非常多的0X00。解决办法如下

int payLoadLengthInt = payloadLength.intValue();
byte[] payloadBin = new byte[payLoadLengthInt];
int readReadLength = s.read(payloadBin,0,payLoadLengthInt);

while(readReadLength<payLoadLengthInt){
   int currP = readReadLength;
   readReadLength =readReadLength+ s.read(payloadBin,currP,payLoadLengthInt-currP);
}