Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Attempt to clear a buffer that's already been flushed

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic