Source Code Cross Referenced for Handler.java in  » 6.0-JDK-Modules » j2me » sun » net » www » protocol » file » 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 » sun.net.www.protocol.file 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)Handler.java	1.16 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 sun.net.www.protocol.file;
029:
030:        import java.net.InetAddress;
031:        import java.net.URLConnection;
032:        import java.net.URL;
033:        import java.net.MalformedURLException;
034:        import java.net.URLStreamHandler;
035:        import java.io.InputStream;
036:        import java.io.IOException;
037:        import sun.net.www.ParseUtil;
038:        import java.io.File;
039:
040:        /**
041:         * Open an file input stream given a URL.
042:         * @author	James Gosling
043:         * @version 	1.41, 99/12/04
044:         */
045:        public class Handler extends URLStreamHandler {
046:
047:            private String getHost(URL url) {
048:                String host = url.getHost();
049:                if (host == null)
050:                    host = "";
051:                return host;
052:            }
053:
054:            // Fix for bug 6240398: This method was added to preserve UNC file
055:            // paths. URLStreamHandler did not handle it then. But 
056:            // with j2se1.4.2 updates, parent class URLStreamHandler handles UNC
057:            // file paths. Hence we don't need this.
058:            /*
059:            protected String toExternalForm(URL u) {
060:                StringBuffer result = new StringBuffer(u.getProtocol());
061:                result.append(":");
062:                if (u.getAuthority() != null) {
063:                    result.append("//");
064:                    result.append(u.getAuthority());
065:                } else {
066:                    result.append("//");
067:            }
068:                if (u.getFile() != null) {
069:                    result.append(u.getFile());
070:                }
071:                if (u.getRef() != null) {
072:                    result.append("#");
073:                    result.append(u.getRef());
074:                }
075:                return result.toString();
076:            }
077:             */
078:
079:            protected void parseURL(URL u, String spec, int start, int limit) {
080:                /*
081:                 * Ugly backwards compatibility. Flip any file separator
082:                 * characters to be forward slashes. This is a nop on Unix
083:                 * and "fixes" win32 file paths. According to RFC 2396,
084:                 * only forward slashes may be used to represent hierarchy
085:                 * separation in a URL but previous releases unfortunately
086:                 * performed this "fixup" behavior in the file URL parsing code
087:                 * rather than forcing this to be fixed in the caller of the URL
088:                 * class where it belongs. Since backslash is an "unwise"
089:                 * character that would normally be encoded if literally intended
090:                 * as a non-seperator character the damage of veering away from the
091:                 * specification is presumably limited.
092:                 */
093:                super .parseURL(u, spec.replace(File.separatorChar, '/'), start,
094:                        limit);
095:            }
096:
097:            public synchronized URLConnection openConnection(URL url)
098:                    throws IOException {
099:
100:                String path;
101:                String file = url.getFile();
102:                String host = url.getHost();
103:
104:                path = ParseUtil.decode(file);
105:                path = path.replace('/', '\\');
106:                path = path.replace('|', ':');
107:
108:                if ((host == null) || host.equals("")
109:                        || host.equalsIgnoreCase("localhost")
110:                        || host.equals("~")) {
111:                    return createFileURLConnection(url, new File(path));
112:                }
113:
114:                /*
115:                 * attempt to treat this as a UNC path. See 4180841
116:                 */
117:                path = "\\\\" + host + path;
118:                File f = new File(path);
119:                if (f.exists()) {
120:                    return createFileURLConnection(url, f);
121:                }
122:
123:                /*
124:                 * Now attempt an ftp connection.
125:                 */
126:                /* Commented out, because CDC/Foundation doesn't support FTP
127:                URLConnection uc;
128:                URL newurl;
129:
130:                try {
131:                    newurl = new URL("ftp", host, file +
132:                		    (url.getRef() == null ? "":
133:                		    "#" + url.getRef()));
134:                    uc = newurl.openConnection();
135:                } catch (IOException e) {
136:                    uc = null;
137:                }
138:                if (uc == null) {
139:                    throw new IOException("Unable to connect to: " +
140:                				url.toExternalForm());
141:                }
142:                return uc;
143:                 */
144:                throw new IOException("URL connection with specified hostname "
145:                        + "is not supported. " + "Only localhost is supported.");
146:            }
147:
148:            /**
149:             * Template method to be overriden by Java Plug-in. [stanleyh]
150:             */
151:            protected URLConnection createFileURLConnection(URL url, File file) {
152:                return new FileURLConnection(url, file);
153:            }
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.