Source Code Cross Referenced for StripLineBreaks.java in  » Build » ANT » org » apache » tools » ant » filters » 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.filters 
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.filters;
019:
020:        import java.io.IOException;
021:        import java.io.Reader;
022:        import org.apache.tools.ant.types.Parameter;
023:
024:        /**
025:         * Filter to flatten the stream to a single line.
026:         *
027:         * Example:
028:         *
029:         * <pre>&lt;striplinebreaks/&gt;</pre>
030:         *
031:         * Or:
032:         *
033:         * <pre>&lt;filterreader
034:         *   classname=&quot;org.apache.tools.ant.filters.StripLineBreaks&quot;/&gt;</pre>
035:         *
036:         */
037:        public final class StripLineBreaks extends BaseParamFilterReader
038:                implements  ChainableReader {
039:            /**
040:             * Line-breaking characters.
041:             * What should we do on funny IBM mainframes with odd line endings?
042:             */
043:            private static final String DEFAULT_LINE_BREAKS = "\r\n";
044:
045:            /** Parameter name for the line-breaking characters parameter. */
046:            private static final String LINE_BREAKS_KEY = "linebreaks";
047:
048:            /** The characters that are recognized as line breaks. */
049:            private String lineBreaks = DEFAULT_LINE_BREAKS;
050:
051:            /**
052:             * Constructor for "dummy" instances.
053:             *
054:             * @see BaseFilterReader#BaseFilterReader()
055:             */
056:            public StripLineBreaks() {
057:                super ();
058:            }
059:
060:            /**
061:             * Creates a new filtered reader.
062:             *
063:             * @param in A Reader object providing the underlying stream.
064:             *           Must not be <code>null</code>.
065:             */
066:            public StripLineBreaks(final Reader in) {
067:                super (in);
068:            }
069:
070:            /**
071:             * Returns the next character in the filtered stream, only including
072:             * characters not in the set of line-breaking characters.
073:             *
074:             * @return the next character in the resulting stream, or -1
075:             * if the end of the resulting stream has been reached
076:             *
077:             * @exception IOException if the underlying stream throws an IOException
078:             * during reading
079:             */
080:            public int read() throws IOException {
081:                if (!getInitialized()) {
082:                    initialize();
083:                    setInitialized(true);
084:                }
085:
086:                int ch = in.read();
087:                while (ch != -1) {
088:                    if (lineBreaks.indexOf(ch) == -1) {
089:                        break;
090:                    } else {
091:                        ch = in.read();
092:                    }
093:                }
094:                return ch;
095:            }
096:
097:            /**
098:             * Sets the line-breaking characters.
099:             *
100:             * @param lineBreaks A String containing all the characters to be
101:             *                   considered as line-breaking.
102:             */
103:            public void setLineBreaks(final String lineBreaks) {
104:                this .lineBreaks = lineBreaks;
105:            }
106:
107:            /**
108:             * Returns the line-breaking characters as a String.
109:             *
110:             * @return a String containing all the characters considered as
111:             *         line-breaking
112:             */
113:            private String getLineBreaks() {
114:                return lineBreaks;
115:            }
116:
117:            /**
118:             * Creates a new StripLineBreaks using the passed in
119:             * Reader for instantiation.
120:             *
121:             * @param rdr A Reader object providing the underlying stream.
122:             *            Must not be <code>null</code>.
123:             *
124:             * @return a new filter based on this configuration, but filtering
125:             *         the specified reader
126:             */
127:            public Reader chain(final Reader rdr) {
128:                StripLineBreaks newFilter = new StripLineBreaks(rdr);
129:                newFilter.setLineBreaks(getLineBreaks());
130:                newFilter.setInitialized(true);
131:                return newFilter;
132:            }
133:
134:            /**
135:             * Parses the parameters to set the line-breaking characters.
136:             */
137:            private void initialize() {
138:                String userDefinedLineBreaks = null;
139:                Parameter[] params = getParameters();
140:                if (params != null) {
141:                    for (int i = 0; i < params.length; i++) {
142:                        if (LINE_BREAKS_KEY.equals(params[i].getName())) {
143:                            userDefinedLineBreaks = params[i].getValue();
144:                            break;
145:                        }
146:                    }
147:                }
148:                if (userDefinedLineBreaks != null) {
149:                    lineBreaks = userDefinedLineBreaks;
150:                }
151:            }
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.