Source Code Cross Referenced for DataInputCompressor.java in  » Internationalization-Localization » icu4j » com » ibm » icu » dev » test » 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 » Internationalization Localization » icu4j » com.ibm.icu.dev.test.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //##header
002:        /*
003:         *******************************************************************************
004:         * Copyright (C) 1996-2006, International Business Machines Corporation and    *
005:         * others. All Rights Reserved.                                                *
006:         *******************************************************************************
007:         */
008:        //#ifndef FOUNDATION
009:        package com.ibm.icu.dev.test.util;
010:
011:        import java.io.DataInput;
012:        import java.io.IOException;
013:        import java.io.ObjectInput;
014:        import java.util.ArrayList;
015:        import java.util.Collection; //import java.util.HashMap;
016:        import java.util.LinkedHashSet;
017:        import java.util.List; //import java.util.Map;
018:
019:        //import com.ibm.icu.impl.Utility;
020:        import com.ibm.icu.text.UTF16;
021:
022:        /**
023:         * Simple data input compressor. Nothing fancy, but much smaller footprint for
024:         * ints and many strings.
025:         */
026:        public final class DataInputCompressor implements  ObjectInput {
027:            static final boolean SHOW = false;
028:
029:            private ObjectInput dataInput;
030:
031:            private transient StringBuffer stringBuffer = new StringBuffer();
032:
033:            public DataInputCompressor(ObjectInput dataInput) {
034:                this .dataInput = dataInput;
035:            }
036:
037:            public DataInput getDataInput() {
038:                return dataInput;
039:            }
040:
041:            public void setDataInput(ObjectInput dataInput) {
042:                this .dataInput = dataInput;
043:            }
044:
045:            public boolean readBoolean() throws IOException {
046:                return dataInput.readBoolean();
047:            }
048:
049:            public byte readByte() throws IOException {
050:                return dataInput.readByte();
051:            }
052:
053:            public int readUnsignedByte() throws IOException {
054:                return dataInput.readUnsignedByte();
055:            }
056:
057:            public double readDouble() throws IOException {
058:                return dataInput.readDouble();
059:            }
060:
061:            public float readFloat() throws IOException {
062:                return dataInput.readFloat();
063:            }
064:
065:            public void readFully(byte[] b) throws IOException {
066:                dataInput.readFully(b);
067:            }
068:
069:            public void readFully(byte[] b, int off, int len)
070:                    throws IOException {
071:                dataInput.readFully(b, off, len);
072:            }
073:
074:            public int skipBytes(int n) throws IOException {
075:                return dataInput.skipBytes(n);
076:            }
077:
078:            public String readLine() throws IOException {
079:                return dataInput.readLine();
080:            }
081:
082:            public int available() throws IOException {
083:                return dataInput.available();
084:            }
085:
086:            public void close() throws IOException {
087:                dataInput.close();
088:            }
089:
090:            public int read() throws IOException {
091:                return dataInput.read();
092:            }
093:
094:            public int read(byte[] b) throws IOException {
095:                return dataInput.read(b);
096:            }
097:
098:            public int read(byte[] b, int off, int len) throws IOException {
099:                return dataInput.read(b, off, len);
100:            }
101:
102:            public Object readObject() throws ClassNotFoundException,
103:                    IOException {
104:                return dataInput.readObject();
105:            }
106:
107:            public long skip(long n) throws IOException {
108:                return dataInput.skip(n);
109:            }
110:
111:            public String toString() {
112:                return dataInput.toString();
113:            }
114:
115:            // ==== New Routines ====
116:
117:            public char readChar() throws IOException {
118:                return (char) readULong();
119:            }
120:
121:            public short readShort() throws IOException {
122:                return (short) readLong();
123:            }
124:
125:            public int readUnsignedShort() throws IOException {
126:                return (int) readULong();
127:            }
128:
129:            public int readUShort() throws IOException {
130:                return (int) readULong();
131:            }
132:
133:            public int readInt() throws IOException {
134:                return (int) readLong();
135:            }
136:
137:            public int readUInt() throws IOException {
138:                return (int) readULong();
139:            }
140:
141:            public String readChars(int len) throws IOException {
142:                stringBuffer.setLength(0);
143:                for (int i = 0; i < len; ++i) {
144:                    int cp = (int) readULong();
145:                    UTF16.append(stringBuffer, cp);
146:                }
147:                return stringBuffer.toString();
148:            }
149:
150:            public String readUTF() throws IOException {
151:                int len = (int) readULong();
152:                return readChars(len);
153:            }
154:
155:            public long readLong() throws IOException {
156:                long result = 0;
157:                int offset = 0;
158:                while (true) {
159:                    long input = readByte();
160:                    result |= (input & 0x7F) << offset;
161:                    if ((input & 0x80) == 0)
162:                        break;
163:                    offset += 7;
164:                }
165:                boolean negative = (result & 1) != 0; // get sign bit from the bottom,
166:                // and invert
167:                result >>>= 1;
168:                if (negative)
169:                    result = ~result;
170:                return result;
171:            }
172:
173:            public long readULong() throws IOException {
174:                long result = 0;
175:                int offset = 0;
176:                while (true) { // read sequence of 7 bits, with top bit = 1 for
177:                    // continuation
178:                    int input = readByte();
179:                    result |= (input & 0x7F) << offset;
180:                    if ((input & 0x80) == 0)
181:                        return result;
182:                    offset += 7;
183:                }
184:            }
185:
186:            /**
187:             *  
188:             */
189:            public Object[] readStringSet(Collection availableValues)
190:                    throws IOException {
191:                int size = readUInt();
192:                if (SHOW)
193:                    System.out.println("readStringSet");
194:                Object[] valuesList = new Object[size + 1];
195:                // first item is null
196:                String lastString = "";
197:                ReadPool trailingPool = new ReadPool();
198:                for (int i = 0; i < size; ++i) {
199:                    int common = readUInt();
200:                    boolean inPool = (common & 1) != 0;
201:                    common >>>= 1;
202:                    if (SHOW)
203:                        System.out.println(common);
204:                    String current;
205:                    if (inPool) {
206:                        int poolIndex = readUInt();
207:                        if (SHOW)
208:                            System.out.println("\t" + poolIndex);
209:                        current = (String) trailingPool.get(poolIndex);
210:                    } else {
211:                        current = readUTF();
212:                        trailingPool.add(current);
213:                    }
214:                    valuesList[i + 1] = lastString = lastString.substring(0,
215:                            common)
216:                            + current;
217:                    if (SHOW)
218:                        System.out.println("\t\t" + lastString);
219:                    if (availableValues != null)
220:                        availableValues.add(current);
221:                }
222:                return valuesList;
223:            }
224:
225:            public static class ReadPool {
226:                private List trailingPool = new ArrayList();
227:
228:                public Object get(int index) {
229:                    return trailingPool.get(index);
230:                }
231:
232:                public void add(Object o) {
233:                    trailingPool.add(o);
234:                }
235:            }
236:
237:            /**
238:             * @throws IOException
239:             * @throws ClassNotFoundException
240:             * 
241:             */
242:            public Object[] readCollection(LinkedHashSet availableValues)
243:                    throws ClassNotFoundException, IOException {
244:                int size = readUInt();
245:                Object[] valuesList = new Object[size + 1];
246:                for (int i = 0; i < size; ++i) {
247:                    valuesList[i + 1] = readObject();
248:                }
249:                return valuesList;
250:            }
251:        }
252:        //#endif
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.