BufferedReader就绪方法 [英] BufferedReader ready method

查看:137
本文介绍了BufferedReader就绪方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在观察java.io.BufferedReader的ready方法的奇怪行为,该方法在Tomcat中返回false,而在Jetty中运行相同的servlet时它返回true.

I am observing a strange behaviour with the java.io.BufferedReader's ready method which returns false inside Tomcat while it returns true when the same servlet is run within Jetty.

BufferedReader bufferedReader = httpRequest.getReader();
System.out.println(bufferedReader.ready());
/** Perform some read operation */

输出:

true //Jetty
false //Tomcat

我了解BufferedReader#ready方法仅指示是否不会阻止输入(真)的下一次读取(真)或否(假),但是我无法理解两个Web服务器之间的行为差​​异环境.

I understand that the BufferedReader#ready method only indicates if the next read is not going to blocked for the input(true) or not(false), but I am failing to understand the difference in its behavior between the two web server environments.

如果以前已经有人遇到过这种情况,我需要帮助以更好地了解这一点吗?

If someone has already come across this situation before ,I need help in understanding this better ?

谢谢.

推荐答案

ready()返回true.它返回false的事实并不能保证下一次读取将被阻止,并且Reader实现被授权始终从此方法返回false.

ready() returns true if the reader can guarantee that the next read won't block. The fact that it returns false doesn't guarantee that the next read will block, and a Reader implementation is authorized to always return false from this method.

Jetty和Tomcat是Java EE Web容器的两种不同实现,并且各自提供自己的HttpServletRequest实现.因此,他们显然做出了不同的设计选择,但他们每个人都遵守规范.

Jetty and Tomcat are two different implementations of a Java EE web container, and each provides its own HttpServletRequest implementation. They've thus obviously made different design choices, but each of them respects the specification.

您不应该完全依赖此方法.我从未遇到过使用它很有用的情况.

You should simply not rely on this method. I've never met a case where using it was useful.

这篇关于BufferedReader就绪方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆