开发者

Find if InputStream of DataHandler is empty

In my application I develop web service that get attached file. The file is mapped to DataHandler object via J开发者_开发技巧axB, and I have access to the file via DataHandler.getInputStream()

My problem is this: When the file attribute exist in the web service request, but no file is attached, I still get the DataHandler object, and its getInputStream().available() = 11 bytes (a header I guess...??).

So I can I know that the inputStream is empty?

Thanks, Alon


Read it and parse the data as it should be parsed. The answer is in there.

The InputStream#available() certainly does not return the length of the stream or so as you seem to think. In some cases it (by coincidence) may, but you shouldn't rely on that. It just returns the amount of bytes which are available for read without blocking other threads. Just read the stream the usual Java IO way fully until the last bit returned -1 and then intercept on the whole data you received.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜