You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Bibs L <bi...@yahoo.com> on 2007/04/26 01:01:15 UTC
java.lang.OutOfMemoryError - IOUtils.copy - When file size larger than 7 MB
Hi,
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 org.apache.commons.io.IOUtils,
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 heapdump<dateTimestamp>.phd file and a javacore<dateTimeStamp> File on the shared environemnt's profile location.
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 - "//serverName/somedir/file.doc"
I would greatly appreciate any help you could offer!!!! THANKS!!!!!!!!!!!!!!!!!
Here's my code:
FileInputStream fileIn = null;
File file = null;
URL url = null;
URLConnection urlConn = null;
InputStream in = null;
PrintWriter pw = null;
try{
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.setContentType(urlConn.getContentType());
response.setHeader("Content-Disposition","inline; filename=\"" + file.getName() + "\"");
LOG.debug("urlConn.getContentType() = " + urlConn.getContentType());
long startTime = System.currentTimeMillis();
IOUtils.copy(fileIn, response.getOutputStream());
response.setStatus(response.SC_OK);
response.flushBuffer();
LOG.debug("Total Time Taken to download: "+(System.currentTimeMillis() - startTime) + " ms"); renderFileFlag = true;
}else{
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 out new cars at Yahoo! Autos.
---------------------------------
Ahhh...imagining that irresistible "new car" smell?
Check outnew cars at Yahoo! Autos.
java.lang.OutOfMemoryError - IOUtils.copy - When file size larger than 7 MB
Posted by Bibs L <bi...@yahoo.com>.
Hi,
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 org.apache.commons.io.IOUtils,
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 heapdump.phd file and a javacore File on the shared environemnt's profile location.
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 - "//serverName/somedir/file.doc"
I would greatly appreciate any help you could offer!!!! THANKS!!!!!!!!!!!!!!!!!
Here's my code:
FileInputStream fileIn = null;
File file = null;
URL url = null;
URLConnection urlConn = null;
InputStream in = null;
PrintWriter pw = null;
try{
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.setContentType(urlConn.getContentType());
response.setHeader("Content-Disposition","inline; filename=\"" + file.getName() + "\"");
LOG.debug("urlConn.getContentType() = " + urlConn.getContentType());
long startTime = System.currentTimeMillis();
IOUtils.copy(fileIn, response.getOutputStream());
response.setStatus(response.SC_OK);
response.flushBuffer();
LOG.debug("Total Time Taken to download: "+(System.currentTimeMillis() - startTime) + " ms"); renderFileFlag = true;
}else{
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 out new cars at Yahoo! Autos.
---------------------------------
Ahhh...imagining that irresistible "new car" smell?
Check outnew cars at Yahoo! Autos.
---------------------------------
Ahhh...imagining that irresistible "new car" smell?
Check outnew cars at Yahoo! Autos.