commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bibs L <>
Subject java.lang.OutOfMemoryError - IOUtils.copy - When file size larger than 7 MB
Date Wed, 25 Apr 2007 23:05:00 GMT
I am stuck with a java.lang.OutOfMemoryError when I try to copy a file 
of about 7 MB from a window server. I am using the, 
IOUtils.copy(fileIn, response.getOutputStream()) with Survlet response 
to get the download diaglog to pop up.

This is working fine when I run it locally - (download file larger than 
7MB), but when I deploy the code to Shaed Environment- (download the 
SAME file larger than 7MB), it is throwing java.lang.OutOfMemoryError 
Exception. And evertime it throw the OutOfMemoryError, it creates a file and a javacore File on the shared environemnt's profile 

Does anyone know what I need to do to fix this issue? 

The only thing I could think of is that the memory is low on the 
server, do we need to increase the JVM heap? What's the down side to that? 
Is it something I am doing wring in my Code below? I could download 
file size less than 7MB.

A few notes about our shared envirnment:
- We are running WebSphere 6.0 on Window server
- It is a Virtual Machine
- 4 GBs on server, but is split to 4 server instance, so we have about 
1 GB
- The code below is executed on WebSphere, but the file that need to be 
downloaded is on a different window server - shared server - 

I would greatly appreciate any help you could offer!!!! 

Here's my code:

FileInputStream fileIn = null;
File file = null;
URL url = null;
URLConnection urlConn = null;
InputStream in = null;
PrintWriter pw = null; 
file = new File("\\serverPath\download\documents\test.doc"); 

if(file.exists() == true){ 
LOG.debug("file exists..."); 

//generate URL for file 
url = file.toURL(); 
urlConn = url.openConnection(); 
in = url.openStream();

fileIn = new FileInputStream(file); 

response.setHeader("Content-Disposition","inline; filename=\"" + 
file.getName() + "\"");

LOG.debug("urlConn.getContentType() = " + urlConn.getContentType());

long startTime = System.currentTimeMillis(); 

IOUtils.copy(fileIn, response.getOutputStream());

LOG.debug("Total Time Taken to download: "+(System.currentTimeMillis() 
- startTime) + " ms"); renderFileFlag = true; 

LOG.debug("file not found..."); 
} catch (FileNotFoundExceptione) { 
LOG.error("FileNotFoundExceptione: download - " + e.getMessage(), e);

} catch (IOExceptione) { 
LOG.error("IOException: download - " + e.getMessage(), e); 

} catch (Exception e) { 
LOG.error("Exception : download - " + e.getMessage(), e);

} finally { 
if (facesContext != null) facesContext = null; 
if (fileIn != null) fileIn.close(); 
if (file != null) file = null; 
if (url != null) url = null;
if (urlConn != null) urlConn = null;
if (in != null) in.close(); 
if (pw != null) pw.close();

Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message