Source Code Cross Referenced for CompressionOutputStream.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » service » rmi » socket » 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 » ERP CRM Financial » SourceTap CRM » org.ofbiz.service.rmi.socket 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: CompressionOutputStream.java,v 1.1 2003/12/02 06:39:32 ajzeneski Exp $
003:         *
004:         * Copyright (c) 1998, 1999 Sun Microsystems, Inc. All Rights Reserved.
005:         *
006:         * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
007:         * modify and redistribute this software in source and binary code form,
008:         * provided that i) this copyright notice and license appear on all copies of
009:         * the software; and ii) Licensee does not utilize the software in a manner
010:         * which is disparaging to Sun.
011:         *
012:         * This software is provided "AS IS," without a warranty of any kind. ALL
013:         * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
014:         * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
015:         * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
016:         * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
017:         * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
018:         * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
019:         * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
020:         * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
021:         * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
022:         * POSSIBILITY OF SUCH DAMAGES.
023:         *
024:         * This software is not designed or intended for use in on-line control of
025:         * aircraft, air traffic, aircraft navigation or aircraft communications; or in
026:         * the design, construction, operation or maintenance of any nuclear
027:         * facility. Licensee represents and warrants that it will not use or
028:         * redistribute the Software for such purposes.
029:         */
030:
031:        package org.ofbiz.service.rmi.socket;
032:
033:        import java.io.FilterOutputStream;
034:        import java.io.IOException;
035:        import java.io.OutputStream;
036:
037:        class CompressionOutputStream extends FilterOutputStream implements 
038:                CompressionConstants {
039:
040:            /*
041:             * Constructor calls constructor of superclass.
042:             */
043:            public CompressionOutputStream(OutputStream out) {
044:                super (out);
045:            }
046:
047:            /*
048:             * Buffer of 6-bit codes to pack into next 32-bit word
049:             * Five 6-bit codes fit into 4 words.
050:             */
051:            int buf[] = new int[5];
052:
053:            /*
054:             * Index of valid codes waiting in buf.
055:             */
056:            int bufPos = 0;
057:
058:            /*
059:             * This method writes one byte to the socket stream.
060:             */
061:            public void write(int b) throws IOException {
062:                // force argument to one byte
063:                b &= 0xFF;
064:
065:                // Look up pos in codeTable to get its encoding.
066:                int pos = codeTable.indexOf((char) b);
067:
068:                if (pos != -1) {
069:                    // If pos is in the codeTable, write BASE + pos into buf.
070:                    // By adding BASE to pos, we know that the characters in
071:                    // the codeTable will always have a code between 2 and 63
072:                    // inclusive. This allows us to use RAW (RAW is equal to
073:                    // 1) to signify that the next two groups of 6-bits are
074:                    // necessary for decompression of the next character.
075:
076:                    writeCode(BASE + pos);
077:                } else {
078:                    // Otherwise, write RAW into buf to signify that the
079:                    // Character is being sent in 12 bits.
080:                    writeCode(RAW);
081:
082:                    // Write the last 4 bits of b into the buf.
083:                    writeCode(b >> 4);
084:
085:                    // Truncate b to contain data in only the first 4 bits,
086:                    // and write the first 4 bits of b into buf.
087:                    writeCode(b & 0xF);
088:                }
089:            }
090:
091:            /*
092:             * This method writes up to len bytes to the socket stream.
093:             */
094:            public void write(byte b[], int off, int len) throws IOException {
095:                /*
096:                 * This implementation is quite inefficient because it has to
097:                 * call the other write method for every byte in the array.  It
098:                 * could be optimized for performance by doing all the processing
099:                 * in this method.
100:                 */
101:                for (int i = 0; i < len; i++)
102:                    write(b[off + i]);
103:            }
104:
105:            /*
106:             * Clears buffer of all data (zeroes it out).
107:             */
108:            public void flush() throws IOException {
109:                while (bufPos > 0)
110:                    writeCode(NOP);
111:            }
112:
113:            /*
114:             * This method actually puts the data into the output stream after
115:             * packing the data from all 5 bytes in buf into one word.
116:             * Remember, each byte has, at most, 6 significant bits.
117:             */
118:            private void writeCode(int c) throws IOException {
119:                buf[bufPos++] = c;
120:                if (bufPos == 5) { // write next word when we have 5 codes
121:                    int pack = (buf[0] << 24) | (buf[1] << 18) | (buf[2] << 12)
122:                            | (buf[3] << 6) | buf[4];
123:                    out.write((pack >>> 24) & 0xFF);
124:                    out.write((pack >>> 16) & 0xFF);
125:                    out.write((pack >>> 8) & 0xFF);
126:                    out.write((pack >>> 0) & 0xFF);
127:                    bufPos = 0;
128:                }
129:            }
130:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.