1 /*
2 * Copyright (c) 1995, 2013, 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
780 *
781 * @param filename the file to load.
782 * @exception SecurityException if a security manager exists and its
783 * <code>checkLink</code> method doesn't allow
784 * loading of the specified dynamic library
785 * @exception UnsatisfiedLinkError if either the filename is not an
786 * absolute path name, the native library is not statically
787 * linked with the VM, or the library cannot be mapped to
788 * a native library image by the host system.
789 * @exception NullPointerException if <code>filename</code> is
790 * <code>null</code>
791 * @see java.lang.Runtime#getRuntime()
792 * @see java.lang.SecurityException
793 * @see java.lang.SecurityManager#checkLink(java.lang.String)
794 */
795 @CallerSensitive
796 public void load(String filename) {
797 load0(Reflection.getCallerClass(), filename);
798 }
799
800 synchronized void load0(Class<?> fromClass, String filename) {
801 SecurityManager security = System.getSecurityManager();
802 if (security != null) {
803 security.checkLink(filename);
804 }
805 if (!(new File(filename).isAbsolute())) {
806 throw new UnsatisfiedLinkError(
807 "Expecting an absolute path of the library: " + filename);
808 }
809 ClassLoader.loadLibrary(fromClass, filename, true);
810 }
811
812 /**
813 * Loads the native library specified by the <code>libname</code>
814 * argument. The <code>libname</code> argument must not contain any platform
815 * specific prefix, file extension or path. If a native library
816 * called <code>libname</code> is statically linked with the VM, then the
817 * JNI_OnLoad_<code>libname</code> function exported by the library is invoked.
818 * See the JNI Specification for more details.
819 *
820 * Otherwise, the libname argument is loaded from a system library
841 * name, the second and subsequent calls are ignored.
842 *
843 * @param libname the name of the library.
844 * @exception SecurityException if a security manager exists and its
845 * <code>checkLink</code> method doesn't allow
846 * loading of the specified dynamic library
847 * @exception UnsatisfiedLinkError if either the libname argument
848 * contains a file path, the native library is not statically
849 * linked with the VM, or the library cannot be mapped to a
850 * native library image by the host system.
851 * @exception NullPointerException if <code>libname</code> is
852 * <code>null</code>
853 * @see java.lang.SecurityException
854 * @see java.lang.SecurityManager#checkLink(java.lang.String)
855 */
856 @CallerSensitive
857 public void loadLibrary(String libname) {
858 loadLibrary0(Reflection.getCallerClass(), libname);
859 }
860
861 synchronized void loadLibrary0(Class<?> fromClass, String libname) {
862 SecurityManager security = System.getSecurityManager();
863 if (security != null) {
864 security.checkLink(libname);
865 }
866 if (libname.indexOf((int)File.separatorChar) != -1) {
867 throw new UnsatisfiedLinkError(
868 "Directory separator should not appear in library name: " + libname);
869 }
870 ClassLoader.loadLibrary(fromClass, libname, false);
871 }
872
873 /**
874 * Creates a localized version of an input stream. This method takes
875 * an <code>InputStream</code> and returns an <code>InputStream</code>
876 * equivalent to the argument in all respects except that it is
877 * localized: as characters in the local character set are read from
878 * the stream, they are automatically converted from the local
879 * character set to Unicode.
880 * <p>
881 * If the argument is already a localized stream, it may be returned
|
1 /*
2 * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2019, Azul Systems, Inc. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation. Oracle designates this
9 * particular file as subject to the "Classpath" exception as provided
10 * by Oracle in the LICENSE file that accompanied this code.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23 * or visit www.oracle.com if you need additional information or have any
781 *
782 * @param filename the file to load.
783 * @exception SecurityException if a security manager exists and its
784 * <code>checkLink</code> method doesn't allow
785 * loading of the specified dynamic library
786 * @exception UnsatisfiedLinkError if either the filename is not an
787 * absolute path name, the native library is not statically
788 * linked with the VM, or the library cannot be mapped to
789 * a native library image by the host system.
790 * @exception NullPointerException if <code>filename</code> is
791 * <code>null</code>
792 * @see java.lang.Runtime#getRuntime()
793 * @see java.lang.SecurityException
794 * @see java.lang.SecurityManager#checkLink(java.lang.String)
795 */
796 @CallerSensitive
797 public void load(String filename) {
798 load0(Reflection.getCallerClass(), filename);
799 }
800
801 void load0(Class<?> fromClass, String filename) {
802 SecurityManager security = System.getSecurityManager();
803 if (security != null) {
804 security.checkLink(filename);
805 }
806 if (!(new File(filename).isAbsolute())) {
807 throw new UnsatisfiedLinkError(
808 "Expecting an absolute path of the library: " + filename);
809 }
810 ClassLoader.loadLibrary(fromClass, filename, true);
811 }
812
813 /**
814 * Loads the native library specified by the <code>libname</code>
815 * argument. The <code>libname</code> argument must not contain any platform
816 * specific prefix, file extension or path. If a native library
817 * called <code>libname</code> is statically linked with the VM, then the
818 * JNI_OnLoad_<code>libname</code> function exported by the library is invoked.
819 * See the JNI Specification for more details.
820 *
821 * Otherwise, the libname argument is loaded from a system library
842 * name, the second and subsequent calls are ignored.
843 *
844 * @param libname the name of the library.
845 * @exception SecurityException if a security manager exists and its
846 * <code>checkLink</code> method doesn't allow
847 * loading of the specified dynamic library
848 * @exception UnsatisfiedLinkError if either the libname argument
849 * contains a file path, the native library is not statically
850 * linked with the VM, or the library cannot be mapped to a
851 * native library image by the host system.
852 * @exception NullPointerException if <code>libname</code> is
853 * <code>null</code>
854 * @see java.lang.SecurityException
855 * @see java.lang.SecurityManager#checkLink(java.lang.String)
856 */
857 @CallerSensitive
858 public void loadLibrary(String libname) {
859 loadLibrary0(Reflection.getCallerClass(), libname);
860 }
861
862 void loadLibrary0(Class<?> fromClass, String libname) {
863 SecurityManager security = System.getSecurityManager();
864 if (security != null) {
865 security.checkLink(libname);
866 }
867 if (libname.indexOf((int)File.separatorChar) != -1) {
868 throw new UnsatisfiedLinkError(
869 "Directory separator should not appear in library name: " + libname);
870 }
871 ClassLoader.loadLibrary(fromClass, libname, false);
872 }
873
874 /**
875 * Creates a localized version of an input stream. This method takes
876 * an <code>InputStream</code> and returns an <code>InputStream</code>
877 * equivalent to the argument in all respects except that it is
878 * localized: as characters in the local character set are read from
879 * the stream, they are automatically converted from the local
880 * character set to Unicode.
881 * <p>
882 * If the argument is already a localized stream, it may be returned
|