1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs.provider;
18
19 import org.apache.commons.vfs.FileContent;
20 import org.apache.commons.vfs.FileSystemException;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.OutputStream;
25 import java.net.URL;
26 import java.net.URLConnection;
27
28 /***
29 * A default URL connection that will work for most file systems.
30 *
31 * @author <a href="mailto:brian@mmmanager.org">Brian Olsen</a>
32 * @version $Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
33 */
34 public final class DefaultURLConnection
35 extends URLConnection
36 {
37 private final FileContent content;
38
39 public DefaultURLConnection(final URL url,
40 final FileContent content)
41 {
42 super(url);
43 this.content = content;
44 }
45
46 public void connect()
47 {
48 connected = true;
49 }
50
51 public InputStream getInputStream()
52 throws IOException
53 {
54 return content.getInputStream();
55 }
56
57 public OutputStream getOutputStream()
58 throws IOException
59 {
60 return content.getOutputStream();
61 }
62
63
64 public long getLastModified()
65 {
66 try
67 {
68 return content.getLastModifiedTime();
69 }
70 catch (FileSystemException fse)
71 {
72 }
73
74 return -1;
75 }
76
77 public int getContentLength()
78 {
79 try
80 {
81 return (int) content.getSize();
82 }
83 catch (FileSystemException fse)
84 {
85 }
86
87 return -1;
88 }
89
90 public String getContentType()
91 {
92 try
93 {
94 return content.getContentInfo().getContentType();
95 }
96 catch (FileSystemException e)
97 {
98 throw new RuntimeException(e.getMessage());
99 }
100 }
101
102 public String getContentEncoding()
103 {
104 try
105 {
106 return content.getContentInfo().getContentEncoding();
107 }
108 catch (FileSystemException e)
109 {
110 throw new RuntimeException(e.getMessage());
111 }
112 }
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136 }