Source Code Cross Referenced for FTPFileParser.java in  » Net » edtftpj » com » enterprisedt » net » ftp » 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 » edtftpj » com.enterprisedt.net.ftp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *
003:         *  edtFTPj
004:         * 
005:         *  Copyright (C) 2000-2004 Enterprise Distributed Technologies Ltd
006:         *
007:         *  www.enterprisedt.com
008:         *
009:         *  This library is free software; you can redistribute it and/or
010:         *  modify it under the terms of the GNU Lesser General Public
011:         *  License as published by the Free Software Foundation; either
012:         *  version 2.1 of the License, or (at your option) any later version.
013:         *
014:         *  This library is distributed in the hope that it will be useful,
015:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
017:         *  Lesser General Public License for more details.
018:         *
019:         *  You should have received a copy of the GNU Lesser General Public
020:         *  License along with this library; if not, write to the Free Software
021:         *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
022:         *
023:         *  Bug fixes, suggestions and comments should be should posted on 
024:         *  http://www.enterprisedt.com/forums/index.php
025:         *
026:         *  Change Log:
027:         *
028:         *    $Log: FTPFileParser.java,v $
029:         *    Revision 1.9  2007-12-18 07:53:20  bruceb
030:         *    trimStart() changes
031:         *
032:         *    Revision 1.8  2007-10-12 05:20:44  bruceb
033:         *    permit ignoring date parser errors
034:         *
035:         *    Revision 1.7  2007-01-15 23:03:22  bruceb
036:         *    more splitter methods
037:         *
038:         *    Revision 1.6  2005/07/22 10:25:12  bruceb
039:         *    upped MAX_FIELDS
040:         *
041:         *    Revision 1.5  2005/06/03 11:26:25  bruceb
042:         *    comment change
043:         *
044:         *    Revision 1.4  2004/10/18 15:57:51  bruceb
045:         *    setLocale added
046:         *
047:         *    Revision 1.3  2004/07/23 08:29:57  bruceb
048:         *    updated comment
049:         *
050:         *    Revision 1.2  2004/06/25 11:48:30  bruceb
051:         *    changed MAX_FIELDS to 20
052:         *
053:         *    Revision 1.1  2004/04/17 23:42:07  bruceb
054:         *    file parsing part II
055:         *
056:         *    Revision 1.1  2004/04/17 18:37:23  bruceb
057:         *    new parse functionality
058:         *
059:         */package com.enterprisedt.net.ftp;
060:
061:        import java.text.ParseException;
062:        import java.util.Locale;
063:
064:        /**
065:         *  Root class of all file parsers
066:         *
067:         *  @author      Bruce Blackshaw
068:         *  @version     $Revision: 1.9 $
069:         */
070:        abstract public class FTPFileParser {
071:
072:            /**
073:             * Maximum number of fields in raw string
074:             */
075:            private final static int MAX_FIELDS = 100;
076:
077:            /**
078:             * Ignore date parsing errors
079:             */
080:            protected boolean ignoreDateParseErrors = false;
081:
082:            /**
083:             * Parse server supplied string
084:             * 
085:             * @param raw   raw string to parse
086:             */
087:            abstract public FTPFile parse(String raw) throws ParseException;
088:
089:            /**
090:             * Set the locale for date parsing of listings
091:             * 
092:             * @param locale    locale to set
093:             */
094:            abstract public void setLocale(Locale locale);
095:
096:            /**
097:             * Ignore date parse errors
098:             * 
099:             * @param ignore
100:             */
101:            public void setIgnoreDateParseErrors(boolean ignore) {
102:                this .ignoreDateParseErrors = ignore;
103:            }
104:
105:            /**
106:             * Trim the start of the supplied string
107:             * 
108:             * @param str   string to trim
109:             * @return string trimmed of whitespace at the start
110:             */
111:            protected String trimStart(String str) {
112:                StringBuffer buf = new StringBuffer();
113:                boolean found = false;
114:                for (int i = 0; i < str.length(); i++) {
115:                    char ch = str.charAt(i);
116:                    if (!found & Character.isWhitespace(ch))
117:                        continue;
118:                    found = true;
119:                    buf.append(ch);
120:                }
121:                return buf.toString();
122:            }
123:
124:            /**
125:             * Splits string consisting of fields separated by
126:             * whitespace into an array of strings. Yes, we could
127:             * use String.split() but this would restrict us to 1.4+
128:             * 
129:             * @param str   string to split
130:             * @return array of fields
131:             */
132:            protected String[] split(String str) {
133:                return split(str, new WhitespaceSplitter());
134:            }
135:
136:            /**
137:             * Splits string consisting of fields separated by
138:             * whitespace into an array of strings. Yes, we could
139:             * use String.split() but this would restrict us to 1.4+
140:             * 
141:             * @param str   string to split
142:             * @return array of fields
143:             */
144:            protected String[] split(String str, char token) {
145:                return split(str, new CharSplitter(token));
146:            }
147:
148:            /**
149:             * Splits string consisting of fields separated by
150:             * whitespace into an array of strings. Yes, we could
151:             * use String.split() but this would restrict us to 1.4+
152:             * 
153:             * @param str   string to split
154:             * @return array of fields
155:             */
156:            protected String[] split(String str, Splitter splitter) {
157:                String[] fields = new String[MAX_FIELDS];
158:                int pos = 0;
159:                StringBuffer field = new StringBuffer();
160:                for (int i = 0; i < str.length(); i++) {
161:                    char ch = str.charAt(i);
162:                    if (!splitter.isSeparator(ch))
163:                        field.append(ch);
164:                    else {
165:                        if (field.length() > 0) {
166:                            fields[pos++] = field.toString();
167:                            field.setLength(0);
168:                        }
169:                    }
170:                }
171:                // pick up last field
172:                if (field.length() > 0) {
173:                    fields[pos++] = field.toString();
174:                }
175:                String[] result = new String[pos];
176:                System.arraycopy(fields, 0, result, 0, pos);
177:                return result;
178:            }
179:
180:            interface Splitter {
181:                boolean isSeparator(char ch);
182:            }
183:
184:            class CharSplitter implements  Splitter {
185:                private char token;
186:
187:                CharSplitter(char token) {
188:                    this .token = token;
189:                }
190:
191:                public boolean isSeparator(char ch) {
192:                    if (ch == token)
193:                        return true;
194:                    return false;
195:                }
196:
197:            }
198:
199:            class WhitespaceSplitter implements  Splitter {
200:
201:                public boolean isSeparator(char ch) {
202:                    if (Character.isWhitespace(ch))
203:                        return true;
204:                    return false;
205:                }
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.