Source Code Cross Referenced for StringTokenizer.java in  » Build » ANT » org » apache » tools » ant » 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 » Build » ANT » org.apache.tools.ant.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:        package org.apache.tools.ant.util;
019:
020:        import java.io.IOException;
021:        import java.io.Reader;
022:        import org.apache.tools.ant.ProjectComponent;
023:
024:        /**
025:         * Class to tokenize the input as areas separated
026:         * by white space, or by a specified list of
027:         * delim characters. Behaves like java.util.StringTokenizer.
028:         * If the stream starts with delim characters, the first
029:         * token will be an empty string (unless the treat delims
030:         * as tokens flag is set).
031:         * @since Ant 1.7
032:         */
033:        public class StringTokenizer extends ProjectComponent implements 
034:                Tokenizer {
035:            private String intraString = "";
036:            private int pushed = -2;
037:            private char[] delims = null;
038:            private boolean delimsAreTokens = false;
039:            private boolean suppressDelims = false;
040:            private boolean includeDelims = false;
041:
042:            /**
043:             * attribute delims - the delimiter characters
044:             * @param delims a string containing the delimiter characters
045:             */
046:            public void setDelims(String delims) {
047:                this .delims = StringUtils.resolveBackSlash(delims)
048:                        .toCharArray();
049:            }
050:
051:            /**
052:             * attribute delimsaretokens - treat delimiters as
053:             * separate tokens.
054:             * @param delimsAreTokens true if delimiters are to be separate
055:             */
056:
057:            public void setDelimsAreTokens(boolean delimsAreTokens) {
058:                this .delimsAreTokens = delimsAreTokens;
059:            }
060:
061:            /**
062:             * attribute suppressdelims - suppress delimiters.
063:             * default - false
064:             * @param suppressDelims if true do not report delimiters
065:             */
066:            public void setSuppressDelims(boolean suppressDelims) {
067:                this .suppressDelims = suppressDelims;
068:            }
069:
070:            /**
071:             * attribute includedelims - treat delimiters as part
072:             * of the token.
073:             * default - false
074:             * @param includeDelims if true add delimiters to the token
075:             */
076:            public void setIncludeDelims(boolean includeDelims) {
077:                this .includeDelims = includeDelims;
078:            }
079:
080:            /**
081:             * find and return the next token
082:             *
083:             * @param in the input stream
084:             * @return the token
085:             * @exception IOException if an error occurs reading
086:             */
087:            public String getToken(Reader in) throws IOException {
088:                int ch = -1;
089:                if (pushed != -2) {
090:                    ch = pushed;
091:                    pushed = -2;
092:                } else {
093:                    ch = in.read();
094:                }
095:                if (ch == -1) {
096:                    return null;
097:                }
098:                boolean inToken = true;
099:                intraString = "";
100:                StringBuffer word = new StringBuffer();
101:                StringBuffer padding = new StringBuffer();
102:                while (ch != -1) {
103:                    char c = (char) ch;
104:                    boolean isDelim = isDelim(c);
105:                    if (inToken) {
106:                        if (isDelim) {
107:                            if (delimsAreTokens) {
108:                                if (word.length() == 0) {
109:                                    word.append(c);
110:                                } else {
111:                                    pushed = ch;
112:                                }
113:                                break;
114:                            }
115:                            padding.append(c);
116:                            inToken = false;
117:                        } else {
118:                            word.append(c);
119:                        }
120:                    } else {
121:                        if (isDelim) {
122:                            padding.append(c);
123:                        } else {
124:                            pushed = ch;
125:                            break;
126:                        }
127:                    }
128:                    ch = in.read();
129:                }
130:                intraString = padding.toString();
131:                if (includeDelims) {
132:                    word.append(intraString);
133:                }
134:                return word.toString();
135:            }
136:
137:            /**
138:             * @return the intratoken string
139:             */
140:            public String getPostToken() {
141:                return suppressDelims || includeDelims ? "" : intraString;
142:            }
143:
144:            private boolean isDelim(char ch) {
145:                if (delims == null) {
146:                    return Character.isWhitespace(ch);
147:                }
148:                for (int i = 0; i < delims.length; ++i) {
149:                    if (delims[i] == ch) {
150:                        return true;
151:                    }
152:                }
153:                return false;
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.