From: Greg W. <gr...@mo...> - 2006-03-11 17:58:31
|
Vincent, two suggestions: 1) put e.printStackTrace() in your catch blocks.... just in case an exception is happening. 2) send this example as a war file, so others can run your test and diagnose the problem. cheers Vincent Chen wrote: > Hi, all > > I have a servlet serving images under jetty 5.1.10. It read png files into > buffer and then send it to browser like the code below: > > --- code --- > > os=response.getOutputStream(); > > byte[] rawPNG=null; > try { > String imagePath=<image location> > FileInputStream fis=new FileInputStream(imagePath); > int imageSize=fis.available(); > rawPNG=new byte[imageSize]; > int offset=0,counter=0; > while ( offset < imageSize ) { > counter=fis.read(rawPNG,offset,imageSize-offset); > offset+=counter; > //System.out.println("size="+imageSize+",offset="+offset+",read="+counter); > } > fis.close(); > } catch (Exception e) { > // read image error > } > try { > sr.setContentType("image/png"); > sr.setContentLength(rawPNG.length); > os.write(rawPNG); > os.flush(); > //os.close(); > } catch (Exception e) { > // send image error > } > > --- code --- > > The strange thing is browser get 1 broken image in about 5 requests. If my ocde > has problem, it should not work at all. Why I got random result? Is there any > parameters in jetty container that I can tune to help? Is it possible the > request time out, my server usually under high load? > > Any help would be appreciated. > > Vincent Chen > > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting language > that extends applications into web and mobile media. Attend the live webcast > and join the prime developer group breaking into this new coding territory! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 |