Source Code Cross Referenced for ImageComparator.java in  » Report » pentaho-report » org » jfree » report » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » pentaho report » org.jfree.report.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * ===========================================
003:         * JFreeReport : a free Java reporting library
004:         * ===========================================
005:         *
006:         * Project Info:  http://reporting.pentaho.org/
007:         *
008:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009:         *
010:         * This library is free software; you can redistribute it and/or modify it under the terms
011:         * of the GNU Lesser General Public License as published by the Free Software Foundation;
012:         * either version 2.1 of the License, or (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015:         * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         * See the GNU Lesser General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU Lesser General Public License along with this
019:         * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020:         * Boston, MA 02111-1307, USA.
021:         *
022:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023:         * in the United States and other countries.]
024:         *
025:         * ------------
026:         * ImageComparator.java
027:         * ------------
028:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029:         */package org.jfree.report.util;
030:
031:        import java.security.MessageDigest;
032:        import java.security.NoSuchAlgorithmException;
033:        import java.util.Arrays;
034:
035:        import org.jfree.util.Log;
036:
037:        /**
038:         * The ImageComparator tries to compare a byte[] for equality by creating 2 hashes for the
039:         * bytearray and comparing thoose hashes. If no digest algorithms are available, then the
040:         * complete byte[] is used for comparison.
041:         * <p>
042:         * Using the digest method trades computing time for space.
043:         *
044:         * @author Thomas Morgner
045:         * @deprecated This class is no longer used anywhere.
046:         */
047:        public class ImageComparator {
048:            /**
049:             * A ImageCompareData that uses the complete image data for comparison.
050:             */
051:            private static final class CompleteImageCompareData {
052:                /**
053:                 * The image content.
054:                 */
055:                private final byte[] image;
056:
057:                /**
058:                 * Create a new CompleteImageCompareData instance.
059:                 *
060:                 * @param image the image data used for comparison.
061:                 */
062:                private CompleteImageCompareData(final byte[] image) {
063:                    this .image = image;
064:                }
065:
066:                /**
067:                 * Checks whether the given Object equals this object.
068:                 *
069:                 * @param o the to be compared object
070:                 * @return true, if both objects are equal
071:                 */
072:                public boolean equals(final Object o) {
073:                    if (this  == o) {
074:                        return true;
075:                    }
076:                    if (!(o instanceof  CompleteImageCompareData)) {
077:                        return false;
078:                    }
079:
080:                    final CompleteImageCompareData data = (CompleteImageCompareData) o;
081:
082:                    if (!Arrays.equals(image, data.image)) {
083:                        return false;
084:                    }
085:
086:                    return true;
087:                }
088:
089:                /**
090:                 * returns a hashcode for this class.
091:                 *
092:                 * @return always 0.
093:                 */
094:                public int hashCode() {
095:                    return image.length;
096:                }
097:            }
098:
099:            /**
100:             * An ImageComparator which uses precomputed Message-Digests to compare the image.
101:             */
102:            private static final class DigestImageCompareData {
103:                /**
104:                 * An MD5 digest.
105:                 */
106:                private byte[] digestMD5Data;
107:
108:                /**
109:                 * An SHA digest.
110:                 */
111:                private byte[] digestSHAData;
112:
113:                /**
114:                 * Creates a new DigestImageCompareData instance.
115:                 *
116:                 * @param digestMD5Data the MD5 digest data
117:                 * @param digestSHAData the SHA1 digest data
118:                 */
119:                private DigestImageCompareData(final byte[] digestMD5Data,
120:                        final byte[] digestSHAData) {
121:                    if (digestMD5Data == null || digestSHAData == null) {
122:                        throw new NullPointerException();
123:                    }
124:                    this .digestMD5Data = digestMD5Data;
125:                    this .digestSHAData = digestSHAData;
126:                }
127:
128:                /**
129:                 * Checks whether the given Object equals this object.
130:                 *
131:                 * @param o the to be compared object
132:                 * @return true, if both objects are equal
133:                 */
134:                public boolean equals(final Object o) {
135:                    if (this  == o) {
136:                        return true;
137:                    }
138:                    if (!(o instanceof  DigestImageCompareData)) {
139:                        return false;
140:                    }
141:
142:                    final DigestImageCompareData data = (DigestImageCompareData) o;
143:
144:                    if (!Arrays.equals(digestMD5Data, data.digestMD5Data)) {
145:                        return false;
146:                    }
147:                    if (!Arrays.equals(digestSHAData, data.digestSHAData)) {
148:                        return false;
149:                    }
150:
151:                    return true;
152:                }
153:
154:                /**
155:                 * returns a hashcode for this class.
156:                 *
157:                 * @return always 0.
158:                 */
159:                public int hashCode() {
160:                    return 0;
161:                }
162:            }
163:
164:            /**
165:             * An MD5 message digest.
166:             */
167:            private MessageDigest digestMD5;
168:
169:            /**
170:             * An SHA message digest.
171:             */
172:            private MessageDigest digestSHA;
173:
174:            /**
175:             * Creates a new ImageComparator. The comparator checks whether the MD5 and the SHA
176:             * message digest implementations are available. If they are not available, an
177:             * alternative comparison method is used, which is more memory consuming.
178:             */
179:            public ImageComparator() {
180:                try {
181:                    digestMD5 = MessageDigest.getInstance("MD5");
182:                } catch (NoSuchAlgorithmException nse) {
183:                    Log.info("No MD5 algorithm available");
184:                }
185:                try {
186:                    digestSHA = MessageDigest.getInstance("SHA");
187:                } catch (NoSuchAlgorithmException nse) {
188:                    Log.info("No SHA algorithm available");
189:                }
190:            }
191:
192:            /**
193:             * Creates 2 comparable objects. These objects can be compared for equality.
194:             *
195:             * @param image the image data which should be prepared for comparison
196:             * @param fast  whether to prefer the memory intensive faster compare method to the
197:             *              digest based comparation. This may result in outofmemory errors on huge
198:             *              reports or images.
199:             * @return the prepared image data.
200:             */
201:            public Object createCompareData(final byte[] image,
202:                    final boolean fast) {
203:                if (fast == false && (digestMD5 != null && digestSHA != null)) {
204:                    final byte[] dataMD5 = digestMD5.digest(image);
205:                    final byte[] dataSHA = digestSHA.digest(image);
206:                    if (dataSHA != null && dataMD5 != null) {
207:                        return new DigestImageCompareData(dataMD5, dataSHA);
208:                    }
209:                }
210:                return new CompleteImageCompareData(image);
211:            }
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.