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
26 package sun.applet;
27
28 import java.lang.NullPointerException;
29 import java.net.URL;
30 import java.net.URLClassLoader;
31 import java.net.SocketPermission;
32 import java.net.URLConnection;
33 import java.net.MalformedURLException;
34 import java.net.InetAddress;
35 import java.net.UnknownHostException;
36 import java.io.File;
37 import java.io.FilePermission;
38 import java.io.IOException;
39 import java.io.BufferedInputStream;
40 import java.io.InputStream;
41 import java.util.Enumeration;
42 import java.util.HashMap;
43 import java.util.NoSuchElementException;
44 import java.security.AccessController;
45 import java.security.AccessControlContext;
46 import java.security.PrivilegedAction;
47 import java.security.PrivilegedExceptionAction;
48 import java.security.PrivilegedActionException;
49 import java.security.CodeSource;
50 import java.security.Permission;
51 import java.security.PermissionCollection;
52 import sun.awt.AppContext;
53 import sun.awt.SunToolkit;
54 import sun.misc.IOUtils;
55 import sun.misc.ManagedLocalsThread;
56 import sun.net.www.ParseUtil;
57 import sun.security.util.SecurityConstants;
58
59 /**
60 * This class defines the class loader for loading applet classes and
61 * resources. It extends URLClassLoader to search the applet code base
62 * for the class or resource after checking any loaded JAR files.
63 */
64 public class AppletClassLoader extends URLClassLoader {
65 private URL base; /* applet code base URL */
66 private CodeSource codesource; /* codesource for the base URL */
67 private AccessControlContext acc;
68 private boolean exceptionStatus = false;
69
70 private final Object threadGroupSynchronizer = new Object();
71 private final Object grabReleaseSynchronizer = new Object();
72
73 private boolean codebaseLookup = true;
74 private volatile boolean allowRecursiveDirectoryRead = true;
317 */
318 private static byte[] getBytes(URL url) throws IOException {
319 URLConnection uc = url.openConnection();
320 if (uc instanceof java.net.HttpURLConnection) {
321 java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc;
322 int code = huc.getResponseCode();
323 if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) {
324 throw new IOException("open HTTP connection failed.");
325 }
326 }
327 int len = uc.getContentLength();
328
329 // Fixed #4507227: Slow performance to load
330 // class and resources. [stanleyh]
331 //
332 // Use buffered input stream [stanleyh]
333 InputStream in = new BufferedInputStream(uc.getInputStream());
334
335 byte[] b;
336 try {
337 b = IOUtils.readFully(in, len, true);
338 } finally {
339 in.close();
340 }
341 return b;
342 }
343
344 // Object for synchronization around getResourceAsStream()
345 private Object syncResourceAsStream = new Object();
346 private Object syncResourceAsStreamFromJar = new Object();
347
348 // Flag to indicate getResourceAsStream() is in call
349 private boolean resourceAsStreamInCall = false;
350 private boolean resourceAsStreamFromJarInCall = false;
351
352 /**
353 * Returns an input stream for reading the specified resource.
354 *
355 * The search order is described in the documentation for {@link
356 * #getResource(String)}.<p>
357 *
|
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
26 package sun.applet;
27
28 import java.lang.NullPointerException;
29 import java.net.URL;
30 import java.net.URLClassLoader;
31 import java.net.SocketPermission;
32 import java.net.URLConnection;
33 import java.net.MalformedURLException;
34 import java.net.InetAddress;
35 import java.net.UnknownHostException;
36 import java.io.EOFException;
37 import java.io.File;
38 import java.io.FilePermission;
39 import java.io.IOException;
40 import java.io.BufferedInputStream;
41 import java.io.InputStream;
42 import java.util.Enumeration;
43 import java.util.HashMap;
44 import java.util.NoSuchElementException;
45 import java.security.AccessController;
46 import java.security.AccessControlContext;
47 import java.security.PrivilegedAction;
48 import java.security.PrivilegedExceptionAction;
49 import java.security.PrivilegedActionException;
50 import java.security.CodeSource;
51 import java.security.Permission;
52 import java.security.PermissionCollection;
53 import sun.awt.AppContext;
54 import sun.awt.SunToolkit;
55 import sun.misc.ManagedLocalsThread;
56 import sun.net.www.ParseUtil;
57 import sun.security.util.SecurityConstants;
58
59 /**
60 * This class defines the class loader for loading applet classes and
61 * resources. It extends URLClassLoader to search the applet code base
62 * for the class or resource after checking any loaded JAR files.
63 */
64 public class AppletClassLoader extends URLClassLoader {
65 private URL base; /* applet code base URL */
66 private CodeSource codesource; /* codesource for the base URL */
67 private AccessControlContext acc;
68 private boolean exceptionStatus = false;
69
70 private final Object threadGroupSynchronizer = new Object();
71 private final Object grabReleaseSynchronizer = new Object();
72
73 private boolean codebaseLookup = true;
74 private volatile boolean allowRecursiveDirectoryRead = true;
317 */
318 private static byte[] getBytes(URL url) throws IOException {
319 URLConnection uc = url.openConnection();
320 if (uc instanceof java.net.HttpURLConnection) {
321 java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc;
322 int code = huc.getResponseCode();
323 if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) {
324 throw new IOException("open HTTP connection failed.");
325 }
326 }
327 int len = uc.getContentLength();
328
329 // Fixed #4507227: Slow performance to load
330 // class and resources. [stanleyh]
331 //
332 // Use buffered input stream [stanleyh]
333 InputStream in = new BufferedInputStream(uc.getInputStream());
334
335 byte[] b;
336 try {
337 b = in.readAllBytes();
338 if (len != -1 && b.length != len)
339 throw new EOFException("Expected:" + len + ", read:" + b.length);
340 } finally {
341 in.close();
342 }
343 return b;
344 }
345
346 // Object for synchronization around getResourceAsStream()
347 private Object syncResourceAsStream = new Object();
348 private Object syncResourceAsStreamFromJar = new Object();
349
350 // Flag to indicate getResourceAsStream() is in call
351 private boolean resourceAsStreamInCall = false;
352 private boolean resourceAsStreamFromJarInCall = false;
353
354 /**
355 * Returns an input stream for reading the specified resource.
356 *
357 * The search order is described in the documentation for {@link
358 * #getResource(String)}.<p>
359 *
|