if (permissionStorage == null || isReadOnly() || !permissionStorage.isDirty())
return;
if (Debug.DEBUG && Debug.DEBUG_GENERAL)
Debug.println("About to save permission data ..."); //$NON-NLS-1$
try {
ManagedOutputStream fmos = storageManager.getOutputStream(PERM_DATA_FILE);
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(fmos));
boolean error = true;
try {
out.writeByte(PERMDATA_VERSION);
// always write the default permissions first
String[] defaultPerms = permissionStorage.getPermissionData(null);
out.writeInt(defaultPerms == null ? 0 : defaultPerms.length);
if (defaultPerms != null)
for (int i = 0; i < defaultPerms.length; i++)
out.writeUTF(defaultPerms[i]);
String[] locations = permissionStorage.getLocations();
out.writeInt(locations == null ? 0 : locations.length);
if (locations != null)
for (int i = 0; i < locations.length; i++) {
out.writeUTF(locations[i]);
String[] perms = permissionStorage.getPermissionData(locations[i]);
out.writeInt(perms == null ? 0 : perms.length);
if (perms != null)
for (int j = 0; j < perms.length; j++)
out.writeUTF(perms[j]);
}
String[] condPerms = permissionStorage.getConditionalPermissionInfos();
out.writeInt(condPerms == null ? 0 : condPerms.length);
if (condPerms != null)
for (int i = 0; i < condPerms.length; i++)
out.writeUTF(condPerms[i]);
out.close();
permissionStorage.setDirty(false);
error = false;
} finally {
// if something happens, don't close a corrupt file
if (error) {
fmos.abort();
try {
out.close();
} catch (IOException e) {/*ignore*/
}
}