Source Code Cross Referenced for DirectoryEntry.java in  » IDE » J » org » armedbear » j » 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 » IDE » J » org.armedbear.j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DirectoryEntry.java
003:         *
004:         * Copyright (C) 1998-2004 Peter Graves
005:         * $Id: DirectoryEntry.java,v 1.7 2004/05/21 16:42:02 piso Exp $
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or (at your option) any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         */
021:
022:        package org.armedbear.j;
023:
024:        import gnu.regexp.REMatch;
025:        import java.text.SimpleDateFormat;
026:        import java.util.Date;
027:
028:        public final class DirectoryEntry {
029:            private String name;
030:            private long date;
031:            private long size;
032:            private boolean isDirectory;
033:            private boolean isLink;
034:            private String linkedTo;
035:            private boolean isMarked;
036:
037:            // For native format, this is all we store.
038:            private final String string;
039:
040:            private static final String DIR = "     <DIR>";
041:            private static final int DIRLENGTH = DIR.length();
042:            private static final String DATEFORMAT = "MMM dd yyyy HH:mm";
043:            private static SimpleDateFormat dateFormatter = new SimpleDateFormat(
044:                    DATEFORMAT);
045:
046:            // Constructor for native "ls -l" format.
047:            private DirectoryEntry(String string, char firstChar) {
048:                this .string = string;
049:                if (firstChar == 'd')
050:                    isDirectory = true;
051:                else if (firstChar == 'l')
052:                    isLink = true;
053:                size = -1;
054:            }
055:
056:            // Constructor for internal format.
057:            public DirectoryEntry(String name, long date, long size) {
058:                this .name = name;
059:                this .date = date;
060:                this .size = size;
061:                string = null;
062:            }
063:
064:            // Constructor for internal format.
065:            public DirectoryEntry(String name, long date, long size,
066:                    boolean isDirectory) {
067:                this .name = name;
068:                this .date = date;
069:                this .size = size;
070:                this .isDirectory = isDirectory;
071:                string = null;
072:            }
073:
074:            // Wrapper for constructor for native "ls -l" format.
075:            // Ignore strings that aren't really directory entries.
076:            // Apply filter (if any).
077:            public static DirectoryEntry getDirectoryEntry(String s,
078:                    DirectoryFilenameFilter filter) {
079:                if (s.length() == 0)
080:                    return null;
081:                // Ignore "total" line, command line echo.
082:                // First char must be one of "-dlcbsp".
083:                final char c = s.charAt(0);
084:                if ("-dlcbsp".indexOf(c) < 0)
085:                    return null;
086:                if (c == 'l' && s.startsWith("ls "))
087:                    return null;
088:                if (filter != null) {
089:                    if (c != 'd' && !filter.accepts(getName(s)))
090:                        return null;
091:                }
092:                return new DirectoryEntry(s, c);
093:            }
094:
095:            // Extracts filename from "ls -l" directory listing.
096:            public static String getName(String s) {
097:                // Strip symbolic link if any.
098:                int end = s.indexOf(" -> ");
099:                if (end >= 0)
100:                    s = s.substring(0, end);
101:                REMatch match = Directory.getNativeMoveToFilenameRegExp()
102:                        .getMatch(s);
103:                if (match != null)
104:                    return s.substring(match.getEndIndex());
105:                Log.error("DirectoryEntry.getName returning null s = |" + s
106:                        + "|");
107:                return null;
108:            }
109:
110:            public static int getNameColumn(String s) {
111:                // Strip symbolic link if any.
112:                int end = s.indexOf(" -> ");
113:                if (end >= 0)
114:                    s = s.substring(0, end);
115:                REMatch match = Directory.getNativeMoveToFilenameRegExp()
116:                        .getMatch(s);
117:                if (match != null)
118:                    return match.getEndIndex();
119:                return 0;
120:            }
121:
122:            public final String extractName() {
123:                if (name == null && string != null)
124:                    name = getName(string);
125:                return name;
126:            }
127:
128:            // nameColumn must be > 0. It's just a hint.
129:            public final String extractName(int nameColumn) {
130:                if (name != null)
131:                    return name; // Cached.
132:                if (string == null)
133:                    return null;
134:                if (nameColumn > 0 && nameColumn < string.length()) {
135:                    String s = string;
136:                    // Strip symbolic link if any.
137:                    int end = s.indexOf(" -> ");
138:                    if (end >= 0)
139:                        s = s.substring(0, end);
140:                    if (s.charAt(nameColumn - 1) == ' ')
141:                        if (!Character.isWhitespace(s.charAt(nameColumn)))
142:                            return name = s.substring(nameColumn);
143:                }
144:                // Do it the hard way.
145:                return getName(string);
146:            }
147:
148:            public final String getName() {
149:                return name;
150:            }
151:
152:            public final long getDate() {
153:                return date;
154:            }
155:
156:            public final long getSize() {
157:                return size;
158:            }
159:
160:            public final void setSize(long size) {
161:                this .size = size;
162:            }
163:
164:            public final boolean isDirectory() {
165:                return isDirectory;
166:            }
167:
168:            public final boolean isLink() {
169:                return isLink;
170:            }
171:
172:            public final void setLinkedTo(String linkedTo) {
173:                this .linkedTo = linkedTo;
174:            }
175:
176:            public final boolean isMarked() {
177:                return isMarked;
178:            }
179:
180:            public final void setMarked(boolean b) {
181:                isMarked = b;
182:            }
183:
184:            public final String getString() {
185:                return string;
186:            }
187:
188:            public String toString() {
189:                String marked = isMarked ? "T " : "  ";
190:                // Use saved string for native format.
191:                if (string != null)
192:                    return marked.concat(string);
193:                // Construct string for internal format.
194:                FastStringBuffer sb = new FastStringBuffer(256);
195:                sb.append(marked);
196:                if (isDirectory) {
197:                    sb.append(DIR);
198:                } else {
199:                    String sizeString = String.valueOf(size);
200:                    for (int j = 0; j < DIRLENGTH - sizeString.length(); j++)
201:                        sb.append(' ');
202:                    sb.append(sizeString);
203:                }
204:                sb.append(' ');
205:                String dateString = dateFormatter.format(new Date(date));
206:                sb.append(dateString);
207:                sb.append(' ');
208:                sb.append(name);
209:                if (linkedTo != null) {
210:                    sb.append(" -> ");
211:                    sb.append(linkedTo);
212:                }
213:                return sb.toString();
214:            }
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.