Class SecureAction

java.lang.Object
org.eclipse.osgi.framework.util.SecureAction

public class SecureAction extends Object
Utility class to execute common privileged code.
Since:
3.1
  • Method Details

    • createSecureAction

      public static PrivilegedAction<SecureAction> createSecureAction()
      Creates a privileged action that can be used to construct a SecureAction object. The recommended way to construct a SecureAction object is the following:
       SecureAction secureAction = (SecureAction) AccessController.doPrivileged(SecureAction.createSecureAction());
       
      Returns:
      a privileged action object that can be used to construct a SecureAction object.
    • getProperty

      public String getProperty(String property)
      Returns a system property. Same as calling System.getProperty(String).
      Parameters:
      property - the property key.
      Returns:
      the value of the property or null if it does not exist.
    • getProperties

      public Properties getProperties()
      Returns a system properties. Same as calling System.getProperties().
      Returns:
      the system properties.
    • getFileInputStream

      public FileInputStream getFileInputStream(File file) throws FileNotFoundException
      Creates a FileInputStream from a File. Same as calling new FileInputStream(File).
      Parameters:
      file - the File to craete a FileInputStream from.
      Returns:
      The FileInputStream.
      Throws:
      FileNotFoundException - if the File does not exist.
    • getFileOutputStream

      public FileOutputStream getFileOutputStream(File file, boolean append) throws FileNotFoundException
      Creates a FileInputStream from a File. Same as calling new FileOutputStream(File,boolean).
      Parameters:
      file - the File to create a FileOutputStream from.
      append - indicates if the OutputStream should append content.
      Returns:
      The FileOutputStream.
      Throws:
      FileNotFoundException - if the File does not exist.
    • length

      public long length(File file)
      Returns the length of a file. Same as calling file.length().
      Parameters:
      file - a file object
      Returns:
      the length of a file.
    • getCanonicalPath

      public String getCanonicalPath(File file) throws IOException
      Returns the canonical path of a file. Same as calling file.getCanonicalPath().
      Parameters:
      file - a file object
      Returns:
      the canonical path of a file.
      Throws:
      IOException - on error
    • getAbsoluteFile

      public File getAbsoluteFile(File file)
      Returns the absolute file. Same as calling file.getAbsoluteFile().
      Parameters:
      file - a file object
      Returns:
      the absolute file.
    • getCanonicalFile

      public File getCanonicalFile(File file) throws IOException
      Returns the canonical file. Same as calling file.getCanonicalFile().
      Parameters:
      file - a file object
      Returns:
      the canonical file.
      Throws:
      IOException
    • exists

      public boolean exists(File file)
      Returns true if a file exists, otherwise false is returned. Same as calling file.exists().
      Parameters:
      file - a file object
      Returns:
      true if a file exists, otherwise false
    • mkdirs

      public boolean mkdirs(File file)
    • isDirectory

      public boolean isDirectory(File file)
      Returns true if a file is a directory, otherwise false is returned. Same as calling file.isDirectory().
      Parameters:
      file - a file object
      Returns:
      true if a file is a directory, otherwise false
    • lastModified

      public long lastModified(File file)
      Returns a file's last modified stamp. Same as calling file.lastModified().
      Parameters:
      file - a file object
      Returns:
      a file's last modified stamp.
    • list

      public String[] list(File file)
      Returns a file's list. Same as calling file.list().
      Parameters:
      file - a file object
      Returns:
      a file's list.
    • getZipFile

      public ZipFile getZipFile(File file, boolean verify) throws IOException
      Returns a ZipFile. Same as calling new ZipFile(file)
      Parameters:
      file - the file to get a ZipFile for
      verify - whether or not to verify the zip file if it is signed.
      Returns:
      a ZipFile
      Throws:
      IOException - if an error occured
    • getURL

      public URL getURL(String protocol, String host, int port, String file, URLStreamHandler handler) throws MalformedURLException
      Parameters:
      protocol - the protocol
      host - the host
      port - the port
      file - the file
      handler - the URLStreamHandler
      Returns:
      a URL
      Throws:
      MalformedURLException
    • createThread

      public Thread createThread(Runnable target, String name, ClassLoader contextLoader)
      Creates a new Thread from a Runnable. Same as calling new Thread(target,name).setContextClassLoader(contextLoader).
      Parameters:
      target - the Runnable to create the Thread from.
      name - The name of the Thread.
      contextLoader - the context class loader for the thread
      Returns:
      The new Thread
    • getService

      public <S> S getService(ServiceReference<S> reference, BundleContext context)
      Gets a service object. Same as calling context.getService(reference)
      Parameters:
      reference - the ServiceReference
      context - the BundleContext
      Returns:
      a service object
    • forName

      public Class<?> forName(String name) throws ClassNotFoundException
      Returns a Class. Same as calling Class.forName(name)
      Parameters:
      name - the name of the class.
      Returns:
      a Class
      Throws:
      ClassNotFoundException
    • loadSystemClass

      public Class<?> loadSystemClass(String name) throws ClassNotFoundException
      Returns a Class. Tries to load a class from the System ClassLoader or if that doesn't exist tries the boot ClassLoader
      Parameters:
      name - the name of the class.
      Returns:
      a Class
      Throws:
      ClassNotFoundException
    • open

      public void open(ServiceTracker<?,?> tracker)
      Opens a ServiceTracker. Same as calling tracker.open()
      Parameters:
      tracker - the ServiceTracker to open.
    • start

      public void start(Module module, Module.StartOptions... options) throws BundleException
      Starts a module.
      Parameters:
      module - the module to start
      options - the start options
      Throws:
      BundleException
    • getContext

      public BundleContext getContext(Bundle bundle)
    • getLocation

      public String getLocation(Bundle bundle)