1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.http4;
18
19 import java.io.Closeable;
20 import java.net.URI;
21 import java.util.Collection;
22
23 import org.apache.commons.io.function.Uncheck;
24 import org.apache.commons.vfs2.Capability;
25 import org.apache.commons.vfs2.FileName;
26 import org.apache.commons.vfs2.FileObject;
27 import org.apache.commons.vfs2.FileSystemOptions;
28 import org.apache.commons.vfs2.provider.AbstractFileName;
29 import org.apache.commons.vfs2.provider.AbstractFileSystem;
30 import org.apache.http.client.HttpClient;
31 import org.apache.http.client.protocol.HttpClientContext;
32
33
34
35
36
37
38
39 @Deprecated
40 public class Http4FileSystem extends AbstractFileSystem {
41
42
43
44
45 private final URI internalBaseURI;
46
47
48
49
50 private final HttpClient httpClient;
51
52
53
54
55 private final HttpClientContext httpClientContext;
56
57
58
59
60
61
62
63
64
65 protected Http4FileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions, final HttpClient httpClient,
66 final HttpClientContext httpClientContext) {
67 super(rootName, null, fileSystemOptions);
68
69 final String rootURI = getRootURI();
70 final int offset = rootURI.indexOf(':');
71 final char lastCharOfScheme = offset > 0 ? rootURI.charAt(offset - 1) : 0;
72
73
74 final String scheme = lastCharOfScheme == 's' || lastCharOfScheme == 'S' ? "https" : "http";
75 this.internalBaseURI = URI.create(scheme + rootURI.substring(offset));
76 this.httpClient = httpClient;
77 this.httpClientContext = httpClientContext;
78 }
79
80 @Override
81 protected void addCapabilities(final Collection<Capability> caps) {
82 caps.addAll(Http4FileProvider.CAPABILITIES);
83 }
84
85 @Override
86 protected FileObject createFile(final AbstractFileName name) throws Exception {
87 return new Http4FileObject<>(name, this);
88 }
89
90 @Override
91 protected void doCloseCommunicationLink() {
92 if (httpClient instanceof Closeable) {
93
94
95 Uncheck.run(() -> ((Closeable) httpClient).close());
96 }
97 }
98
99
100
101
102
103
104 protected HttpClient getHttpClient() {
105 return httpClient;
106 }
107
108
109
110
111
112
113 protected HttpClientContext getHttpClientContext() {
114 return httpClientContext;
115 }
116
117
118
119
120
121
122 protected URI getInternalBaseURI() {
123 return internalBaseURI;
124 }
125 }