最近搞得一个bug,搞了好久既抓包分析数据,又debug竟然就是搞不懂为什么数据只是读了前面一部分。后来仔细研究了一下API,原来这个方法并不是你指的多少就读入多少指定的长度是最大长度,我嚓,太坑爹了。
这是API的comments
/**
* Reads into an array of bytes. This method will
* block until some input is available.
* @param b the buffer into which the data is read
* @param off the start offset of the data
* @param len the maximum number of bytes read
* @return the actual number of bytes read, -1 is
* returned when the end of the stream is reached.
* @exception IOException If an I/O error has occurred.
*/
public int read(byte b[], int off, int len) throws IOException;
java.io.StreamCorruptedException: invalid type code: 00
at java.io.ObjectInputStream$BlockDataInputStream.readBlockHeader(ObjectInputStream.java:2519)
at java.io.ObjectInputStream$BlockDataInputStream.refill(ObjectInputStream.java:2553)
at java.io.ObjectInputStream$BlockDataInputStream.skipBlockData(ObjectInputStream.java:2455)
at java.io.ObjectInputStream.skipCustomData(ObjectInputStream.java:1951)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1928)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)