Package org.eclipse.osgi.framework.util
Class SecureAction
java.lang.Object
org.eclipse.osgi.framework.util.SecureAction
Utility class to execute common privileged code.
- Since:
- 3.1
-
Method Summary
Modifier and TypeMethodDescriptionstatic PrivilegedAction<SecureAction>
Creates a privileged action that can be used to construct a SecureAction object.createThread
(Runnable target, String name, ClassLoader contextLoader) Creates a new Thread from a Runnable.boolean
Returns true if a file exists, otherwise false is returned.Class<?>
Returns a Class.getAbsoluteFile
(File file) Returns the absolute file.getCanonicalFile
(File file) Returns the canonical file.getCanonicalPath
(File file) Returns the canonical path of a file.getContext
(Bundle bundle) getFileInputStream
(File file) Creates a FileInputStream from a File.getFileOutputStream
(File file, boolean append) Creates a FileInputStream from a File.getLocation
(Bundle bundle) Returns a system properties.getProperty
(String property) Returns a system property.<S> S
getService
(ServiceReference<S> reference, BundleContext context) Gets a service object.getURL
(String protocol, String host, int port, String file, URLStreamHandler handler) Gets a URL.getZipFile
(File file, boolean verify) Returns a ZipFile.boolean
isDirectory
(File file) Returns true if a file is a directory, otherwise false is returned.long
lastModified
(File file) Returns a file's last modified stamp.long
Returns the length of a file.String[]
Returns a file's list.Class<?>
loadSystemClass
(String name) Returns a Class.boolean
void
open
(ServiceTracker<?, ?> tracker) Opens a ServiceTracker.void
start
(Module module, Module.StartOptions... options) Starts a module.
-
Method Details
-
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
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
Returns a system properties. Same as calling System.getProperties().- Returns:
- the system properties.
-
getFileInputStream
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
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
Returns the length of a file. Same as calling file.length().- Parameters:
file
- a file object- Returns:
- the length of a file.
-
getCanonicalPath
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
Returns the absolute file. Same as calling file.getAbsoluteFile().- Parameters:
file
- a file object- Returns:
- the absolute file.
-
getCanonicalFile
Returns the canonical file. Same as calling file.getCanonicalFile().- Parameters:
file
- a file object- Returns:
- the canonical file.
- Throws:
IOException
-
exists
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
-
isDirectory
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
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
Returns a file's list. Same as calling file.list().- Parameters:
file
- a file object- Returns:
- a file's list.
-
getZipFile
Returns a ZipFile. Same as calling new ZipFile(file)- Parameters:
file
- the file to get a ZipFile forverify
- 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 Gets a URL. Same a callingURL(java.lang.String, java.lang.String, int, java.lang.String, java.net.URLStreamHandler)
- Parameters:
protocol
- the protocolhost
- the hostport
- the portfile
- the filehandler
- the URLStreamHandler- Returns:
- a URL
- Throws:
MalformedURLException
-
createThread
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
Gets a service object. Same as calling context.getService(reference)- Parameters:
reference
- the ServiceReferencecontext
- the BundleContext- Returns:
- a service object
-
forName
Returns a Class. Same as calling Class.forName(name)- Parameters:
name
- the name of the class.- Returns:
- a Class
- Throws:
ClassNotFoundException
-
loadSystemClass
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
Opens a ServiceTracker. Same as calling tracker.open()- Parameters:
tracker
- the ServiceTracker to open.
-
start
Starts a module.- Parameters:
module
- the module to startoptions
- the start options- Throws:
BundleException
-
getContext
-
getLocation
-