diff options
Diffstat (limited to 'bundles/org.eclipse.osgi/supplement/src')
-rw-r--r-- | bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/util/SecureAction.java | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/util/SecureAction.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/util/SecureAction.java index 2e654b16c..5fb4cef0d 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/util/SecureAction.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/util/SecureAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2010 IBM Corporation and others. + * Copyright (c) 2003, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -198,6 +198,44 @@ public class SecureAction { } /** + * Returns the absolute file. Same as calling + * file.getAbsoluteFile(). + * @param file a file object + * @return the absolute file. + */ + public File getAbsoluteFile(final File file) { + if (System.getSecurityManager() == null) + return file.getAbsoluteFile(); + return AccessController.doPrivileged(new PrivilegedAction<File>() { + public File run() { + return file.getAbsoluteFile(); + } + }, controlContext); + } + + /** + * Returns the canonical file. Same as calling + * file.getCanonicalFile(). + * @param file a file object + * @return the canonical file. + */ + public File getCanonicalFile(final File file) throws IOException { + if (System.getSecurityManager() == null) + return file.getCanonicalFile(); + try { + return AccessController.doPrivileged(new PrivilegedExceptionAction<File>() { + public File run() throws IOException { + return file.getCanonicalFile(); + } + }, controlContext); + } catch (PrivilegedActionException e) { + if (e.getException() instanceof IOException) + throw (IOException) e.getException(); + throw (RuntimeException) e.getException(); + } + } + + /** * Returns true if a file exists, otherwise false is returned. Same as calling * file.exists(). * @param file a file object |