Source Code Cross Referenced for UrlFileObject.java in  » Library » Apache-commons-vfs-20070724-src » org » apache » commons » vfs » provider » url » 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 » Library » Apache commons vfs 20070724 src » org.apache.commons.vfs.provider.url 
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:        package org.apache.commons.vfs.provider.url;
018:
019:        import org.apache.commons.httpclient.URIException;
020:        import org.apache.commons.vfs.FileName;
021:        import org.apache.commons.vfs.FileObject;
022:        import org.apache.commons.vfs.FileSystemException;
023:        import org.apache.commons.vfs.FileType;
024:        import org.apache.commons.vfs.provider.AbstractFileObject;
025:        import org.apache.commons.vfs.provider.URLFileName;
026:
027:        import java.io.FileNotFoundException;
028:        import java.io.InputStream;
029:        import java.net.HttpURLConnection;
030:        import java.net.MalformedURLException;
031:        import java.net.URL;
032:        import java.net.URLConnection;
033:
034:        /**
035:         * A {@link FileObject} implementation backed by a {@link URL}.
036:         *
037:         * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
038:         * @version $Revision: 480428 $ $Date: 2006-11-28 22:15:24 -0800 (Tue, 28 Nov 2006) $
039:         * @todo Implement set lastModified and get/set attribute
040:         * @todo Implement getOutputStream()
041:         */
042:        public class UrlFileObject extends AbstractFileObject implements 
043:                FileObject {
044:            private URL url;
045:
046:            protected UrlFileObject(final UrlFileSystem fs,
047:                    final FileName fileName) {
048:                super (fileName, fs);
049:            }
050:
051:            /**
052:             * Attaches this file object to its file resource.  This method is called
053:             * before any of the doBlah() or onBlah() methods.  Sub-classes can use
054:             * this method to perform lazy initialisation.
055:             */
056:            protected void doAttach() throws Exception {
057:                if (url == null) {
058:                    // url = new URL(getName().getURI());
059:                    url = createURL(getName());
060:                }
061:            }
062:
063:            protected URL createURL(final FileName name)
064:                    throws MalformedURLException, FileSystemException,
065:                    URIException {
066:                if (name instanceof  URLFileName) {
067:                    URLFileName urlName = (URLFileName) getName();
068:
069:                    // TODO: charset
070:                    return new URL(urlName.getURIEncoded(null));
071:                }
072:                return new URL(getName().getURI());
073:            }
074:
075:            /**
076:             * Determines the type of the file.
077:             */
078:            protected FileType doGetType() throws Exception {
079:                try {
080:                    // Attempt to connect & check status
081:                    final URLConnection conn = url.openConnection();
082:                    final InputStream in = conn.getInputStream();
083:                    try {
084:                        if (conn instanceof  HttpURLConnection) {
085:                            final int status = ((HttpURLConnection) conn)
086:                                    .getResponseCode();
087:                            // 200 is good, maybe add more later...
088:                            if (HttpURLConnection.HTTP_OK != status) {
089:                                return FileType.IMAGINARY;
090:                            }
091:                        }
092:
093:                        return FileType.FILE;
094:                    } finally {
095:                        in.close();
096:                    }
097:                } catch (final FileNotFoundException e) {
098:                    return FileType.IMAGINARY;
099:                }
100:            }
101:
102:            /**
103:             * Returns the size of the file content (in bytes).
104:             */
105:            protected long doGetContentSize() throws Exception {
106:                final URLConnection conn = url.openConnection();
107:                final InputStream in = conn.getInputStream();
108:                try {
109:                    return conn.getContentLength();
110:                } finally {
111:                    in.close();
112:                }
113:            }
114:
115:            /**
116:             * Returns the last modified time of this file.
117:             */
118:            protected long doGetLastModifiedTime() throws Exception {
119:                final URLConnection conn = url.openConnection();
120:                final InputStream in = conn.getInputStream();
121:                try {
122:                    return conn.getLastModified();
123:                } finally {
124:                    in.close();
125:                }
126:            }
127:
128:            /**
129:             * Lists the children of the file.
130:             */
131:            protected String[] doListChildren() throws Exception {
132:                throw new FileSystemException("Not implemented.");
133:            }
134:
135:            /**
136:             * Creates an input stream to read the file content from.
137:             */
138:            protected InputStream doGetInputStream() throws Exception {
139:                return url.openStream();
140:            }
141:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.