code:     public void save() throws Exception {
  
          if (getReadonly()) {
              log.error(sm.getString("memoryUserDatabase.readOnly"));
              return;
          }
  
          if (!isWriteable()) {
              log.warn(sm.getString("memoryUserDatabase.notPersistable"));
              return;
          }
  
          // Write out contents to a temporary file
          File fileNew = new File(pathnameNew);
          if (!fileNew.isAbsolute()) {
              fileNew =
                  new File(System.getProperty(Globals.CATALINA_BASE_PROP), pathnameNew);
          }
          PrintWriter writer = null;
          try {
  
              // Configure our PrintWriter
              FileOutputStream fos = new FileOutputStream(fileNew);
              OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF8");
              writer = new PrintWriter(osw);
  
              // Print the file prolog
              writer.println("<?xml version='1.0' encoding='utf-8'?>");
              writer.println("<tomcat-users>");
  
              // Print entries for each defined role, group, and user
              Iterator<?> values = null;
              values = getRoles();
              while (values.hasNext()) {
                  writer.print("  ");
                  writer.println(values.next());
              }
              values = getGroups();
              while (values.hasNext()) {
                  writer.print("  ");
                  writer.println(values.next());
              }
              values = getUsers();
              while (values.hasNext()) {
                  writer.print("  ");
                  writer.println(values.next());
              }
  
              // Print the file epilog
              writer.println("</tomcat-users>");
  
              // Check for errors that occurred while printing
              if (writer.checkError()) {
                  writer.close();
                  fileNew.delete();
                  throw new IOException
                      (sm.getString("memoryUserDatabase.writeException",
                                    fileNew.getAbsolutePath()));
              }
              writer.close();
          } catch (IOException e) {
              if (writer != null) {
                  writer.close();
              }
              fileNew.delete();
              throw e;
          }
  
          // Perform the required renames to permanently save this file
          File fileOld = new File(pathnameOld);
          if (!fileOld.isAbsolute()) {
              fileOld =
                  new File(System.getProperty(Globals.CATALINA_BASE_PROP), pathnameOld);
          }
          fileOld.delete();
          File fileOrig = new File(pathname);
          if (!fileOrig.isAbsolute()) {
              fileOrig =
                  new File(System.getProperty(Globals.CATALINA_BASE_PROP), pathname);
          }
          if (fileOrig.exists()) {
              fileOld.delete();
              if (!fileOrig.renameTo(fileOld)) {
                  throw new IOException
                      (sm.getString("memoryUserDatabase.renameOld",
                                    fileOld.getAbsolutePath()));
              }
          }
          if (!fileNew.renameTo(fileOrig)) {
              if (fileOld.exists()) {
                  fileOld.renameTo(fileOrig);
              }
              throw new IOException
                  (sm.getString("memoryUserDatabase.renameNew",
                                fileOrig.getAbsolutePath()));
          }
          fileOld.delete();
  
      }
  
  
      /**
       * Return a String representation of this UserDatabase.
       */
      @Override
  