Source Code Cross Referenced for PIReader.java in  » Parser » NanoXML » net » n3 » nanoxml » 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 » Parser » NanoXML » net.n3.nanoxml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* PIReader.java                                                   NanoXML/Java
002:         *
003:         * $Revision: 1.3 $
004:         * $Date: 2002/01/04 21:03:28 $
005:         * $Name: RELEASE_2_2_1 $
006:         *
007:         * This file is part of NanoXML 2 for Java.
008:         * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
009:         *
010:         * This software is provided 'as-is', without any express or implied warranty.
011:         * In no event will the authors be held liable for any damages arising from the
012:         * use of this software.
013:         *
014:         * Permission is granted to anyone to use this software for any purpose,
015:         * including commercial applications, and to alter it and redistribute it
016:         * freely, subject to the following restrictions:
017:         *
018:         *  1. The origin of this software must not be misrepresented; you must not
019:         *     claim that you wrote the original software. If you use this software in
020:         *     a product, an acknowledgment in the product documentation would be
021:         *     appreciated but is not required.
022:         *
023:         *  2. Altered source versions must be plainly marked as such, and must not be
024:         *     misrepresented as being the original software.
025:         *
026:         *  3. This notice may not be removed or altered from any source distribution.
027:         */
028:
029:        package net.n3.nanoxml;
030:
031:        import java.io.Reader;
032:        import java.io.IOException;
033:
034:        /**
035:         * This reader reads data from another reader until the end of a processing
036:         * instruction (?>) has been encountered.
037:         *
038:         * @author Marc De Scheemaecker
039:         * @version $Name: RELEASE_2_2_1 $, $Revision: 1.3 $
040:         */
041:        class PIReader extends Reader {
042:
043:            /**
044:             * The encapsulated reader.
045:             */
046:            private IXMLReader reader;
047:
048:            /**
049:             * True if the end of the stream has been reached.
050:             */
051:            private boolean atEndOfData;
052:
053:            /**
054:             * Creates the reader.
055:             *
056:             * @param reader the encapsulated reader
057:             */
058:            PIReader(IXMLReader reader) {
059:                this .reader = reader;
060:                this .atEndOfData = false;
061:            }
062:
063:            /**
064:             * Cleans up the object when it's destroyed.
065:             */
066:            protected void finalize() throws Throwable {
067:                this .reader = null;
068:                super .finalize();
069:            }
070:
071:            /**
072:             * Reads a block of data.
073:             *
074:             * @param buffer where to put the read data
075:             * @param offset first position in buffer to put the data
076:             * @param size maximum number of chars to read
077:             *
078:             * @return the number of chars read, or -1 if at EOF
079:             *
080:             * @throws java.io.IOException
081:             *		if an error occurred reading the data
082:             */
083:            public int read(char[] buffer, int offset, int size)
084:                    throws IOException {
085:                if (this .atEndOfData) {
086:                    return -1;
087:                }
088:
089:                int charsRead = 0;
090:
091:                if ((offset + size) > buffer.length) {
092:                    size = buffer.length - offset;
093:                }
094:
095:                while (charsRead < size) {
096:                    char ch = this .reader.read();
097:
098:                    if (ch == '?') {
099:                        char ch2 = this .reader.read();
100:
101:                        if (ch2 == '>') {
102:                            this .atEndOfData = true;
103:                            break;
104:                        }
105:
106:                        this .reader.unread(ch2);
107:                    }
108:
109:                    buffer[charsRead] = ch;
110:                    charsRead++;
111:                }
112:
113:                if (charsRead == 0) {
114:                    charsRead = -1;
115:                }
116:
117:                return charsRead;
118:            }
119:
120:            /**
121:             * Skips remaining data and closes the stream.
122:             *
123:             * @throws java.io.IOException
124:             *		if an error occurred reading the data
125:             */
126:            public void close() throws IOException {
127:                while (!this .atEndOfData) {
128:                    char ch = this .reader.read();
129:
130:                    if (ch == '?') {
131:                        char ch2 = this .reader.read();
132:
133:                        if (ch2 == '>') {
134:                            this .atEndOfData = true;
135:                        }
136:                    }
137:                }
138:            }
139:
140:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.