22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.misc;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.Closeable;
30 import java.io.File;
31 import java.io.FileInputStream;
32 import java.io.FileNotFoundException;
33 import java.io.IOException;
34 import java.io.InputStream;
35 import java.net.HttpURLConnection;
36 import java.net.JarURLConnection;
37 import java.net.MalformedURLException;
38 import java.net.URL;
39 import java.net.URLConnection;
40 import java.net.URLStreamHandler;
41 import java.net.URLStreamHandlerFactory;
42 import java.security.AccessControlException;
43 import java.security.AccessController;
44 import java.security.CodeSigner;
45 import java.security.Permission;
46 import java.security.PrivilegedExceptionAction;
47 import java.security.cert.Certificate;
48 import java.util.ArrayList;
49 import java.util.Collections;
50 import java.util.Enumeration;
51 import java.util.HashMap;
52 import java.util.HashSet;
53 import java.util.LinkedList;
54 import java.util.List;
55 import java.util.NoSuchElementException;
56 import java.util.Set;
57 import java.util.Stack;
58 import java.util.StringTokenizer;
59 import java.util.concurrent.atomic.AtomicInteger;
60 import java.util.jar.JarFile;
61 import java.util.zip.ZipEntry;
782 try {
783 url = new URL(getBaseURL(), ParseUtil.encodePath(name, false));
784 if (check) {
785 URLClassPath.check(url);
786 }
787 } catch (MalformedURLException e) {
788 return null;
789 // throw new IllegalArgumentException("name");
790 } catch (IOException e) {
791 return null;
792 } catch (AccessControlException e) {
793 return null;
794 }
795
796 return new Resource() {
797 public String getName() { return name; }
798 public URL getURL() { return url; }
799 public URL getCodeSourceURL() { return csu; }
800 public InputStream getInputStream() throws IOException
801 { return jar.getInputStream(entry); }
802 public int getContentLength()
803 { return (int)entry.getSize(); }
804 public Manifest getManifest() throws IOException
805 { return jar.getManifest(); };
806 public Certificate[] getCertificates()
807 { return entry.getCertificates(); };
808 public CodeSigner[] getCodeSigners()
809 { return entry.getCodeSigners(); };
810 };
811 }
812
813
814 /*
815 * Returns true iff atleast one resource in the jar file has the same
816 * package name as that of the specified resource name.
817 */
818 boolean validIndex(final String name) {
819 String packageName = name;
820 int pos;
821 if((pos = name.lastIndexOf('/')) != -1) {
|
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.misc;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.Closeable;
30 import java.io.File;
31 import java.io.FileInputStream;
32 import java.io.FileNotFoundException;
33 import java.io.IOException;
34 import java.io.InputStream;
35 import java.net.HttpURLConnection;
36 import java.net.JarURLConnection;
37 import java.net.MalformedURLException;
38 import java.net.URL;
39 import java.net.URLConnection;
40 import java.net.URLStreamHandler;
41 import java.net.URLStreamHandlerFactory;
42 import java.nio.ByteBuffer;
43 import java.security.AccessControlException;
44 import java.security.AccessController;
45 import java.security.CodeSigner;
46 import java.security.Permission;
47 import java.security.PrivilegedExceptionAction;
48 import java.security.cert.Certificate;
49 import java.util.ArrayList;
50 import java.util.Collections;
51 import java.util.Enumeration;
52 import java.util.HashMap;
53 import java.util.HashSet;
54 import java.util.LinkedList;
55 import java.util.List;
56 import java.util.NoSuchElementException;
57 import java.util.Set;
58 import java.util.Stack;
59 import java.util.StringTokenizer;
60 import java.util.concurrent.atomic.AtomicInteger;
61 import java.util.jar.JarFile;
62 import java.util.zip.ZipEntry;
783 try {
784 url = new URL(getBaseURL(), ParseUtil.encodePath(name, false));
785 if (check) {
786 URLClassPath.check(url);
787 }
788 } catch (MalformedURLException e) {
789 return null;
790 // throw new IllegalArgumentException("name");
791 } catch (IOException e) {
792 return null;
793 } catch (AccessControlException e) {
794 return null;
795 }
796
797 return new Resource() {
798 public String getName() { return name; }
799 public URL getURL() { return url; }
800 public URL getCodeSourceURL() { return csu; }
801 public InputStream getInputStream() throws IOException
802 { return jar.getInputStream(entry); }
803 @Override
804 public ByteBuffer getByteBuffer() throws IOException
805 { return ByteBuffer.wrap(getBytes()); }
806 @Override
807 public byte[] getBytes() throws IOException {
808 return zipAccess.getBytes(jar, entry);
809 }
810 public int getContentLength()
811 { return (int)entry.getSize(); }
812 public Manifest getManifest() throws IOException
813 { return jar.getManifest(); };
814 public Certificate[] getCertificates()
815 { return entry.getCertificates(); };
816 public CodeSigner[] getCodeSigners()
817 { return entry.getCodeSigners(); };
818 };
819 }
820
821
822 /*
823 * Returns true iff atleast one resource in the jar file has the same
824 * package name as that of the specified resource name.
825 */
826 boolean validIndex(final String name) {
827 String packageName = name;
828 int pos;
829 if((pos = name.lastIndexOf('/')) != -1) {
|