Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Read Large Size File From Server using Java

 
Senthil B Kumar
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using the following code, which is working perfectly for small size files. But when it comes to files of size 2 MB and more its giving Internal Server Error. The Server is a ORACLE 10g server.

The same code was tried in Weblogic 6.1, in which even 6 MB file is displayed easily.

IS THIS A NETWORK PROBLEM ? IS THERE ANY SOLN FOR THIS ?


String fileURL = "http://127.0.0.1:80/reports/test.pdf";
System.out.println("fileURL=="+fileURL);
URL url = new URL(fileURL);

BufferedInputStream bis = new BufferedInputStream(url.openStream());
ServletOutputStream out =response.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(out);

byte[] buff = new byte[4096];
int bytesRead;

// Simple read/write loop.
while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
{

bos.write(buff, 0, bytesRead);

}
out.close();
bis.close();
bos.close();


04/12/08 11:40:28 Internal error in HttpServer

java.lang.InterruptedException
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at com.evermind.io.SingleReadBufferInputStream.readChunk(SingleReadBufferInputStream.java:116)
at com.evermind.io.SingleReadBufferInputStream.read(SingleReadBufferInputStream.java:35)
at com.evermind.server.http.AJPRequestHandler.readAJPPackets(AJPRequestHandler.java:462)
at com.evermind.server.http.AJPRequestHandler.initRequest(AJPRequestHandler.java:396)
at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:185)
at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:125)
at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
at java.lang.Thread.run(Thread.java:534)
04/12/08 11:59:45 9.0.4.0.0 Started
04/12/08 11:59:46 9.0.4.0.0 Started

What could be the reason ?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's taking too long causing your request to timeout most likely.
 
Senthil B Kumar
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i thought of that reason.. so i am trying by increasing the buffer size.

is there anyother workaround for this ? cauz surely this will be a major issue in any applicaitons having this functionality.

anyone could update on this workaround ?
 
Ajith Anand
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why dont you try setting the response.setContentLength.....before streaming the response....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!