Source Code Cross Referenced for MD5InputStream.java in  » Template-Engine » ostermillerutils » com » Ostermiller » 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 » Template Engine » ostermillerutils » com.Ostermiller.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Implements MD5 functionality on a stream.
003:         *
004:         * written Santeri Paavolainen, Helsinki Finland 1996
005:         * (c) Santeri Paavolainen, Helsinki Finland 1996
006:         * modifications Copyright (C) 2002 Stephen Ostermiller
007:         * http://ostermiller.org/contact.pl?regarding=Java+Utilities
008:         *
009:         * This program is free software; you can redistribute it and/or modify
010:         * it under the terms of the GNU General Public License as published by
011:         * the Free Software Foundation; either version 2 of the License, or
012:         * (at your option) any later version.
013:         *
014:         * This program is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017:         * GNU General Public License for more details.
018:         *
019:         * See COPYING.TXT for details.
020:         *
021:         * The original work by Santeri Paavolainen can be found a
022:         * http://www.helsinki.fi/~sjpaavol/programs/md5/
023:         */
024:        package com.Ostermiller.util;
025:
026:        import java.io.*;
027:
028:        /**
029:         * Implements MD5 functionality on a stream.
030:         * More information about this class is available from <a target="_top" href=
031:         * "http://ostermiller.org/utils/MD5.html">ostermiller.org</a>.
032:         * <p>
033:         * This class produces a 128-bit "fingerprint" or "message digest" for
034:         * all data read from this stream.
035:         * It is conjectured that it is computationally infeasible to produce
036:         * two messages having the same message digest, or to produce any
037:         * message having a given pre-specified target message digest. The MD5
038:         * algorithm is intended for digital signature applications, where a
039:         * large file must be "compressed" in a secure manner before being
040:         * encrypted with a private (secret) key under a public-key cryptosystem
041:         * such as RSA.
042:         * <p>
043:         * For more information see RFC1321.
044:         *
045:         * @see MD5
046:         * @see MD5OutputStream
047:         *
048:         * @author Santeri Paavolainen http://www.helsinki.fi/~sjpaavol/programs/md5/
049:         * @author Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities
050:         * @since ostermillerutils 1.00.00
051:         */
052:        public class MD5InputStream extends FilterInputStream {
053:            /**
054:             * MD5 context
055:             */
056:            private MD5 md5;
057:
058:            /**
059:             * Creates a MD5InputStream
060:             * @param in the underlying input stream
061:             */
062:            public MD5InputStream(InputStream in) {
063:                super (in);
064:                md5 = new MD5();
065:            }
066:
067:            /**
068:             * Reads the next byte of data from this input stream. The value byte
069:             * is returned as an int in the range 0 to 255. If no byte is available
070:             * because the end of the stream has been reached, the value -1 is returned.
071:             * This method blocks until input data is available, the end of the stream is
072:             * detected, or an exception is thrown.
073:             * <p>
074:             * This method simply performs in.read() and returns the result.
075:             *
076:             * @return the next byte of data, or -1 if the end of the stream is reached.
077:             * @throws IOException if an I/O error occurs.
078:             *
079:             * @since ostermillerutils 1.00.00
080:             */
081:            @Override
082:            public int read() throws IOException {
083:                int c = in.read();
084:                if (c == -1) {
085:                    return -1;
086:                }
087:                md5.update((byte) (c & 0xff));
088:                return c;
089:            }
090:
091:            /**
092:             * Reads up to length bytes of data from this input stream into an
093:             * array of bytes. This method blocks until some input is available.
094:             *
095:             * @param bytes the buffer into which the data is read.
096:             * @param offset the start offset of the data.
097:             * @param length the maximum number of bytes read.
098:             * @throws IOException if an I/O error occurs.
099:             *
100:             * @since ostermillerutils 1.00.00
101:             */
102:            @Override
103:            public int read(byte[] bytes, int offset, int length)
104:                    throws IOException {
105:                int r;
106:                if ((r = in.read(bytes, offset, length)) == -1) {
107:                    return r;
108:                }
109:                md5.update(bytes, offset, r);
110:                return r;
111:            }
112:
113:            /**
114:             * Returns array of bytes representing hash of the stream so far.
115:             *
116:             * @return Array of 16 bytes, the hash of all read bytes.
117:             *
118:             * @since ostermillerutils 1.00.00
119:             */
120:            public byte[] getHash() {
121:                return md5.getHash();
122:            }
123:
124:            /**
125:             * Get a 32-character hex representation representing hash of the stream so far.
126:             *
127:             * @return A string containing  the hash of all written bytes.
128:             *
129:             * @since ostermillerutils 1.00.00
130:             */
131:            public String getHashString() {
132:                return md5.getHashString();
133:            }
134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.