Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Attempt to clear a buffer that's already been flushed  RSS feed

 
Akhilesh Yadav
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ page language="java" isErrorPage="false"%>
<jsp:directive.page import="java.util.*,java.awt.*,javax.imageio.*,java.io.*,
java.awt.image.*,com.gts.ffp.valueobjects.UserInfoVO;" />
<%@ page autoFlush="true" buffer="1094kb"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<TITLE>Member Card</TITLE>
</head>
<body>
<%
try {
%>
<%
String loyality_id1 = (((UserInfoVO) session.getAttribute("UserInfo")).getUserID());
ServletContext ctx = getServletContext();
String imgPath=(String)session.getAttribute("imgPath").toString();
String strFile=imgPath.substring(6,imgPath.length());
response.setContentType("image/png");

File f= new File(strFile);
FileInputStream is =new FileInputStream(f);

out.clear();
out = pageContext.pushBody();

int read= 0;
byte [] bytes= new byte[1024];
ServletOutputStream out1 = null;

out1 = response.getOutputStream(); //ERROR LINE

while((read=is.read(bytes))!=-1){
out1.write(bytes,0,read);

}
out1.flush();
%>

<%
} catch (Exception e) {
System.out.println("Error ::::::::::: in MEMBER VIEW " + e);
}
%>
</body>
</html>

ABove is the Code when ever i try to run this code it gives me following Error
java.io.IOException: Attempt to clear a buffer that's already been flushed
it gives error on this line out1 = response.getOutputStream();

please let me know how to solve this problem
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the response output Writer has already been created and used, you can't now start outputing bytes with an OutputStream. The text of the exception is concealing that real problem.

Why not just read the file as characters and continue to use the out that you already have?

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!