日期:2014-05-20  浏览次数:20821 次

webserive
请教高手,我用java写的webservice 里面传递图片, 我用byte[]来存放图片信息,但是接收时,只能接受到部分的byte, 比如 这byte[] 大小为 70112 结果到我的方法里面就只有 11234 的大小了!  
  我传个 676 大小的 就只接收到114!
  请问这个是什么原因呢?

------解决方案--------------------
用其他方法试试,不清楚你具体实现
比如ImageIO:


BufferedImage bi = null;
URL url = null;
InputStream in = null;
String hostkey = this.getPickey();
String pichost = MessageResource.get(hostkey);
String prefix = "jpeg";
HttpServletResponse response = ServletActionContext.getResponse();

try {

String purl = new String(this.getPicurl().getBytes("ISO-8859-1"),"UTF-8");
if(purl == null || "".equals(purl)){
log.info("图片路径为空,参数错误!");
return null;
}else{
String suffix = Tooler.getSuffix(purl);
if(suffix == null || "".equals(suffix) ){
log.info("图片路径无效:"+purl);
return null;
}else if(suffix !="jpg" && suffix !="jpeg"){
prefix = suffix;
}
}


response.setContentType("image/"+prefix);
url = new URL(pichost+purl);
if(url == null){
log.info("图片资源找不到!"+pichost+purl);
return null;
}


try{
in = url.openStream();
}catch(IOException e){
String path = ServletActionContext.getServletContext().getRealPath("/images/no_pic.jpg");
File file = new File(path);
in = new FileInputStream(file);
}


bi = ImageIO.read(in);
OutputStream outstream = response.getOutputStream();
ImageIO.write(bi, prefix, outstream);
outstream.close();

}catch(Exception e){
e.printStackTrace();
log.info(e.getMessage());
}finally{
if (in != null){
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;