package ctsjavacoe.ws.fromjava;
import com.sun.xml.ws.util.ASCIIUtility;
import javax.xml.transform.stream.StreamSource;
import javax.imageio.ImageWriter;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageOutputStream;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.image.PixelGrabber;
import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
public class AttachmentHelper {
public static boolean compareStreamSource (StreamSource src1,
StreamSource src2) throws Exception {
if (src1 == null || src2 == null) {
System.out.println ("compareStreamSource - src1 or src2 null!");
return false;
}
InputStream is1 = src1.getInputStream ();
InputStream is2 = src2.getInputStream ();
if ((is1 == null) || (is2 == null)) {
System.out.println ("InputStream of - src1 or src2 null!");
return false;
}
return Arrays.equals (ASCIIUtility.getBytes (is1),
ASCIIUtility.getBytes (is2));
}
public static byte[] getImageBytes(Image image, String type)
throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedImage bufImage = convertToBufferedImage(image);
ImageWriter writer = null;
Iterator i = ImageIO.getImageWritersByMIMEType(type);
if (i.hasNext()) {
writer = (ImageWriter)i.next();
}
if (writer != null) {
ImageOutputStream stream = null;
stream = ImageIO.createImageOutputStream(baos);
writer.setOutput(stream);
writer.write(bufImage);
stream.close();
return baos.toByteArray();
}
return null;
}
private static BufferedImage convertToBufferedImage (Image image)
throws IOException {
if (image instanceof BufferedImage) {
return (BufferedImage)image;
} else {
MediaTracker tracker =
new MediaTracker (null/*not sure how this is used*/);
tracker.addImage (image, 0);
try {
tracker.waitForAll ();
} catch (InterruptedException e) {
throw new IOException (e.getMessage ());
}
BufferedImage bufImage = new BufferedImage (
image.getWidth (null),
image.getHeight (null),
BufferedImage.TYPE_INT_RGB);
Graphics g = bufImage.createGraphics ();
g.drawImage (image, 0, 0, null);
return bufImage;
}
}
public static boolean compareImages (Image image1, Image image2)
throws IOException {
if (image1 == null || image2 == null)
return false;
boolean matched = false;
Rectangle rect = new Rectangle (0, 0,
convertToBufferedImage (image1)
.getWidth (),
convertToBufferedImage (image1)
.getHeight ());
Iterator iter1 = handlePixels (image1, rect);
Iterator iter2 = handlePixels (image2, rect);
while (iter1.hasNext () && iter2.hasNext ()) {
Pixel pixel = (Pixel) iter1.next ();
if (pixel.equals ((Pixel) iter2.next ())) {
matched = true;
} else {
matched = false;
}
}
if (matched)
return true;
return false;
}
private static Iterator handlePixels (Image img, Rectangle rect) {
int x = rect.x;
int y = rect.y;
int w = rect.width;
int h = rect.height;
int[] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber (img, x, y, w, h, pixels, 0, w);
try {
pg.grabPixels ();
} catch (InterruptedException e) {
System.err.println ("interrupted waiting for pixels!");
return null;
}
if ((pg.getStatus () & ImageObserver.ABORT) != 0) {
System.err.println ("image fetch aborted or errored");
return null;
}
ArrayList tmpList = new ArrayList ();
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
tmpList.add (handleSinglePixel (x + i, y + j, pixels[j * w + i]));
}
}
return tmpList.iterator ();
}
private static Pixel handleSinglePixel (int x, int y, int pixel) {
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel) & 0xff;
return new Pixel (alpha, red, green, blue);
}
private static class Pixel {
private int a;
private int r;
private int g;
private int b;
Pixel (int a, int r, int g, int b) {
this.a = a;
this.r = r;
this.g = g;
this.b = b;
}
protected boolean equals (Pixel p) {
if (p.a == a && p.r == r && p.g == g && p.b == b)
return true;
return false;
}
}
}
|
相关推荐
本教程“5天学会jaxws-webservice编程”旨在帮助你快速掌握JAX-WS的核心概念和技术,以便在短短五天内能够熟练地运用到实际项目中。 首先,我们需要了解Web服务的基础。Web服务基于开放标准,如SOAP(Simple Object...
webservice中用到的jar,xfire-jaxws-1.2.6.jar,xfire-jaxws-1.2.6.jar,xfire-jaxws-1.2.6.jar
4. **注解支持**:使用注解简化了Web服务的定义和实现,如`@WebService`、`@SOAPBinding`等。 5. **动态客户端API**:允许在运行时动态创建和使用Web服务客户端,无需预先知道服务接口的详细信息。 6. **WSDL支持**...
maven 下载jaxws-rt 2.1.4 jar 失败了 其中包含包 com.sun.org.apache.xml.internal resolver 20050927 com.sun.xml.bind jaxb-impl 2.1.7 com.sun.xml.messaging.saaj saaj-impl 1.3.1 ...javax.xml.ws jaxws-api 2.1 ...
jaxws-rt-2.3.3
jaxws-rt-2.2.8.jar java webservice依赖包 在Tomcat中发布webservice时所用到
赠送jar包:cxf-rt-frontend-jaxws-3.0.1.jar; 赠送原API文档:cxf-rt-frontend-jaxws-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-frontend-jaxws-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-frontend-jaxws...
还在为找不到jar文件烦心吗,不用了到我空间来有你想要的,持续更新。。。 jaxws-api.jar
【JAX-WS Web服务简介】 JAX-WS(Java API for XML Web Services)是Java平台上用于构建Web服务和客户端的API,它替代了早期的...通过对"jaxws-webservice"的Demo学习,你将能够熟练地运用JAX-WS创建和消费Web服务。
5. **javax.annotation-api-1.2-b03.jar**:此库包含了Java的注解API,如`@WebService`、`@WebMethod`、`@WebResult`等,这些都是在JAX-WS中声明Web服务和操作的关键注解。通过这些注解,开发者可以轻松地在Java类上...
cxf-rt-frontend-jaxws-3.0.16.jar jar包下载3.0.16版本下载
安卓用到的额外的jar包,记录在此以备不时之需
4. **基于注解的开发**:JAX-WS允许开发者使用如`@WebService`、`@SOAPBinding`、`@WebMethod`等注解来声明服务接口和服务实现,简化了开发过程。 5. **WSDL**:Web服务描述语言(WSDL)是用于定义Web服务接口的XML...
1. **jaxws-api.jar**:这是JAX-WS的API接口定义,包含了服务端和客户端的接口,如`javax.jws.WebService`注解和相关的数据类型。 2. **jaxws-ri-runtime.jar**:这是JAX-WS运行时实现,提供了服务端和客户端的实现...
**jaxws-api-2.1-1** 是一个与Java API for XML Web Services(JAX-WS)相关的软件包,版本号为2.1-1。JAX-WS是Java平台上的一个标准,用于构建和部署Web服务。它是Sun Microsystems(现已被Oracle公司收购)在Java ...
5. **性能优化**: jaxws-ri-2.3.0可能包含了一些性能优化,例如更快的序列化/反序列化机制,更高效的内存管理等。 总之,JAX-WS是Java世界中构建和使用Web服务的强大工具,而jaxws-ri-2.3.0则是开发者实现这一功能...
5. **JAXWS-RI实现**: JAX-WS 2.1的Reference Implementation (RI)提供了一个完整的实现,包括工具和运行时环境,便于开发者快速上手。 6. **注解增强**: 提供了更多的注解,如`@WebService`、`@WebMethod`、`@...
【基于jaxws-ri的Web服务项目】 在Java世界中,Web服务是一种常见的跨平台通信方式,它允许不同系统间的应用程序通过HTTP协议交换数据。本项目是基于Java API for XML Web Services (JAX-WS) 的参考实现——JAXWS-...
1. **jaxws-api.jar**:这是JAX-WS的API规范,定义了与Web服务相关的接口和类,如`javax.xml.ws.WebServiceClient`和`javax.jws.WebMethod`等。 2. **jaxws-rt.jar**:运行时库,包含了实现JAX-WS规范所需的所有类...
jaxws-api.jar jaxws-rt.jar jaxws-rt-javadoc.jar jaxws-tools.jar jaxws-tools-javadoc.jar jsr181-api.jar management-api.jar mimepull.jar policy.jar saaj-api.jar saaj-impl.jar stax-ex.jar stax2...