我有一个我想要写入HttpServletResponse的InputStream.这种方法由于使用byte []而花费的时间太长
InputStream is = getInputStream();
int contentLength = getContentLength();
byte[] data = new byte[contentLength];
is.read(data);
//response here is the HttpServletResponse object
response.setContentLength(contentLength);
response.write(data);
Run Code Online (Sandbox Code Playgroud)
在速度和效率方面,我想知道什么是最好的方法.
我知道使用@EJB注释的注入只能在EJB类,servlet或JSF托管bean中进行,但同时我需要在POJO类中有一个注入业务接口的实例,所以我想到做以下事情:
在我的JSF托管bean中
@EJB BusinessInterfaceLocal businessInterface;
private void someMethod(){
PojoInterface pojo = new PojoClass(this.businessInterface);
}
Run Code Online (Sandbox Code Playgroud)
在我的POJO类中,我有这个构造函数
BusinessInterfaceLocal businessInterface;
public PojoClass(BusinessInterfaceLocal businessInterface){
this.businessInterface = businessInterface;
//The following throws a Null Pointer Exception
this.businessInterface.someMethodCall();
}
Run Code Online (Sandbox Code Playgroud)
上述工作不应该正常吗?但事实并非如此,PojoClass中的businessInterface对象被计算为null,从而抛出空指针异常.
我希望有人能指出我,我做错了什么.
提前致谢.