application has below piece of old servlet code for which none of the input streams was closed. I am not sure whether that is correct or wrong. Should I closed each stream (ByteArrayInputStream ,InputStream,PrintWriter)?
public void doPost(HttpServletRequest reqest, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
try{
InputStream xml = new BufferedInputStream(request.getInputStream());
byte[] xmlbytes =getBytes(xml);
if(xmlBytes.lenght>0){
ByteArrayInputStream byteIn = new ByteArrayInputStream(xmlbytes);
ObjectInputStream in = new ObjectInputStream(byteIn);
// some logic here//
}
}catch(Exception e)
{ out.println("Exception");
}
}
Private static byte[] getBytes(InputStream is){
ByteArrayOutputStream os = new ByteArrayOutputStream() ;
BufferedInputStream is= new BufferdInputStream(is);
try {
Boolean b= false;
while(!(b)){
int i = is.read();
if(i == -1)
b= true;
else o.write(i);
}
}catch(IOException e){
return null;
}
return os.toByteArray();
}