我知道的关于 ByteArrayInputStream 的唯一方法是 read() 但它只返回一个整数。
我有一个班级,并在某个地方新建了一个变量。然后我将函数的返回值存储在 devCfgBytes 中,如何将其读取为 int short 或 byte 以将其分配给相应的 int 变量或其他内容。我应该怎么办?任何帮助表示赞赏。
public class ScrewCfg {
short u16size;
int u32crc;
boolean bEnable;
byte u8RstFreqDiv;
final static short screwCfgLegth = 438;
//...
}
//new obj in someplace
ScrewCfg devCfg = new ScrewCfg();
//....
btnLoadConfig.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
byte[] devCfgBytes = new byte[ScrewCfg.screwCfgLegth];
int ret = mcLib.ReadUserData(devCfgBytes, ScrewCfg.screwCfgLegth);
if(ret < 0){
showMessage("Load Screw configuration Error!");
return;
}
//any method like this?
//if i want to read it as boolean, then use one byte
//read it as integer, then use the four bytes
ByteArrayInputStream in = new ByteArrayInputStream(devCfgBytes, 1, 1);
DevCfg.bEnable = in.getBoolean();
in = new ByteArrayInputStream(devCfgBytes, 2, 4);
DevCfg.u32crc = in.getInt();
}
});