Source Code Cross Referenced for MimeBase64Encoder.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:        /**
026:         * Byte to text encoder using base 64 encoding. To create a base 64
027:         * encoding of a byte stream call {@link #translate} for every
028:         * sequence of bytes and {@link #getCharArray} to mark closure of
029:         * the byte stream and retrieve the text presentation.
030:         *
031:         * @author Based on code from the Mozilla Directory SDK
032:         */
033:        public final class MimeBase64Encoder {
034:
035:            private StringBuffer out = new StringBuffer();
036:
037:            private int buf = 0;
038:            private int buf_bytes = 0;
039:            private char[] line = new char[74];
040:            private int line_length = 0;
041:
042:            private final static byte[] crlf = "\r\n".getBytes();
043:
044:            private final static char[] map =
045:
046:            { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
047:                    'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
048:                    'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
049:                    'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
050:                    'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
051:                    '9', '+', '/' };
052:
053:            // 0-7
054:            // 8-15
055:            // 16-23
056:            // 24-31
057:            // 32-39
058:            // 40-47
059:            // 48-55
060:            // 56-63
061:
062:            private final void encode_token() {
063:                int i = line_length;
064:                line[i] = map[0x3F & buf >> 18];
065:                line[i + 1] = map[0x3F & buf >> 12];
066:                line[i + 2] = map[0x3F & buf >> 6];
067:                line[i + 3] = map[0x3F & buf];
068:                line_length += 4;
069:                buf = 0;
070:                buf_bytes = 0;
071:            }
072:
073:            private final void encode_partial_token() {
074:                int i = line_length;
075:                line[i] = map[0x3F & buf >> 18];
076:                line[i + 1] = map[0x3F & buf >> 12];
077:
078:                if (buf_bytes == 1) {
079:                    line[i + 2] = '=';
080:                } else {
081:                    line[i + 2] = map[0x3F & buf >> 6];
082:                }
083:
084:                if (buf_bytes <= 2) {
085:                    line[i + 3] = '=';
086:                } else {
087:                    line[i + 3] = map[0x3F & buf];
088:                }
089:                line_length += 4;
090:                buf = 0;
091:                buf_bytes = 0;
092:            }
093:
094:            private final void flush_line() {
095:                out.append(line, 0, line_length);
096:                line_length = 0;
097:            }
098:
099:            /**
100:             * Given a sequence of input bytes, produces a sequence of output bytes
101:             * using the base64 encoding.  If there are bytes in `out' already, the
102:             * new bytes are appended, so the caller should do `out.setLength(0)'
103:             * first if that's desired.
104:             */
105:            public final void translate(byte[] in) {
106:                int in_length = in.length;
107:
108:                for (int i = 0; i < in_length; i++) {
109:                    if (buf_bytes == 0) {
110:                        buf = buf & 0x00FFFF | in[i] << 16;
111:                    } else if (buf_bytes == 1) {
112:                        buf = buf & 0xFF00FF | in[i] << 8 & 0x00FFFF;
113:                    } else {
114:                        buf = buf & 0xFFFF00 | in[i] & 0x0000FF;
115:                    }
116:
117:                    if (++buf_bytes == 3) {
118:                        encode_token();
119:                        if (line_length >= 72) {
120:                            flush_line();
121:                        }
122:                    }
123:
124:                    if (i == (in_length - 1)) {
125:                        if (buf_bytes > 0 && buf_bytes < 3) {
126:                            encode_partial_token();
127:                        }
128:                        if (line_length > 0) {
129:                            flush_line();
130:                        }
131:                    }
132:                }
133:
134:                for (int i = 0; i < line.length; i++) {
135:                    line[i] = 0;
136:                }
137:            }
138:
139:            public char[] getCharArray() {
140:                char[] ch;
141:
142:                if (buf_bytes != 0) {
143:                    encode_partial_token();
144:                }
145:                flush_line();
146:                for (int i = 0; i < line.length; i++) {
147:                    line[i] = 0;
148:                }
149:                ch = new char[out.length()];
150:                out.getChars(0, out.length(), ch, 0);
151:                return ch;
152:            }
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.