Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/sun/net/ftp/FtpClientProvider.java
41159 views
1
/*
2
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
package sun.net.ftp;
26
27
import java.security.AccessController;
28
import java.security.PrivilegedAction;
29
import java.util.ServiceConfigurationError;
30
//import java.util.ServiceLoader;
31
32
/**
33
* Service provider class for FtpClient.
34
* Sub-classes of FtpClientProvider provide an implementation of {@link FtpClient}
35
* and associated classes. Applications do not normally use this class directly.
36
* See {@link #provider() } for how providers are found and loaded.
37
*
38
* @since 1.7
39
*/
40
public abstract class FtpClientProvider {
41
42
/**
43
* Creates a FtpClient from this provider.
44
*
45
* @return The created {@link FtpClient}.
46
*/
47
public abstract FtpClient createFtpClient();
48
private static final Object lock = new Object();
49
private static FtpClientProvider provider = null;
50
51
/**
52
* Initializes a new instance of this class.
53
*
54
* @throws SecurityException if a security manager is installed and it denies
55
* {@link RuntimePermission}{@code ("ftpClientProvider")}
56
*/
57
protected FtpClientProvider() {
58
@SuppressWarnings("removal")
59
SecurityManager sm = System.getSecurityManager();
60
if (sm != null) {
61
sm.checkPermission(new RuntimePermission("ftpClientProvider"));
62
}
63
}
64
65
private static boolean loadProviderFromProperty() {
66
String cm = System.getProperty("sun.net.ftpClientProvider");
67
if (cm == null) {
68
return false;
69
}
70
try {
71
@SuppressWarnings("deprecation")
72
Object o = Class.forName(cm, true, null).newInstance();
73
provider = (FtpClientProvider)o;
74
return true;
75
} catch (ClassNotFoundException |
76
IllegalAccessException |
77
InstantiationException |
78
SecurityException x) {
79
throw new ServiceConfigurationError(x.toString());
80
}
81
}
82
83
private static boolean loadProviderAsService() {
84
// Iterator<FtpClientProvider> i =
85
// ServiceLoader.load(FtpClientProvider.class,
86
// ClassLoader.getSystemClassLoader()).iterator();
87
//
88
// while (i.hasNext()) {
89
// try {
90
// provider = i.next();
91
// return true;
92
// } catch (ServiceConfigurationError sce) {
93
// if (sce.getCause() instanceof SecurityException) {
94
// // Ignore, try next provider, if any
95
// continue;
96
// }
97
// throw sce;
98
// }
99
// }
100
return false;
101
}
102
103
/**
104
* Returns the system wide default FtpClientProvider for this invocation of
105
* the Java virtual machine.
106
*
107
* <p> The first invocation of this method locates the default provider
108
* object as follows: </p>
109
*
110
* <ol>
111
*
112
* <li><p> If the system property
113
* {@code java.net.FtpClientProvider} is defined then it is
114
* taken to be the fully-qualified name of a concrete provider class.
115
* The class is loaded and instantiated; if this process fails then an
116
* unspecified unchecked error or exception is thrown. </p></li>
117
*
118
* <li><p> If a provider class has been installed in a jar file that is
119
* visible to the system class loader, and that jar file contains a
120
* provider-configuration file named
121
* {@code java.net.FtpClientProvider} in the resource
122
* directory {@code META-INF/services}, then the first class name
123
* specified in that file is taken. The class is loaded and
124
* instantiated; if this process fails then an unspecified unchecked error or exception is
125
* thrown. </p></li>
126
*
127
* <li><p> Finally, if no provider has been specified by any of the above
128
* means then the system-default provider class is instantiated and the
129
* result is returned. </p></li>
130
*
131
* </ol>
132
*
133
* <p> Subsequent invocations of this method return the provider that was
134
* returned by the first invocation. </p>
135
*
136
* @return The system-wide default FtpClientProvider
137
*/
138
@SuppressWarnings("removal")
139
public static FtpClientProvider provider() {
140
synchronized (lock) {
141
if (provider != null) {
142
return provider;
143
}
144
return (FtpClientProvider) AccessController.doPrivileged(
145
new PrivilegedAction<Object>() {
146
147
public Object run() {
148
if (loadProviderFromProperty()) {
149
return provider;
150
}
151
if (loadProviderAsService()) {
152
return provider;
153
}
154
provider = new sun.net.ftp.impl.DefaultFtpClientProvider();
155
return provider;
156
}
157
});
158
}
159
}
160
}
161
162