2009-11-26 9:41:01 org.apache.struts.actions.DispatchAction dispatchMethod
严重: Dispatch[/oaClient] to method 'getInfoItem' returned an exception
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:212)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:818)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:624)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.OutOfMemoryError: Java heap space
2009-11-26 9:41:01 org.apache.struts.action.RequestProcessor processException
警告: Unhandled Exception thrown: class javax.servlet.ServletException
2009-11-26 9:41:01 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.OutOfMemoryError: Java heap space
这是报的错误int flag = 0;//文章计数 9的倍数
int paixu = 0;//文章排序
FileInfo fileinfo = null;
StringBuffer contentUrl =null;
System.out.println("backinfo"+backInfos.size()/9);
byte[] fileByte;
for(String b:backInfos) //backInfos是从WEBSERVICE取过来的
{
flag++;
if(flag==1)
{//文件ID
infoItem.setId(b);
/** 查询附件信息 是否有附件 **/
/** 1、文件的ID,2、附件内容的ID、3、附件名称 **/
ArrayOfString arrayOfStr = service.getInfoItemFileNameByGuid(b);//通过WEBSERVICE接口查询是否有附件
if(arrayOfStr!=null)
{
List<String> backFiles = arrayOfStr.getString();
System.out.println("backfiles"+backFiles.size());
int flag2 = 0;//文件信息计数 3倍数
int imgflag = 0; //图片记录
contentUrl = new StringBuffer();
for(String f:backFiles)
{
flag2++;
if(flag2==2)
{//文件内容
try {
System.out.println(f); //***********************************这个可以打印出
fileByte = fileService.getInfoItemFileBodyByBlobGuid(f);//通过接口查询出文件的byte[]
System.out.println("fileByte"); //******************这个没有打印出来
fileinfo = new FileInfo();
fileinfo.setFileByte(fileByte);
} catch (Exception e) {
System.out.println("F1");
}
finally
{
System.out.println("F2"); //****************可以打印出来
}
}
if(flag2==3&&fileinfo.getFileByte()!=null)
{//文件全名
//后缀名 jpg
String file1 = f.substring(f.lastIndexOf('.') + 1);
//文件名 活动展出
String file2 = f.substring(0, f.indexOf('.'));
f = f.trim();
if(file1.equals("jpg")&&imgflag==0)
{
/**第一张图片文件**/
try
{
StringBuffer sb = new StringBuffer();
sb.append("f:/web");
String fristurl = "/img/";
sb.append(fristurl);
String endurl = guid+"/"+b.trim();
sb.append(endurl);
int isOk = this.mkdir(sb.toString());
if(isOk==1||isOk==2)
{
sb.append("/");
sb.append(f);
File fileaddr = new File(sb.toString());
FileOutputStream out;
out = new FileOutputStream(fileaddr);
out.write(fileinfo.getFileByte());
out.flush();
out.close();
//这应该再判断一下文件是否存在 **备注
StringBuffer imgurl = new StringBuffer();
imgurl.append("../..");
imgurl.append(fristurl);
imgurl.append(endurl);
imgurl.append("/");
imgurl.append(f);
infoItem.setImgUrl(imgurl.toString());
imgflag = 1; //图片取完
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("A1");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("A2");
e.printStackTrace();
}
finally
{
System.out.println("All1");
}
}
else
{
/**其他图片文件或非图片文件**/
try
{
StringBuffer sb = new StringBuffer();
sb.append("f:/web");
String fristUrl = "/img/";
sb.append(fristUrl);
String endurl = guid+"/"+b.trim();
sb.append(endurl);
int isOk = this.mkdir(sb.toString());
if(isOk==1||isOk==2)
{
sb.append("/");
sb.append(f);
File fileaddr = new File(sb.toString());
FileOutputStream out;
out = new FileOutputStream(fileaddr);
out.write(fileinfo.getFileByte());
out.flush();
out.close();
//这应该再判断一下文件是否存在 **备注
//file.setFileUrl(endurl); //
StringBuffer htmBuff = new StringBuffer();
StringBuffer imgurl = new StringBuffer();
imgurl.append("../..");
imgurl.append(fristUrl);
imgurl.append(endurl);
imgurl.append("/");
imgurl.append(f);
htmBuff.append("<a ");
htmBuff.append("href="+imgurl.toString()+"");
htmBuff.append(">");
htmBuff.append(file2);
htmBuff.append("</a><br>");
contentUrl.append(htmBuff);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("B1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("B2");
}
finally
{
System.out.println("ALL2");
}
}
flag2=0;
fileinfo = null;
}
}
}
}
这是报错的FOR循环的其中一部分我怀疑是byte[]的问题。。我连续导某栏目分类的数据 每次导到17条就报错,其他栏目没这个问题。 有个特点就是,这17条栏目的文件大,有1M-2M。。
严重: Dispatch[/oaClient] to method 'getInfoItem' returned an exception
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:212)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:818)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:624)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.OutOfMemoryError: Java heap space
2009-11-26 9:41:01 org.apache.struts.action.RequestProcessor processException
警告: Unhandled Exception thrown: class javax.servlet.ServletException
2009-11-26 9:41:01 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.OutOfMemoryError: Java heap space
这是报的错误int flag = 0;//文章计数 9的倍数
int paixu = 0;//文章排序
FileInfo fileinfo = null;
StringBuffer contentUrl =null;
System.out.println("backinfo"+backInfos.size()/9);
byte[] fileByte;
for(String b:backInfos) //backInfos是从WEBSERVICE取过来的
{
flag++;
if(flag==1)
{//文件ID
infoItem.setId(b);
/** 查询附件信息 是否有附件 **/
/** 1、文件的ID,2、附件内容的ID、3、附件名称 **/
ArrayOfString arrayOfStr = service.getInfoItemFileNameByGuid(b);//通过WEBSERVICE接口查询是否有附件
if(arrayOfStr!=null)
{
List<String> backFiles = arrayOfStr.getString();
System.out.println("backfiles"+backFiles.size());
int flag2 = 0;//文件信息计数 3倍数
int imgflag = 0; //图片记录
contentUrl = new StringBuffer();
for(String f:backFiles)
{
flag2++;
if(flag2==2)
{//文件内容
try {
System.out.println(f); //***********************************这个可以打印出
fileByte = fileService.getInfoItemFileBodyByBlobGuid(f);//通过接口查询出文件的byte[]
System.out.println("fileByte"); //******************这个没有打印出来
fileinfo = new FileInfo();
fileinfo.setFileByte(fileByte);
} catch (Exception e) {
System.out.println("F1");
}
finally
{
System.out.println("F2"); //****************可以打印出来
}
}
if(flag2==3&&fileinfo.getFileByte()!=null)
{//文件全名
//后缀名 jpg
String file1 = f.substring(f.lastIndexOf('.') + 1);
//文件名 活动展出
String file2 = f.substring(0, f.indexOf('.'));
f = f.trim();
if(file1.equals("jpg")&&imgflag==0)
{
/**第一张图片文件**/
try
{
StringBuffer sb = new StringBuffer();
sb.append("f:/web");
String fristurl = "/img/";
sb.append(fristurl);
String endurl = guid+"/"+b.trim();
sb.append(endurl);
int isOk = this.mkdir(sb.toString());
if(isOk==1||isOk==2)
{
sb.append("/");
sb.append(f);
File fileaddr = new File(sb.toString());
FileOutputStream out;
out = new FileOutputStream(fileaddr);
out.write(fileinfo.getFileByte());
out.flush();
out.close();
//这应该再判断一下文件是否存在 **备注
StringBuffer imgurl = new StringBuffer();
imgurl.append("../..");
imgurl.append(fristurl);
imgurl.append(endurl);
imgurl.append("/");
imgurl.append(f);
infoItem.setImgUrl(imgurl.toString());
imgflag = 1; //图片取完
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("A1");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("A2");
e.printStackTrace();
}
finally
{
System.out.println("All1");
}
}
else
{
/**其他图片文件或非图片文件**/
try
{
StringBuffer sb = new StringBuffer();
sb.append("f:/web");
String fristUrl = "/img/";
sb.append(fristUrl);
String endurl = guid+"/"+b.trim();
sb.append(endurl);
int isOk = this.mkdir(sb.toString());
if(isOk==1||isOk==2)
{
sb.append("/");
sb.append(f);
File fileaddr = new File(sb.toString());
FileOutputStream out;
out = new FileOutputStream(fileaddr);
out.write(fileinfo.getFileByte());
out.flush();
out.close();
//这应该再判断一下文件是否存在 **备注
//file.setFileUrl(endurl); //
StringBuffer htmBuff = new StringBuffer();
StringBuffer imgurl = new StringBuffer();
imgurl.append("../..");
imgurl.append(fristUrl);
imgurl.append(endurl);
imgurl.append("/");
imgurl.append(f);
htmBuff.append("<a ");
htmBuff.append("href="+imgurl.toString()+"");
htmBuff.append(">");
htmBuff.append(file2);
htmBuff.append("</a><br>");
contentUrl.append(htmBuff);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("B1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("B2");
}
finally
{
System.out.println("ALL2");
}
}
flag2=0;
fileinfo = null;
}
}
}
}
这是报错的FOR循环的其中一部分我怀疑是byte[]的问题。。我连续导某栏目分类的数据 每次导到17条就报错,其他栏目没这个问题。 有个特点就是,这17条栏目的文件大,有1M-2M。。
内存问题
在jvm参数中加大内存
网上搜一下,很多
fileByte = fileService.getInfoItemFileBodyByBlobGuid(f);//通过接口查询出文件的byte
还有个有意思的现象是,我单独导第3条记录,导第一次不报错,导第二次准报错 屡试不爽。。其它均无此现象
赐教绝对不敢当,我也是菜鸟。
只能把一个从网上down mp3的小程序放下面给你参考下。你可以适当调整写文件的SAVE_SIZE的大小。
另外就是我用到的Stream类可能跟你的不一样,你的代码好长,我也看不懂。package test;import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;public class DownloadFile { public static void getSong(String _path, String _savePath) {
String savePath = _savePath;
String path = _path;
int BYTE_SIZE = 1;
int SAVE_SIZE = 1024;
byte[] buff = new byte[BYTE_SIZE];
byte[] save = new byte[SAVE_SIZE];
BufferedInputStream bf = null;
FileOutputStream file;
URL url = null;
HttpURLConnection httpUrl;
try {
url = new URL(path);
httpUrl = (HttpURLConnection) url.openConnection();
System.out.println("已经打开连接....");
bf = new BufferedInputStream(httpUrl.getInputStream());
System.out.println("已经获取资源......");
file = new FileOutputStream(savePath);
System.out.println("准备保存到:" + savePath); System.out.println("开始读入......");
int i = 0;
while (bf.read(buff) != -1) {
save[i] = buff[0];
if (i == SAVE_SIZE - 1) {
file.write(save, 0, SAVE_SIZE);
save = new byte[SAVE_SIZE];
i = 0;
} else {
i++;
}
}
if (i > 0) {
file.write(save, 0, i - 1);
}
System.out.println("下载成功!!!");
httpUrl.disconnect();
bf.close();
file.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} public static void main(String[] args) {
DownloadFile
.getSong(
" http://cdn1-20.projectplaylist.com/e1/files/cdn7/mp3_new/2584535.mp3",
"D:\\daoxiang.mp3"); }}
但是发现如下:
List <String> backFiles = arrayOfStr.getString();
//很费解,backFiles是List,下面的方式能够遍历出来吗?
for(String f:backFiles)
byte[] save = new byte[SAVE_SIZE]; //保存前缓存
循环取
int i = 0;
while (bf.read(buff) != -1) { //一个字节一个字节读
save[i] = buff[0];
if (i == SAVE_SIZE - 1) { //达到保存长度时开始保存
file.write(save, 0, SAVE_SIZE);
save = new byte[SAVE_SIZE];
i = 0;
} else {
i++;
}
}
//最后这段如果没达到保存长度,需要把前面的保存下来
if (i > 0) {
file.write(save, 0, i - 1);
}