KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > provider > DefaultURLConnection


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.vfs.provider;
17
18 import org.apache.commons.vfs.FileContent;
19 import org.apache.commons.vfs.FileSystemException;
20
21 import java.io.IOException JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.io.OutputStream JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.net.URLConnection JavaDoc;
26
27 /**
28  * A default URL connection that will work for most file systems.
29  *
30  * @author <a HREF="mailto:brian@mmmanager.org">Brian Olsen</a>
31  */

32 public final class DefaultURLConnection
33     extends URLConnection JavaDoc
34 {
35     private final FileContent content;
36
37     public DefaultURLConnection(final URL JavaDoc url,
38                                 final FileContent content)
39     {
40         super(url);
41         this.content = content;
42     }
43
44     public void connect()
45     {
46         connected = true;
47     }
48
49     public InputStream JavaDoc getInputStream()
50         throws IOException JavaDoc
51     {
52         return content.getInputStream();
53     }
54
55     public OutputStream JavaDoc getOutputStream()
56         throws IOException JavaDoc
57     {
58         return content.getOutputStream();
59     }
60
61     public int getContentLength()
62     {
63         try
64         {
65             return (int) content.getSize();
66         }
67         catch (FileSystemException fse)
68         {
69         }
70
71         return -1;
72     }
73
74     public String JavaDoc getContentType()
75     {
76         try
77         {
78             return content.getContentInfo().getContentType();
79         }
80         catch (FileSystemException e)
81         {
82             throw new RuntimeException JavaDoc(e.getMessage());
83         }
84     }
85
86     public String JavaDoc getContentEncoding()
87     {
88         try
89         {
90             return content.getContentInfo().getContentEncoding();
91         }
92         catch (FileSystemException e)
93         {
94             throw new RuntimeException JavaDoc(e.getMessage());
95         }
96     }
97
98     /*
99     public String getHeaderField(String name)
100     {
101         try
102         {
103             if (content.getFile().getFileSystem().hasCapability(Capability.ATTRIBUTES))
104             {
105                 String value = (String) content.getAttribute(name);
106                 if (value != null)
107                 {
108                     return value;
109                 }
110             }
111
112             return null;
113         }
114         catch (FileSystemException e)
115         {
116             throw new RuntimeException(e);
117         }
118     }
119     */

120 }
121
Popular Tags