Source Code Cross Referenced for MimeOutputStream.java in  » Test-Coverage » GroboUtils » net » sourceforge » groboutils » util » io » v1 » 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 » Test Coverage » GroboUtils » net.sourceforge.groboutils.util.io.v1 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * MimeOutputStream.java - A Filter stream for MIME encoding
003:         *
004:         * Copyright (C) 2000,,2003 2002 Matt Albrecht
005:         * groboclown@users.sourceforge.net
006:         * http://groboutils.sourceforge.net
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU Lesser General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or (at your option) any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU Lesser General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU Lesser General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         */
022:
023:        package net.sourceforge.groboutils.util.io.v1;
024:
025:        import java.io.FilterOutputStream;
026:        import java.io.OutputStream;
027:        import java.io.IOException;
028:        import java.awt.TextComponent;
029:
030:        /**
031:         * java.io.FilterOutputStream implementation for Mime base 64. Not incredibly
032:         * efficient, but it works and is small.
033:         * <P>
034:         * All we need to implement are:
035:         * <ul>
036:         *     <li>write(int)</li>
037:         *     <li>flush()</li>
038:         * </ul>
039:         *
040:         * @author   Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
041:         * @since    0.9.0 Alpha (early 2000)
042:         * @version  $Date: 2003/02/10 22:52:45 $
043:         */
044:        public class MimeOutputStream extends FilterOutputStream {
045:            private int bits = 0, spare = 0;
046:
047:            /**
048:             * Mime character set translation
049:             */
050:            private static final int[] charset = { 'A', 'B', 'C', 'D', 'E',
051:                    'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
052:                    'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c',
053:                    'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
054:                    'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0',
055:                    '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };
056:            private static final int pad = '=';
057:
058:            /** Constructor! */
059:            public MimeOutputStream(OutputStream o) {
060:                super (o);
061:            }
062:
063:            /**
064:             * Write the specified <code>byte</code>, performing mime encoding.
065:             *
066:             * <p>Override this method, since all other write methods call it.
067:             *
068:             * @exception  IOException  If an I/O error occurs
069:             */
070:            public void write(int c) throws IOException {
071:                int s, t;
072:                switch (bits) {
073:                case 0:
074:                    bits++;
075:                    s = (c >> 2) & 0x3f;
076:                    spare = c & 0x03;
077:                    out.write(charset[s]);
078:                    break;
079:                case 1:
080:                    bits++;
081:                    s = (spare << 4) | ((c >> 4) & 0x0f);
082:                    spare = c & 0x0f;
083:                    out.write(charset[s]);
084:                    break;
085:                case 2:
086:                    bits = 0;
087:                    s = (spare << 2) | ((c >> 6) & 0x03);
088:                    t = c & 0x3f;
089:                    out.write(charset[s]);
090:                    out.write(charset[t]);
091:                    break;
092:                }
093:            }
094:
095:            /**
096:             * Flush the stream.  If the stream has saved any characters from the
097:             * various write() methods in a buffer, write them immediately to their
098:             * intended destination.  Then, if that destination is another character or
099:             * byte stream, flush it.  Thus one flush() invocation will flush all the
100:             * buffers in a chain of Writers and OutputStreams.
101:             * <P>
102:             * This version does not buffer, but Mime encoding may have some trailing
103:             * stuff, which needs padding.
104:             *
105:             * @exception  IOException  If an I/O error occurs
106:             */
107:            public void flush() throws IOException {
108:                switch (bits) {
109:                case 1:
110:                    out.write(charset[spare << 4]);
111:                    out.write(pad);
112:                    out.write(pad);
113:                    break;
114:                case 2:
115:                    out.write(charset[spare << 2]);
116:                    out.write(pad);
117:                    break;
118:                }
119:                super.flush();
120:            }
121:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.