How can I know a DataInput size?
public void readFields(DataInput in) throws IOException{
//How can I set up the byteArray size here?
//DataInput does not have available() or length() method.
byte[] videoByteArray = new byte[size];
in.readFully(videoByt开发者_开发百科eArray);
}
How can I know the DataInput size? Before I read all data into a byte array, I need set up the size first.
If you are sending a portion of data, the simplest approach to know the size is to send it first in the DataOutput stream. Otherwise you have to assume you want to read all the data until the end of the stream (and you can't send anything else)
DataInput is an interface for reading stream data, i.e. when length may be not known upfront. The idea is to read data chunks into byte array in a loop until you hit the end, indicated by EOFException.
精彩评论