Source Code Cross Referenced for BasicHeaderIterator.java in  » Net » httpcomponents-core-4.0-beta1 » org » apache » http » message » 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 » Net » httpcomponents core 4.0 beta1 » org.apache.http.message 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/main/java/org/apache/http/message/BasicHeaderIterator.java $
003:         * $Revision: 581981 $
004:         * $Date: 2007-10-04 20:26:26 +0200 (Thu, 04 Oct 2007) $
005:         *
006:         * ====================================================================
007:         * Licensed to the Apache Software Foundation (ASF) under one
008:         * or more contributor license agreements.  See the NOTICE file
009:         * distributed with this work for additional information
010:         * regarding copyright ownership.  The ASF licenses this file
011:         * to you under the Apache License, Version 2.0 (the
012:         * "License"); you may not use this file except in compliance
013:         * with the License.  You may obtain a copy of the License at
014:         *
015:         *   http://www.apache.org/licenses/LICENSE-2.0
016:         *
017:         * Unless required by applicable law or agreed to in writing,
018:         * software distributed under the License is distributed on an
019:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020:         * KIND, either express or implied.  See the License for the
021:         * specific language governing permissions and limitations
022:         * under the License.
023:         * ====================================================================
024:         *
025:         * This software consists of voluntary contributions made by many
026:         * individuals on behalf of the Apache Software Foundation.  For more
027:         * information on the Apache Software Foundation, please see
028:         * <http://www.apache.org/>.
029:         *
030:         */
031:
032:        package org.apache.http.message;
033:
034:        import java.util.NoSuchElementException;
035:
036:        import org.apache.http.Header;
037:        import org.apache.http.HeaderIterator;
038:
039:        /**
040:         * Basic implementation of a {@link HeaderIterator}.
041:         * 
042:         * @version $Revision: 581981 $
043:         */
044:        public class BasicHeaderIterator implements  HeaderIterator {
045:
046:            /**
047:             * An array of headers to iterate over.
048:             * Not all elements of this array are necessarily part of the iteration.
049:             * This array will never be modified by the iterator.
050:             * Derived implementations are expected to adhere to this restriction.
051:             */
052:            protected final Header[] allHeaders;
053:
054:            /**
055:             * The position of the next header in {@link #allHeaders allHeaders}.
056:             * Negative if the iteration is over.
057:             */
058:            protected int currentIndex;
059:
060:            /**
061:             * The header name to filter by.
062:             * <code>null</code> to iterate over all headers in the array.
063:             */
064:            protected String headerName;
065:
066:            /**
067:             * Creates a new header iterator.
068:             *
069:             * @param headers   an array of headers over which to iterate
070:             * @param name      the name of the headers over which to iterate, or
071:             *                  <code>null</code> for any
072:             */
073:            public BasicHeaderIterator(Header[] headers, String name) {
074:                if (headers == null) {
075:                    throw new IllegalArgumentException(
076:                            "Header array must not be null.");
077:                }
078:
079:                this .allHeaders = headers;
080:                this .headerName = name;
081:                this .currentIndex = findNext(-1);
082:            }
083:
084:            /**
085:             * Determines the index of the next header.
086:             *
087:             * @param from      one less than the index to consider first,
088:             *                  -1 to search for the first header
089:             *
090:             * @return  the index of the next header that matches the filter name,
091:             *          or negative if there are no more headers
092:             */
093:            protected int findNext(int from) {
094:                if (from < -1)
095:                    return -1;
096:
097:                final int to = this .allHeaders.length - 1;
098:                boolean found = false;
099:                while (!found && (from < to)) {
100:                    from++;
101:                    found = filterHeader(from);
102:                }
103:                return found ? from : -1;
104:            }
105:
106:            /**
107:             * Checks whether a header is part of the iteration.
108:             *
109:             * @param index     the index of the header to check
110:             *
111:             * @return  <code>true</code> if the header should be part of the
112:             *          iteration, <code>false</code> to skip
113:             */
114:            protected boolean filterHeader(int index) {
115:                return (this .headerName == null)
116:                        || this .headerName
117:                                .equalsIgnoreCase(this .allHeaders[index]
118:                                        .getName());
119:            }
120:
121:            // non-javadoc, see interface HeaderIterator
122:            public boolean hasNext() {
123:                return (this .currentIndex >= 0);
124:            }
125:
126:            /**
127:             * Obtains the next header from this iteration.
128:             *
129:             * @return  the next header in this iteration
130:             *
131:             * @throws NoSuchElementException   if there are no more headers
132:             */
133:            public Header nextHeader() throws NoSuchElementException {
134:
135:                final int current = this .currentIndex;
136:                if (current < 0) {
137:                    throw new NoSuchElementException(
138:                            "Iteration already finished.");
139:                }
140:
141:                this .currentIndex = findNext(current);
142:
143:                return this .allHeaders[current];
144:            }
145:
146:            /**
147:             * Returns the next header.
148:             * Same as {@link #nextHeader nextHeader}, but not type-safe.
149:             *
150:             * @return  the next header in this iteration
151:             *
152:             * @throws NoSuchElementException   if there are no more headers
153:             */
154:            public final Object next() throws NoSuchElementException {
155:                return nextHeader();
156:            }
157:
158:            /**
159:             * Removing headers is not supported.
160:             *
161:             * @throws UnsupportedOperationException    always
162:             */
163:            public void remove() throws UnsupportedOperationException {
164:
165:                throw new UnsupportedOperationException(
166:                        "Removing headers is not supported.");
167:            }
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.