Source Code Cross Referenced for PGPCompressedData.java in  » Security » Bouncy-Castle » org » bouncycastle » openpgp » 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 » Security » Bouncy Castle » org.bouncycastle.openpgp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.bouncycastle.openpgp;
002:
003:        import java.io.EOFException;
004:        import java.io.IOException;
005:        import java.io.InputStream;
006:        import java.util.zip.Inflater;
007:        import java.util.zip.InflaterInputStream;
008:
009:        import org.bouncycastle.bcpg.BCPGInputStream;
010:        import org.bouncycastle.bcpg.CompressedDataPacket;
011:        import org.bouncycastle.bcpg.CompressionAlgorithmTags;
012:        import org.bouncycastle.apache.bzip2.CBZip2InputStream;
013:
014:        /**
015:         * Compressed data objects.
016:         */
017:        public class PGPCompressedData implements  CompressionAlgorithmTags {
018:            CompressedDataPacket data;
019:
020:            public PGPCompressedData(BCPGInputStream pIn) throws IOException {
021:                data = (CompressedDataPacket) pIn.readPacket();
022:            }
023:
024:            /**
025:             * Return the algorithm used for compression
026:             * 
027:             * @return algorithm code
028:             */
029:            public int getAlgorithm() {
030:                return data.getAlgorithm();
031:            }
032:
033:            /**
034:             * Return the raw input stream contained in the object.
035:             * 
036:             * @return InputStream
037:             */
038:            public InputStream getInputStream() {
039:                return data.getInputStream();
040:            }
041:
042:            /**
043:             * Return an uncompressed input stream which allows reading of the 
044:             * compressed data.
045:             * 
046:             * @return InputStream
047:             * @throws PGPException
048:             */
049:            public InputStream getDataStream() throws PGPException {
050:                if (this .getAlgorithm() == UNCOMPRESSED) {
051:                    return this .getInputStream();
052:                }
053:                if (this .getAlgorithm() == ZIP) {
054:                    return new InflaterInputStream(this .getInputStream(),
055:                            new Inflater(true)) {
056:                        // If the "nowrap" inflater option is used the stream can 
057:                        // apparently overread - we override fill() and provide
058:                        // an extra byte for the end of the input stream to get
059:                        // around this.
060:                        //
061:                        // Totally weird...
062:                        //
063:                        protected void fill() throws IOException {
064:                            if (eof) {
065:                                throw new EOFException(
066:                                        "Unexpected end of ZIP input stream");
067:                            }
068:
069:                            len = this .in.read(buf, 0, buf.length);
070:
071:                            if (len == -1) {
072:                                buf[0] = 0;
073:                                len = 1;
074:                                eof = true;
075:                            }
076:
077:                            inf.setInput(buf, 0, len);
078:                        }
079:
080:                        private boolean eof = false;
081:                    };
082:                }
083:                if (this .getAlgorithm() == ZLIB) {
084:                    return new InflaterInputStream(this .getInputStream()) {
085:                        // If the "nowrap" inflater option is used the stream can 
086:                        // apparently overread - we override fill() and provide
087:                        // an extra byte for the end of the input stream to get
088:                        // around this.
089:                        //
090:                        // Totally weird...
091:                        //
092:                        protected void fill() throws IOException {
093:                            if (eof) {
094:                                throw new EOFException(
095:                                        "Unexpected end of ZIP input stream");
096:                            }
097:
098:                            len = this .in.read(buf, 0, buf.length);
099:
100:                            if (len == -1) {
101:                                buf[0] = 0;
102:                                len = 1;
103:                                eof = true;
104:                            }
105:
106:                            inf.setInput(buf, 0, len);
107:                        }
108:
109:                        private boolean eof = false;
110:                    };
111:                }
112:                if (this .getAlgorithm() == BZIP2) {
113:                    try {
114:                        return new CBZip2InputStream(this .getInputStream());
115:                    } catch (IOException e) {
116:                        throw new PGPException("I/O problem with stream: " + e,
117:                                e);
118:                    }
119:                }
120:
121:                throw new PGPException(
122:                        "can't recognise compression algorithm: "
123:                                + this.getAlgorithm());
124:            }
125:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.