我想了解的代碼插座和DataInputStream所
DataInputStream stream =
new DataInputStream(
new ByteArrayInputStream(messageBuffer));
int messageLength = stream.readInt();
char recordType = (char) stream.readByte();
byte padding = stream.readByte();
short numberRecords = stream.readShort();
messageBuffer初始化爲新的字節[32768]作爲經由Socket.read()方法填充此片段。 我不明白的是一旦messageLength被初始化爲stream.readInt(),第二個第二條語句如何工作,即recordType?
第一條語句從字節數組的開頭讀取一個int,而下一條語句從字節數組的開頭讀取一個字節?它究竟從什麼地方知道讀取字節,整數,短褲等?
謝謝。我正在查看DataInputStream的文檔。 – ziggy