Source Code Cross Referenced for ASCIIHexDecode.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: ASCIIHexDecode.java,v 1.2 2007/12/20 18:33:32 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.PDFObject;
028:        import com.sun.pdfview.PDFParseException;
029:        import com.sun.pdfview.PDFFile;
030:
031:        /**
032:         * decode an array of hex nybbles into a byte array
033:         *
034:         * @author Mike Wessler
035:         */
036:        public class ASCIIHexDecode {
037:            private ByteBuffer buf;
038:
039:            /**
040:             * initialize the decoder with an array of bytes in ASCIIHex format
041:             */
042:            private ASCIIHexDecode(ByteBuffer buf) {
043:                this .buf = buf;
044:            }
045:
046:            /**
047:             * get the next character from the input
048:             * @return a number from 0-15, or -1 for the end character
049:             */
050:            private int readHexDigit() throws PDFParseException {
051:                // read until we hit a non-whitespace character or the
052:                // end of the stream
053:                while (buf.remaining() > 0) {
054:                    int c = (int) buf.get();
055:
056:                    // see if we found a useful character
057:                    if (!PDFFile.isWhiteSpace((char) c)) {
058:                        if (c >= '0' && c <= '9') {
059:                            c -= '0';
060:                        } else if (c >= 'a' && c <= 'f') {
061:                            c -= 'a' - 10;
062:                        } else if (c >= 'A' && c <= 'F') {
063:                            c -= 'A' - 10;
064:                        } else if (c == '>') {
065:                            c = -1;
066:                        } else {
067:                            // unknown character
068:                            throw new PDFParseException("Bad character " + c
069:                                    + "in ASCIIHex decode");
070:                        }
071:
072:                        // return the useful character
073:                        return c;
074:                    }
075:                }
076:
077:                // end of stream reached
078:                throw new PDFParseException("Short stream in ASCIIHex decode");
079:            }
080:
081:            /**
082:             * decode the array
083:             * @return the decoded bytes
084:             */
085:            private ByteBuffer decode() throws PDFParseException {
086:                // start at the beginning of the buffer
087:                buf.rewind();
088:
089:                // allocate the output buffer
090:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
091:
092:                while (true) {
093:                    int first = readHexDigit();
094:                    int second = readHexDigit();
095:
096:                    if (first == -1) {
097:                        break;
098:                    } else if (second == -1) {
099:                        baos.write((byte) (first << 4));
100:                        break;
101:                    } else {
102:                        baos.write((byte) ((first << 4) + second));
103:                    }
104:                }
105:
106:                return ByteBuffer.wrap(baos.toByteArray());
107:            }
108:
109:            /**
110:             * decode an array of bytes in ASCIIHex format.
111:             * <p>
112:             * ASCIIHex format consists of a sequence of Hexidecimal
113:             * digits, with possible whitespace, ending with the
114:             * '&gt;' character.
115:             * 
116:             * @param buf the encoded ASCII85 characters in a byte
117:             *        buffer
118:             * @param params parameters to the decoder (ignored)
119:             * @return the decoded bytes
120:             */
121:            public static ByteBuffer decode(ByteBuffer buf, PDFObject params)
122:                    throws PDFParseException {
123:                ASCIIHexDecode me = new ASCIIHexDecode(buf);
124:                return me.decode();
125:            }
126:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.