Source Code Cross Referenced for XRefStreamParser.java in  » PDF » jPod » de » intarsys » pdf » st » 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 » PDF » jPod » de.intarsys.pdf.st 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2007, intarsys consulting GmbH
003:         *
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, are permitted provided that the following conditions are met:
006:         *
007:         * - Redistributions of source code must retain the above copyright notice,
008:         *   this list of conditions and the following disclaimer.
009:         *
010:         * - Redistributions in binary form must reproduce the above copyright notice,
011:         *   this list of conditions and the following disclaimer in the documentation
012:         *   and/or other materials provided with the distribution.
013:         *
014:         * - Neither the name of intarsys nor the names of its contributors may be used
015:         *   to endorse or promote products derived from this software without specific
016:         *   prior written permission.
017:         *
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021:         * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
028:         * POSSIBILITY OF SUCH DAMAGE.
029:         */
030:        package de.intarsys.pdf.st;
031:
032:        import java.io.ByteArrayInputStream;
033:        import java.io.IOException;
034:        import java.util.Iterator;
035:        import de.intarsys.pdf.cos.COSArray;
036:        import de.intarsys.pdf.cos.COSIndirectObject;
037:        import de.intarsys.pdf.cos.COSInteger;
038:        import de.intarsys.pdf.cos.COSNumber;
039:        import de.intarsys.pdf.cos.COSObject;
040:        import de.intarsys.pdf.cos.COSObjectKey;
041:        import de.intarsys.pdf.cos.COSStream;
042:        import de.intarsys.pdf.parser.COSDocumentParser;
043:        import de.intarsys.pdf.parser.COSLoadException;
044:        import de.intarsys.tools.randomaccess.IRandomAccess;
045:
046:        /**
047:         * A parser for XRef streams.
048:         */
049:        public class XRefStreamParser extends AbstractXRefParser {
050:            private int[] wSizeDefault = { 1, 2, 1 };
051:
052:            private int[] wSize;
053:
054:            private ByteArrayInputStream in;
055:
056:            public XRefStreamParser(STDocument doc, COSDocumentParser parser) {
057:                super (doc, parser);
058:            }
059:
060:            private void initWBytes(STStreamXRefSection xRef) {
061:                COSArray w = xRef.getW();
062:                if (w == null) {
063:                    wSize = wSizeDefault;
064:                    return;
065:                }
066:                wSize = new int[3];
067:                for (int i = 0; i < w.size(); i++) {
068:                    wSize[i] = ((COSInteger) w.get(i)).intValue();
069:                }
070:                for (int i = w.size(); i < 3; i++) {
071:                    wSize[i] = 0;
072:                }
073:            }
074:
075:            protected STXRefSection parseXRef(IRandomAccess randomAcces)
076:                    throws IOException, COSLoadException {
077:                long offset = randomAcces.getOffset();
078:                COSStream stream = (COSStream) getDoc().getParser()
079:                        .parseIndirectObject(randomAcces, null);
080:                ((COSIndirectObject) stream.containable()).setDirty(false);
081:                STStreamXRefSection xRefSection = new STStreamXRefSection(
082:                        getDoc(), offset, stream);
083:                parseStreamContent(xRefSection);
084:                return xRefSection;
085:            }
086:
087:            private void parseStreamContent(STStreamXRefSection section)
088:                    throws IOException {
089:                initWBytes(section);
090:                in = new ByteArrayInputStream(section.cosGetStream()
091:                        .getDecodedBytes());
092:                COSArray index = section.getIndex();
093:                for (Iterator i = index.iterator(); i.hasNext();) {
094:                    COSNumber cosStart = ((COSObject) i.next()).asNumber();
095:                    if (!i.hasNext()) {
096:                        continue;
097:                    }
098:                    COSNumber cosCount = ((COSObject) i.next()).asNumber();
099:                    if (cosStart == null || cosCount == null) {
100:                        continue;
101:                    }
102:                    int start = cosStart.intValue();
103:                    int count = cosCount.intValue();
104:                    for (int io = 0; io < count; io++) {
105:                        int type = readType(in);
106:                        switch (type) {
107:                        case 0:
108:                            section.addEntry(parseType0(in, start + io));
109:                            break;
110:                        case 1:
111:                            section.addEntry(parseType1(in, start + io));
112:                            break;
113:                        case 2:
114:                            section.addEntry(parseType2(in, start + io));
115:                            break;
116:                        default:
117:                            parseTypeUnknown(in);
118:                        }
119:                    }
120:                }
121:            }
122:
123:            private void parseTypeUnknown(ByteArrayInputStream pIn) {
124:                read(pIn, wSize[1], -1);
125:                read(pIn, wSize[1], -1);
126:            }
127:
128:            private STXRefEntry parseType2(ByteArrayInputStream pIn,
129:                    int objectNumber) {
130:                int keyStmObject = read(pIn, wSize[1], -1);
131:                int indexOfObject = read(pIn, wSize[2], 0);
132:                COSObjectKey objectStreamKey = new COSObjectKey(keyStmObject, 0);
133:                return new STXRefEntryCompressed(new COSObjectKey(objectNumber,
134:                        0), objectStreamKey, indexOfObject);
135:            }
136:
137:            private STXRefEntry parseType1(ByteArrayInputStream pIn,
138:                    int objectNumber) {
139:                int offset = read(pIn, wSize[1], -1);
140:                int genNum = read(pIn, wSize[2], 0);
141:                return new STXRefEntryOccupied(new COSObjectKey(objectNumber,
142:                        genNum), offset);
143:            }
144:
145:            private STXRefEntry parseType0(ByteArrayInputStream pIn,
146:                    int objectNumber) {
147:                int nextFree = read(pIn, wSize[1], -1);
148:                int nextGenNum = read(pIn, wSize[2], -1);
149:                return new STXRefEntryFree(new COSObjectKey(objectNumber,
150:                        nextGenNum), nextFree);
151:            }
152:
153:            private int readType(ByteArrayInputStream pIn) {
154:                return read(pIn, wSize[0], 1);
155:            }
156:
157:            private int read(ByteArrayInputStream pIn, int numBytes,
158:                    int defaultValue) {
159:                if (numBytes == 0) {
160:                    return defaultValue;
161:                }
162:                int result = 0;
163:                for (int i = 0; i < numBytes; i++) {
164:                    result <<= 8;
165:                    result += pIn.read();
166:                }
167:                return result;
168:            }
169:
170:            protected void loadPrevious(IRandomAccess randomAccess,
171:                    STXRefSection xRefSection) throws IOException,
172:                    COSLoadException {
173:                int offset = xRefSection.getPreviousOffset();
174:                if (offset != -1) {
175:                    AbstractXRefParser parser = new XRefStreamParser(getDoc(),
176:                            getParser());
177:                    randomAccess.seek(offset);
178:                    STXRefSection xrefStream = parser.parse(randomAccess);
179:                    xRefSection.setPrevious(xrefStream);
180:                }
181:            }
182:
183:            /*
184:             * (non-Javadoc)
185:             * 
186:             * @see de.intarsys.pdf.st.AbstractXRefParser#parse(de.intarsys.tools.randomaccess.IRandomAccess)
187:             */
188:            public STXRefSection parse(IRandomAccess randomAcces)
189:                    throws IOException, COSLoadException {
190:                STXRefSection xRefSection = parseXRef(randomAcces);
191:                loadPrevious(randomAcces, xRefSection);
192:                return xRefSection;
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.