Source Code Cross Referenced for Encoder.java in  » ERP-CRM-Financial » Personal-Finance-Manager » SevenZip » Compression » RangeCoder » 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 » Personal Finance Manager » SevenZip.Compression.RangeCoder 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package SevenZip.Compression.RangeCoder;
002:
003:        import java.io.IOException;
004:
005:        public class Encoder {
006:            static final int kTopMask = ~((1 << 24) - 1);
007:
008:            static final int kNumBitModelTotalBits = 11;
009:            static final int kBitModelTotal = (1 << kNumBitModelTotalBits);
010:            static final int kNumMoveBits = 5;
011:
012:            java.io.OutputStream Stream;
013:
014:            long Low;
015:            int Range;
016:            int _cacheSize;
017:            int _cache;
018:
019:            long _position;
020:
021:            public void SetStream(java.io.OutputStream stream) {
022:                Stream = stream;
023:            }
024:
025:            public void ReleaseStream() {
026:                Stream = null;
027:            }
028:
029:            public void Init() {
030:                _position = 0;
031:                Low = 0;
032:                Range = -1;
033:                _cacheSize = 1;
034:                _cache = 0;
035:            }
036:
037:            public void FlushData() throws IOException {
038:                for (int i = 0; i < 5; i++)
039:                    ShiftLow();
040:            }
041:
042:            public void FlushStream() throws IOException {
043:                Stream.flush();
044:            }
045:
046:            public void ShiftLow() throws IOException {
047:                int LowHi = (int) (Low >>> 32);
048:                if (LowHi != 0 || Low < 0xFF000000L) {
049:                    _position += _cacheSize;
050:                    int temp = _cache;
051:                    do {
052:                        Stream.write(temp + LowHi);
053:                        temp = 0xFF;
054:                    } while (--_cacheSize != 0);
055:                    _cache = (((int) Low) >>> 24);
056:                }
057:                _cacheSize++;
058:                Low = (Low & 0xFFFFFF) << 8;
059:            }
060:
061:            public void EncodeDirectBits(int v, int numTotalBits)
062:                    throws IOException {
063:                for (int i = numTotalBits - 1; i >= 0; i--) {
064:                    Range >>>= 1;
065:                    if (((v >>> i) & 1) == 1)
066:                        Low += Range;
067:                    if ((Range & Encoder.kTopMask) == 0) {
068:                        Range <<= 8;
069:                        ShiftLow();
070:                    }
071:                }
072:            }
073:
074:            public long GetProcessedSizeAdd() {
075:                return _cacheSize + _position + 4;
076:            }
077:
078:            static final int kNumMoveReducingBits = 2;
079:            public static final int kNumBitPriceShiftBits = 6;
080:
081:            public static void InitBitModels(short[] probs) {
082:                for (int i = 0; i < probs.length; i++)
083:                    probs[i] = (kBitModelTotal >>> 1);
084:            }
085:
086:            public void Encode(short[] probs, int index, int symbol)
087:                    throws IOException {
088:                int prob = probs[index];
089:                int newBound = (Range >>> kNumBitModelTotalBits) * prob;
090:                if (symbol == 0) {
091:                    Range = newBound;
092:                    probs[index] = (short) (prob + ((kBitModelTotal - prob) >>> kNumMoveBits));
093:                } else {
094:                    Low += (newBound & 0xFFFFFFFFL);
095:                    Range -= newBound;
096:                    probs[index] = (short) (prob - ((prob) >>> kNumMoveBits));
097:                }
098:                if ((Range & kTopMask) == 0) {
099:                    Range <<= 8;
100:                    ShiftLow();
101:                }
102:            }
103:
104:            private static int[] ProbPrices = new int[kBitModelTotal >>> kNumMoveReducingBits];
105:
106:            static {
107:                int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);
108:                for (int i = kNumBits - 1; i >= 0; i--) {
109:                    int start = 1 << (kNumBits - i - 1);
110:                    int end = 1 << (kNumBits - i);
111:                    for (int j = start; j < end; j++)
112:                        ProbPrices[j] = (i << kNumBitPriceShiftBits)
113:                                + (((end - j) << kNumBitPriceShiftBits) >>> (kNumBits
114:                                        - i - 1));
115:                }
116:            }
117:
118:            static public int GetPrice(int Prob, int symbol) {
119:                return ProbPrices[(((Prob - symbol) ^ ((-symbol))) & (kBitModelTotal - 1)) >>> kNumMoveReducingBits];
120:            }
121:
122:            static public int GetPrice0(int Prob) {
123:                return ProbPrices[Prob >>> kNumMoveReducingBits];
124:            }
125:
126:            static public int GetPrice1(int Prob) {
127:                return ProbPrices[(kBitModelTotal - Prob) >>> kNumMoveReducingBits];
128:            }
129:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.