Source Code Cross Referenced for MimeBase64Decoder.java in  » Database-DBMS » Ozone-1.1 » org » ozoneDB » 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 » Database DBMS » Ozone 1.1 » org.ozoneDB.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * The contents of this file are subject to the Netscape Public
004:         * License Version 1.1 (the "License"); you may not use this file
005:         * except in compliance with the License. You may obtain a copy of
006:         * the License at http://www.mozilla.org/NPL/
007:         *
008:         * Software distributed under the License is distributed on an "AS
009:         * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
010:         * implied. See the License for the specific language governing
011:         * rights and limitations under the License.
012:         *
013:         * The Original Code is mozilla.org code.
014:         *
015:         * The Initial Developer of the Original Code is Netscape
016:         * Communications Corporation.  Portions created by Netscape are
017:         * Copyright (C) 1999 Netscape Communications Corporation. All
018:         * Rights Reserved.
019:         *
020:         * Contributor(s): 
021:         */
022:
023:        package org.ozoneDB.util;
024:
025:        import java.io.ByteArrayOutputStream;
026:
027:        /**
028:         * Base 64 text to byte decoded. To produce the binary  array from
029:         * base 64 encoding call {@link #translate} for each sequence of
030:         * characters and {@link #getByteArray} to mark closure of the
031:         * character stream and retrieve the binary contents.
032:         *
033:         * @author Based on code from the Mozilla Directory SDK
034:         */
035:        public final class MimeBase64Decoder {
036:
037:            private ByteArrayOutputStream out = new ByteArrayOutputStream();
038:
039:            private byte[] token = new byte[4];
040:            private byte[] bytes = new byte[3];
041:            private int token_length = 0;
042:
043:            private final static byte NUL = 127;
044:            private final static byte EOF = 126;
045:
046:            private final static byte[] map =
047:
048:            { NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
049:                    NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
050:                    NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
051:                    NUL, NUL, NUL, NUL, NUL, NUL, 62, NUL, NUL, NUL, 63, 52,
052:                    53, 54, 55, 56, 57, 58, 59, 60, 61, NUL, NUL, NUL, EOF,
053:                    NUL, NUL, NUL, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
054:                    13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NUL,
055:                    NUL, NUL, NUL, NUL, NUL, 26, 27, 28, 29, 30, 31, 32, 33,
056:                    34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
057:                    49, 50, 51, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
058:                    NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
059:                    NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
060:                    NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
061:                    NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
062:                    NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
063:                    NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
064:                    NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
065:                    NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
066:                    NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
067:                    NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
068:                    NUL, NUL, NUL, NUL };
069:
070:            //   000-007
071:            //   010-017
072:            //   020-027
073:            //   030-037
074:            //   040-047   !"#$%&'
075:            //   050-057  ()*+,-./
076:            //   060-067  01234567
077:            //   070-077  89:;<=>?
078:
079:            //   100-107  @ABCDEFG
080:            //   110-117  HIJKLMNO
081:            //   120-127  PQRSTUVW
082:            //   130-137  XYZ[\]^_
083:            //   140-147  `abcdefg
084:            //   150-157  hijklmno
085:            //   160-167  pqrstuvw
086:            //   170-177  xyz{|}~
087:
088:            //   200-207
089:            //   210-217
090:            //   220-227
091:            //   230-237
092:            //   240-247
093:            //   250-257
094:            //   260-267
095:            //   270-277
096:
097:            //   300-307
098:            //   310-317
099:            //   320-327
100:            //   330-337
101:            //   340-347
102:            //   350-357
103:            //   360-367
104:            //   370-377
105:
106:            // Fast routine that assumes full 4-char tokens with no '=' in them.
107:            //
108:            private void decode_token() {
109:                int num = token[0] << 18 | token[1] << 12 | token[2] << 6
110:                        | token[3];
111:
112:                bytes[0] = (byte) (0xFF & num >> 16);
113:                bytes[1] = (byte) (0xFF & num >> 8);
114:                bytes[2] = (byte) (0xFF & num);
115:
116:                out.write(bytes, 0, 3);
117:            }
118:
119:            // Hairier routine that deals with the final token, which can have fewer
120:            // than four characters, and that might be padded with '='.
121:            //
122:            private final void decode_final_token() {
123:
124:                byte b0 = token[0];
125:                byte b1 = token[1];
126:                byte b2 = token[2];
127:                byte b3 = token[3];
128:
129:                int eq_count = 0;
130:
131:                if (b0 == EOF) {
132:                    b0 = 0;
133:                    eq_count++;
134:                }
135:                if (b1 == EOF) {
136:                    b1 = 0;
137:                    eq_count++;
138:                }
139:                if (b2 == EOF) {
140:                    b2 = 0;
141:                    eq_count++;
142:                }
143:                if (b3 == EOF) {
144:                    b3 = 0;
145:                    eq_count++;
146:                }
147:
148:                int num = b0 << 18 | b1 << 12 | b2 << 6 | b3;
149:
150:                // eq_count will be 0, 1, or 2.
151:                // No "=" padding means 4 bytes mapped to 3, the normal case,
152:                //        not handled in this routine.
153:                // "xxx=" means 3 bytes mapped to 2.
154:                // "xx==" means 2 bytes mapped to 1.
155:                // "x===" can't happen, because "x" would then be encoding
156:                //        only 6 bits, not 8, the minimum possible.
157:
158:                out.write((byte) (num >> 16));
159:                if (eq_count <= 1) {
160:                    out.write((byte) (num >> 8 & 0xFF));
161:                    if (eq_count == 0) {
162:                        out.write((byte) (num & 0xFF));
163:                    }
164:                }
165:            }
166:
167:            public final void translate(char[] ch) {
168:                translate(ch, 0, ch.length);
169:            }
170:
171:            public final void translate(char[] ch, int offset, int length) {
172:
173:                if (token == null) {
174:                    return;
175:                }
176:
177:                for (int i = offset; i < offset + length; i++) {
178:                    byte t = map[ch[i] & 0xff];
179:
180:                    if (t == EOF) {
181:                        eof();
182:                    } else {
183:                        if (t != NUL) {
184:                            token[token_length++] = t;
185:                        }
186:                    }
187:                    if (token_length == 4) {
188:                        decode_token();
189:                        token_length = 0;
190:                    }
191:                }
192:            }
193:
194:            private void eof() {
195:                if (token != null && token_length != 0) {
196:                    while (token_length < 4) {
197:                        token[token_length++] = EOF;
198:                    }
199:                    decode_final_token();
200:                }
201:                token_length = 0;
202:                token = new byte[4];
203:                bytes = new byte[3];
204:            }
205:
206:            public byte[] getByteArray() {
207:                eof();
208:                return out.toByteArray();
209:            }
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.