Xfire 图片(image) webservice byte 加密 传输 ---- 上传

最近研究 xfire 进行文件传输,现提供BASE64 加密 byte流传输方法:

https 及apache 调用方式 注意服务端xalan.jar包

 

客户端:

1、byte[]   buffer   =   image2Bytes("D:/Koala.jpg"); //读文件,转换为byte流

2、String encodedFileString = Base64.encode(buffer);//对数据流进行加密,需要注意的是此BASE64加密方法为import org.codehaus.xfire.util.Base64;包提供
      buffer   = Base64.decode(encodedFileString);

3、函数,里面提供两种方法

//将图片转成字节流
 public static byte[] image2Bytes(String imagePath) throws FileNotFoundException {

//  start
//  BufferedImage input = ImageIO.read(file1);
//  Image scaledImage = input.getScaledInstance(256,256,Image.SCALE_DEFAULT);
//  BufferedImage output = new BufferedImage(256,BufferedImage.TYPE_INT_BGR);
//  output.createGraphics().drawImage(scaledImage,null); //画图

//  end 这断方法 提供测试用 可直接将图片画出

 

//第一种方法,此方法不对图片进行任何改动
  File   image   =   new   File( imagePath);//读取文件路径,存文件
  InputStream is = new FileInputStream(image);
  byte[] buff = new byte[(int)image.length()];//文件大小  System.out.println("image.length()=="+image.length());
  

//第二种方法图片进行格式化
//  ImageIcon ima = new ImageIcon(imagePath);
//  int outputWidth = ima.getimage().getWidth(null);  
//        if (outputWidth < 1) {  
//            throw new IllegalArgumentException("output image width " + outputWidth + " is out of range");  
//        }  
//        int outputHeight = ima.getimage().getHeight(null);  
//        if (outputHeight < 1) {  
//            throw new IllegalArgumentException("output image height " + outputHeight + " is out of range");  
//        }  
//  BufferedImage bu = new BufferedImage(ima.getimage().getWidth(null),ima.getimage().getHeight(null),BufferedImage.TYPE_INT_RGB);
//  ByteArrayOutputStream imagestream = new ByteArrayOutputStream();


  try {
        //把这个jpg图像写到这个流中去,这里可以转变图片的编码格式
        //boolean resultWrite = ImageIO.write(bu,"png",imagestream);
       is.read(buff);
       is.close();
  } catch (IOException e) {
   e.printstacktrace();
  }
  //byte[] tagInfo = imagestream.toByteArray();
  byte[] tagInfo = buff;
  return tagInfo;
  }

 

服务端

1、buffer   = Base64.decode(encodedFileString);//服务端接收到加密串后进行解密

相关文章

1.使用ajax调用varxhr;functioninvoke(){if(window.ActiveXO...
               好不容易把WebService服务器...
1新建一个工程项目用来做服务端增加一个MyService1类文件pac...
packagecom.transsion.util;importjava.io.BufferedReader;i...
再生产wsdl文件时重写描述文件1usingSystem;2usingSystem.Co...
一般情况下,使用eclipse自带的jax-ws生成webservice会自动生...