Xfire 图片(image) webservice byte 加密 传输 ---- 上传
2011-05-19 16:33
363 查看
最近研究 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, 256,BufferedImage.TYPE_INT_BGR);
// output.createGraphics().drawImage(scaledImage, 0, 0, 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);//服务端接收到加密串后进行解密
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, 256,BufferedImage.TYPE_INT_BGR);
// output.createGraphics().drawImage(scaledImage, 0, 0, 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);//服务端接收到加密串后进行解密
相关文章推荐
- java 调用xfire发布的webservice,通过传输byte[]上传图片,byte[]丢失、截断
- 图片上传转换byte[],后台接收之后将byte[]转换成Image
- 图片image和byte处理,fileupload上传图片
- android上传图片到服务器(使用base64字节流的形式通过 AsyncHttpClient框架传输)
- javscript上传图片前预览的方法setPreViewImage()
- 安卓实现拍照、在手机中选择图片通过webservice上传图片到服务器
- myBatis + SpringMVC上传、下载文件、显示byte图片文件、等比例缩放图片
- Android通过WebService实现图片的上传和下载(一)
- 图片上传根据stream生成image
- MVC与webservice上传文件(图片和视频),希望帮且到一些朋友
- Android拍照选择图片通过webservice上传图片到到服务器
- js 判断上传图片尺寸大小(var img =new Image())
- megapix-image插件 使用Canvas压缩图片上传 MegaPixImage.js下载
- android上传图片到服务器(使用base64字节流的形式通过 AsyncHttpClient框架传输)
- MVC与webservice上传文件(图片和视频),希望帮且到一些朋友
- php getimagesize 上传图片的长度和宽度检测代码
- Nginx + image_filter_module + fastdfs实现上传图片的实时缩略图预览
- WebService应用:音乐站图片上传
- webservice 以流的形式上传图片
- Android通过WebService实现图片的上传和下载(一)