Method from java.util.prefs.FileSystemPreferences Detail: |
protected AbstractPreferences childSpi(String name) {
return new FileSystemPreferences(this, name);
}
|
protected String[] childrenNamesSpi() {
return AccessController.doPrivileged(
new PrivilegedAction< String[] >() {
public String[] run() {
List< String > result = new ArrayList< >();
File[] dirContents = dir.listFiles();
if (dirContents != null) {
for (int i = 0; i < dirContents.length; i++)
if (dirContents[i].isDirectory())
result.add(nodeName(dirContents[i].getName()));
}
return result.toArray(EMPTY_STRING_ARRAY);
}
});
}
|
public void flush() throws BackingStoreException {
if (isRemoved())
return;
sync();
}
|
protected void flushSpi() throws BackingStoreException {
// assert false;
}
|
protected String getSpi(String key) {
initCacheIfNecessary();
return prefsCache.get(key);
}
|
static synchronized Preferences getSystemRoot() {
if (systemRoot == null) {
setupSystemRoot();
systemRoot = new FileSystemPreferences(false);
}
return systemRoot;
}
|
static synchronized Preferences getUserRoot() {
if (userRoot == null) {
setupUserRoot();
userRoot = new FileSystemPreferences(true);
}
return userRoot;
}
|
public boolean isUserNode() {
return isUserNode;
}
|
protected String[] keysSpi() {
initCacheIfNecessary();
return prefsCache.keySet().toArray(new String[prefsCache.size()]);
}
|
protected void putSpi(String key,
String value) {
initCacheIfNecessary();
changeLog.add(new Put(key, value));
prefsCache.put(key, value);
}
|
public void removeNode() throws BackingStoreException {
synchronized (isUserNode()? userLockFile: systemLockFile) {
// to remove a node we need an exclusive lock
if (!lockFile(false))
throw(new BackingStoreException("Couldn't get file lock."));
try {
super.removeNode();
} finally {
unlockFile();
}
}
}
|
protected void removeNodeSpi() throws BackingStoreException {
try {
AccessController.doPrivileged(
new PrivilegedExceptionAction< Void >() {
public Void run() throws BackingStoreException {
if (changeLog.contains(nodeCreate)) {
changeLog.remove(nodeCreate);
nodeCreate = null;
return null;
}
if (!dir.exists())
return null;
prefsFile.delete();
tmpFile.delete();
// dir should be empty now. If it's not, empty it
File[] junk = dir.listFiles();
if (junk.length != 0) {
getLogger().warning(
"Found extraneous files when removing node: "
+ Arrays.asList(junk));
for (int i=0; i< junk.length; i++)
junk[i].delete();
}
if (!dir.delete())
throw new BackingStoreException("Couldn't delete dir: "
+ dir);
return null;
}
});
} catch (PrivilegedActionException e) {
throw (BackingStoreException) e.getException();
}
}
Called with file lock held (in addition to node locks). |
protected void removeSpi(String key) {
initCacheIfNecessary();
changeLog.add(new Remove(key));
prefsCache.remove(key);
}
|
public synchronized void sync() throws BackingStoreException {
boolean userNode = isUserNode();
boolean shared;
if (userNode) {
shared = false; /* use exclusive lock for user prefs */
} else {
/* if can write to system root, use exclusive lock.
otherwise use shared lock. */
shared = !isSystemRootWritable;
}
synchronized (isUserNode()? userLockFile:systemLockFile) {
if (!lockFile(shared))
throw(new BackingStoreException("Couldn't get file lock."));
final Long newModTime =
AccessController.doPrivileged(
new PrivilegedAction< Long >() {
public Long run() {
long nmt;
if (isUserNode()) {
nmt = userRootModFile.lastModified();
isUserRootModified = userRootModTime == nmt;
} else {
nmt = systemRootModFile.lastModified();
isSystemRootModified = systemRootModTime == nmt;
}
return new Long(nmt);
}
});
try {
super.sync();
AccessController.doPrivileged(new PrivilegedAction< Void >() {
public Void run() {
if (isUserNode()) {
userRootModTime = newModTime.longValue() + 1000;
userRootModFile.setLastModified(userRootModTime);
} else {
systemRootModTime = newModTime.longValue() + 1000;
systemRootModFile.setLastModified(systemRootModTime);
}
return null;
}
});
} finally {
unlockFile();
}
}
}
|
protected void syncSpi() throws BackingStoreException {
try {
AccessController.doPrivileged(
new PrivilegedExceptionAction< Void >() {
public Void run() throws BackingStoreException {
syncSpiPrivileged();
return null;
}
});
} catch (PrivilegedActionException e) {
throw (BackingStoreException) e.getException();
}
}
|