What 0 returned by InputStream.read() means? How to handle this?

后端 未结 4 770
不思量自难忘°
不思量自难忘° 2020-12-16 00:10

What 0 (number of bytes read) returned by InputStream.read means? How to handle this situation?

Update: I mean read(byte[] b)

4条回答
  •  旧巷少年郎
    2020-12-16 00:58

    Take a look at the implementation of javax.sound.AudioInputStream#read(byte[] b, int off, int len) ... yuck. They completely violated the standard java.io.InputStream semantics and return a read size of 0 if you request fewer than a whole frame of data.

    So unfortunately; the common advice (and api spec) should preclude having to deal with return of zero when len > 0 but even for JDK provided classes you can't universally rely on this to be true for InputStreams of arbitrary types.

    Again, yuck.

提交回复
热议问题