Source Code Cross Referenced for ASCII85Decode.java in  » PDF » PDF-Renderer » com » sun » pdfview » decode » 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 » PDF » PDF Renderer » com.sun.pdfview.decode 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: ASCII85Decode.java,v 1.2 2007/12/20 18:33:33 rbair Exp $
003:         *
004:         * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005:         * Santa Clara, California 95054, U.S.A. All rights reserved.
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         * 
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         * 
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
020:         */
021:
022:        package com.sun.pdfview.decode;
023:
024:        import java.io.ByteArrayOutputStream;
025:        import java.nio.ByteBuffer;
026:
027:        import com.sun.pdfview.PDFFile;
028:        import com.sun.pdfview.PDFObject;
029:        import com.sun.pdfview.PDFParseException;
030:
031:        /**
032:         * decode ASCII85 text into a byte array.
033:         * 
034:         * @author Mike Wessler
035:         */
036:        public class ASCII85Decode {
037:            private ByteBuffer buf;
038:
039:            /**
040:             * initialize the decoder with byte buffer in ASCII85 format
041:             */
042:            private ASCII85Decode(ByteBuffer buf) {
043:                this .buf = buf;
044:            }
045:
046:            /**
047:             * get the next character from the input.
048:             * @return the next character, or -1 if at end of stream
049:             */
050:            private int nextChar() {
051:                // skip whitespace
052:                // returns next character, or -1 if end of stream
053:                while (buf.remaining() > 0) {
054:                    char c = (char) buf.get();
055:
056:                    if (!PDFFile.isWhiteSpace(c)) {
057:                        return c;
058:                    }
059:                }
060:
061:                // EOF reached
062:                return -1;
063:            }
064:
065:            /**
066:             * decode the next five ASCII85 characters into up to four decoded
067:             * bytes.  Return false when finished, or true otherwise.
068:             *
069:             * @param baos the ByteArrayOutputStream to write output to, set to the
070:             *        correct position
071:             * @return false when finished, or true otherwise.
072:             */
073:            private boolean decode5(ByteArrayOutputStream baos)
074:                    throws PDFParseException {
075:                // stream ends in ~>
076:                int[] five = new int[5];
077:                int i;
078:                for (i = 0; i < 5; i++) {
079:                    five[i] = nextChar();
080:                    if (five[i] == '~') {
081:                        if (nextChar() == '>') {
082:                            break;
083:                        } else {
084:                            throw new PDFParseException(
085:                                    "Bad character in ASCII85Decode: not ~>");
086:                        }
087:                    } else if (five[i] >= '!' && five[i] <= 'u') {
088:                        five[i] -= '!';
089:                    } else if (five[i] == 'z') {
090:                        if (i == 0) {
091:                            five[i] = 0;
092:                            i = 4;
093:                        } else {
094:                            throw new PDFParseException(
095:                                    "Inappropriate 'z' in ASCII85Decode");
096:                        }
097:                    } else {
098:                        throw new PDFParseException(
099:                                "Bad character in ASCII85Decode: " + five[i]
100:                                        + " (" + (char) five[i] + ")");
101:                    }
102:                }
103:
104:                if (i > 0) {
105:                    i -= 1;
106:                }
107:
108:                int value = five[0] * 85 * 85 * 85 * 85 + five[1] * 85 * 85
109:                        * 85 + five[2] * 85 * 85 + five[3] * 85 + five[4];
110:
111:                for (int j = 0; j < i; j++) {
112:                    int shift = 8 * (3 - j);
113:                    baos.write((byte) ((value >> shift) & 0xff));
114:                }
115:
116:                return (i == 4);
117:            }
118:
119:            /**
120:             * decode the bytes
121:             * @return the decoded bytes
122:             */
123:            private ByteBuffer decode() throws PDFParseException {
124:                // start from the beginning of the data
125:                buf.rewind();
126:
127:                // allocate the output buffer
128:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
129:
130:                // decode the bytes 
131:                while (decode5(baos)) {
132:                }
133:
134:                return ByteBuffer.wrap(baos.toByteArray());
135:            }
136:
137:            /**
138:             * decode an array of bytes in ASCII85 format.
139:             * <p>
140:             * In ASCII85 format, every 5 characters represents 4 decoded
141:             * bytes in base 85.  The entire stream can contain whitespace,
142:             * and ends in the characters '~&gt;'.
143:             *
144:             * @param buf the encoded ASCII85 characters in a byte buffer
145:             * @param params parameters to the decoder (ignored)
146:             * @return the decoded bytes
147:             */
148:            public static ByteBuffer decode(ByteBuffer buf, PDFObject params)
149:                    throws PDFParseException {
150:                ASCII85Decode me = new ASCII85Decode(buf);
151:                return me.decode();
152:            }
153:
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.