src/share/classes/java/lang/Runtime.java

Print this page




 763      * name, allowing any file of native code to be loaded.
 764      * <p>
 765      * The method {@link System#load(String)} is the conventional and
 766      * convenient means of invoking this method.
 767      *
 768      * @param      filename   the file to load.
 769      * @exception  SecurityException  if a security manager exists and its
 770      *             <code>checkLink</code> method doesn't allow
 771      *             loading of the specified dynamic library
 772      * @exception  UnsatisfiedLinkError  if the file does not exist.
 773      * @exception  NullPointerException if <code>filename</code> is
 774      *             <code>null</code>
 775      * @see        java.lang.Runtime#getRuntime()
 776      * @see        java.lang.SecurityException
 777      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
 778      */
 779     public void load(String filename) {
 780         load0(System.getCallerClass(), filename);
 781     }
 782 
 783     synchronized void load0(Class fromClass, String filename) {
 784         SecurityManager security = System.getSecurityManager();
 785         if (security != null) {
 786             security.checkLink(filename);
 787         }
 788         if (!(new File(filename).isAbsolute())) {
 789             throw new UnsatisfiedLinkError(
 790                 "Expecting an absolute path of the library: " + filename);
 791         }
 792         ClassLoader.loadLibrary(fromClass, filename, true);
 793     }
 794 
 795     /**
 796      * Loads the dynamic library with the specified library name.
 797      * A file containing native code is loaded from the local file system
 798      * from a place where library files are conventionally obtained. The
 799      * details of this process are implementation-dependent. The
 800      * mapping from a library name to a specific filename is done in a
 801      * system-specific manner.
 802      * <p>
 803      * First, if there is a security manager, its <code>checkLink</code>


 816      * initialized, the necessary native code implementation for the native
 817      * methods will then be loaded as well.
 818      * <p>
 819      * If this method is called more than once with the same library
 820      * name, the second and subsequent calls are ignored.
 821      *
 822      * @param      libname   the name of the library.
 823      * @exception  SecurityException  if a security manager exists and its
 824      *             <code>checkLink</code> method doesn't allow
 825      *             loading of the specified dynamic library
 826      * @exception  UnsatisfiedLinkError  if the library does not exist.
 827      * @exception  NullPointerException if <code>libname</code> is
 828      *             <code>null</code>
 829      * @see        java.lang.SecurityException
 830      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
 831      */
 832     public void loadLibrary(String libname) {
 833         loadLibrary0(System.getCallerClass(), libname);
 834     }
 835 
 836     synchronized void loadLibrary0(Class fromClass, String libname) {
 837         SecurityManager security = System.getSecurityManager();
 838         if (security != null) {
 839             security.checkLink(libname);
 840         }
 841         if (libname.indexOf((int)File.separatorChar) != -1) {
 842             throw new UnsatisfiedLinkError(
 843     "Directory separator should not appear in library name: " + libname);
 844         }
 845         ClassLoader.loadLibrary(fromClass, libname, false);
 846     }
 847 
 848     /**
 849      * Creates a localized version of an input stream. This method takes
 850      * an <code>InputStream</code> and returns an <code>InputStream</code>
 851      * equivalent to the argument in all respects except that it is
 852      * localized: as characters in the local character set are read from
 853      * the stream, they are automatically converted from the local
 854      * character set to Unicode.
 855      * <p>
 856      * If the argument is already a localized stream, it may be returned




 763      * name, allowing any file of native code to be loaded.
 764      * <p>
 765      * The method {@link System#load(String)} is the conventional and
 766      * convenient means of invoking this method.
 767      *
 768      * @param      filename   the file to load.
 769      * @exception  SecurityException  if a security manager exists and its
 770      *             <code>checkLink</code> method doesn't allow
 771      *             loading of the specified dynamic library
 772      * @exception  UnsatisfiedLinkError  if the file does not exist.
 773      * @exception  NullPointerException if <code>filename</code> is
 774      *             <code>null</code>
 775      * @see        java.lang.Runtime#getRuntime()
 776      * @see        java.lang.SecurityException
 777      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
 778      */
 779     public void load(String filename) {
 780         load0(System.getCallerClass(), filename);
 781     }
 782 
 783     synchronized void load0(Class<?> fromClass, String filename) {
 784         SecurityManager security = System.getSecurityManager();
 785         if (security != null) {
 786             security.checkLink(filename);
 787         }
 788         if (!(new File(filename).isAbsolute())) {
 789             throw new UnsatisfiedLinkError(
 790                 "Expecting an absolute path of the library: " + filename);
 791         }
 792         ClassLoader.loadLibrary(fromClass, filename, true);
 793     }
 794 
 795     /**
 796      * Loads the dynamic library with the specified library name.
 797      * A file containing native code is loaded from the local file system
 798      * from a place where library files are conventionally obtained. The
 799      * details of this process are implementation-dependent. The
 800      * mapping from a library name to a specific filename is done in a
 801      * system-specific manner.
 802      * <p>
 803      * First, if there is a security manager, its <code>checkLink</code>


 816      * initialized, the necessary native code implementation for the native
 817      * methods will then be loaded as well.
 818      * <p>
 819      * If this method is called more than once with the same library
 820      * name, the second and subsequent calls are ignored.
 821      *
 822      * @param      libname   the name of the library.
 823      * @exception  SecurityException  if a security manager exists and its
 824      *             <code>checkLink</code> method doesn't allow
 825      *             loading of the specified dynamic library
 826      * @exception  UnsatisfiedLinkError  if the library does not exist.
 827      * @exception  NullPointerException if <code>libname</code> is
 828      *             <code>null</code>
 829      * @see        java.lang.SecurityException
 830      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
 831      */
 832     public void loadLibrary(String libname) {
 833         loadLibrary0(System.getCallerClass(), libname);
 834     }
 835 
 836     synchronized void loadLibrary0(Class<?> fromClass, String libname) {
 837         SecurityManager security = System.getSecurityManager();
 838         if (security != null) {
 839             security.checkLink(libname);
 840         }
 841         if (libname.indexOf((int)File.separatorChar) != -1) {
 842             throw new UnsatisfiedLinkError(
 843     "Directory separator should not appear in library name: " + libname);
 844         }
 845         ClassLoader.loadLibrary(fromClass, libname, false);
 846     }
 847 
 848     /**
 849      * Creates a localized version of an input stream. This method takes
 850      * an <code>InputStream</code> and returns an <code>InputStream</code>
 851      * equivalent to the argument in all respects except that it is
 852      * localized: as characters in the local character set are read from
 853      * the stream, they are automatically converted from the local
 854      * character set to Unicode.
 855      * <p>
 856      * If the argument is already a localized stream, it may be returned