Source Code Cross Referenced for VxWorksFileSystem.java in  » 6.0-JDK-Modules » j2me » java » io » 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 » 6.0 JDK Modules » j2me » java.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)VxWorksFileSystem.java	1.9 06/10/10
003:         *
004:         * Copyright  1990-2006 Sun Microsystems, Inc. All Rights Reserved.  
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER  
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 version  
009:         * 2 only, as published by the Free Software Foundation.   
010:         *   
011:         * This program is distributed in the hope that it will be useful, but  
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of  
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  
014:         * General Public License version 2 for more details (a copy is  
015:         * included at /legal/license.txt).   
016:         *   
017:         * You should have received a copy of the GNU General Public License  
018:         * version 2 along with this work; if not, write to the Free Software  
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  
020:         * 02110-1301 USA   
021:         *   
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa  
023:         * Clara, CA 95054 or visit www.sun.com if you need additional  
024:         * information or have any questions. 
025:         *
026:         */
027:
028:        package java.io;
029:
030:        import java.security.AccessController;
031:        import sun.security.action.GetPropertyAction;
032:
033:        class VxWorksFileSystem extends FileSystem {
034:
035:            private final char slash;
036:            private final char semicolon;
037:
038:            public VxWorksFileSystem() {
039:                slash = ((String) AccessController
040:                        .doPrivileged(new GetPropertyAction("file.separator")))
041:                        .charAt(0);
042:                semicolon = ((String) AccessController
043:                        .doPrivileged(new GetPropertyAction("path.separator")))
044:                        .charAt(0);
045:            }
046:
047:            /* -- Normalization and construction -- */
048:
049:            public char getSeparator() {
050:                return slash;
051:            }
052:
053:            public char getPathSeparator() {
054:                return semicolon;
055:            }
056:
057:            /* A normal VxWorks pathname contains no duplicate slashes and does not end
058:               with a slash.  It may be the empty string. */
059:
060:            /* Normalize the given pathname, whose length is len, starting at the given
061:               offset; everything before this offset is already normal. */
062:            private String normalize(String pathname, int len, int off) {
063:                if (len == 0)
064:                    return pathname;
065:                int n = len;
066:                while ((n > 0) && (pathname.charAt(n - 1) == '/'))
067:                    n--;
068:                if (n == 0)
069:                    return "/";
070:                StringBuffer sb = new StringBuffer(pathname.length());
071:                if (off > 0)
072:                    sb.append(pathname.substring(0, off));
073:                char prevChar = 0;
074:                for (int i = off; i < n; i++) {
075:                    char c = pathname.charAt(i);
076:                    if ((prevChar == '/') && (c == '/'))
077:                        continue;
078:                    sb.append(c);
079:                    prevChar = c;
080:                }
081:                return sb.toString();
082:            }
083:
084:            /* Check that the given pathname is normal.  If not, invoke the real
085:               normalizer on the part of the pathname that requires normalization.
086:               This way we iterate through the whole pathname string only once. */
087:            public String normalize(String pathname) {
088:                int n = pathname.length();
089:                if (n > 0 && pathname.charAt(0) == slash) {
090:                    // Remove the leading slash inserted by File.toURL(). 
091:                    // See bugid 4288740
092:                    String sub = pathname.substring(1);
093:                    if (isAbsolute(sub)) {
094:                        String s = normalize(sub, n - 1, 0);
095:                        return s;
096:                    }
097:                }
098:                char prevChar = 0;
099:                for (int i = 0; i < n; i++) {
100:                    char c = pathname.charAt(i);
101:                    if ((prevChar == '/') && (c == '/'))
102:                        return normalize(pathname, n, i - 1);
103:                    prevChar = c;
104:                }
105:                if (prevChar == '/')
106:                    return normalize(pathname, n, n - 1);
107:                return pathname;
108:            }
109:
110:            public int prefixLength(String pathname) {
111:                int n = pathname.length();
112:                if (n == 0)
113:                    return 0;
114:                // Support <hostname>:<path> pathnames
115:                int prefixEnd = pathname.indexOf(':');
116:                int i = prefixEnd + 1;
117:                if (i < n && pathname.charAt(i) == slash) {
118:                    return i + 1;
119:                } else {
120:                    return i;
121:                }
122:            }
123:
124:            public String resolve(String parent, String child) {
125:                if (child.equals(""))
126:                    return parent;
127:                if (child.charAt(0) == '/') {
128:                    if (parent.equals("/"))
129:                        return child;
130:                    return parent + child;
131:                }
132:                if (parent.equals("/"))
133:                    return parent + child;
134:                return parent + '/' + child;
135:            }
136:
137:            public String getDefaultParent() {
138:                return "/";
139:            }
140:
141:            /* -- Path operations -- */
142:
143:            private boolean isAbsolute(String pathname) {
144:                int pl = prefixLength(pathname);
145:                return pl > 0 ? (pathname.charAt(pl - 1) == slash) : false;
146:            }
147:
148:            public boolean isAbsolute(File f) {
149:                return isAbsolute(f.getPath());
150:            }
151:
152:            public String resolve(File f) {
153:                if (isAbsolute(f))
154:                    return f.getPath();
155:                return resolve(System.getProperty("user.dir"), f.getPath());
156:            }
157:
158:            public native String canonicalize(String path) throws IOException;
159:
160:            /* -- Attribute accessors -- */
161:
162:            public native int getBooleanAttributes0(File f);
163:
164:            public int getBooleanAttributes(File f) {
165:                int rv = getBooleanAttributes0(f);
166:                String name = f.getName();
167:                boolean hidden = (name.length() > 0) && (name.charAt(0) == '.');
168:                return rv | (hidden ? BA_HIDDEN : 0);
169:            }
170:
171:            public native boolean checkAccess(File f, boolean write);
172:
173:            public native long getLastModifiedTime(File f);
174:
175:            public native long getLength(File f);
176:
177:            /* -- File operations -- */
178:
179:            public native boolean createFileExclusively(String path)
180:                    throws IOException;
181:
182:            public native boolean delete(File f);
183:
184:            public synchronized native boolean deleteOnExit(File f);
185:
186:            public native String[] list(File f);
187:
188:            public native boolean createDirectory(File f);
189:
190:            public native boolean rename(File f1, File f2);
191:
192:            public native boolean setLastModifiedTime(File f, long time);
193:
194:            public native boolean setReadOnly(File f);
195:
196:            /* -- Filesystem interface -- */
197:
198:            public File[] listRoots() {
199:                try {
200:                    SecurityManager security = System.getSecurityManager();
201:                    if (security != null) {
202:                        security.checkRead("/");
203:                    }
204:                    return new File[] { new File("/") };
205:                } catch (SecurityException x) {
206:                    return new File[0];
207:                }
208:            }
209:
210:            /* -- Basic infrastructure -- */
211:
212:            public int compare(File f1, File f2) {
213:                return f1.getPath().compareTo(f2.getPath());
214:            }
215:
216:            public int hashCode(File f) {
217:                return f.getPath().hashCode() ^ 1234321;
218:            }
219:
220:            private static native void initIDs();
221:
222:            static {
223:                initIDs();
224:            }
225:
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.