Example #1
0
 /** Save this IP restriction list. */
 public synchronized void save() throws IOException {
   FileWriter fw = null;
   try {
     fw = new FileWriter(mIpFile);
     Object[] entries = mAllEntries.toArray();
     for (int i = entries.length; --i >= 0; ) {
       fw.write(entries[i].toString());
       fw.write(LINE_SEP);
     }
   } finally {
     IoUtils.close(fw);
   }
 }
Example #2
0
 /** Read the list from the file. */
 public synchronized void reload() throws IOException {
   BufferedReader br = null;
   Vector newEntries = new Vector();
   try {
     if (mIpFile.exists()) {
       br = IoUtils.getBufferedReader(new FileReader(mIpFile));
       String line = null;
       while ((line = br.readLine()) != null) {
         line = line.trim();
         if (!line.equals("")) {
           newEntries.add(line);
         }
       }
     }
     mAllEntries = newEntries;
   } finally {
     IoUtils.close(br);
   }
 }
  /** @throws FtpException */
  private void saveUserData() throws FtpException {
    File dir = userDataFile.getAbsoluteFile().getParentFile();
    if (dir != null && !dir.exists() && !dir.mkdirs()) {
      String dirName = dir.getAbsolutePath();
      throw new FtpServerConfigurationException(
          "Cannot create directory for user data file : " + dirName);
    }

    // save user data
    FileOutputStream fos = null;
    try {
      fos = new FileOutputStream(userDataFile);
      userDataProp.store(fos, "Generated file - don't edit (please)");
    } catch (IOException ex) {
      LOG.error("Failed saving user data", ex);
      throw new FtpException("Failed saving user data", ex);
    } finally {
      IoUtils.close(fos);
    }
  }
  /** Configure user manager. */
  public void configure() {
    isConfigured = true;
    try {
      userDataProp = new BaseProperties();

      if (userDataFile != null && userDataFile.exists()) {
        FileInputStream fis = null;
        try {
          fis = new FileInputStream(userDataFile);
          userDataProp.load(fis);
        } finally {
          IoUtils.close(fis);
        }
      }
    } catch (IOException e) {
      throw new FtpServerConfigurationException(
          "Error loading user data file : " + userDataFile.getAbsolutePath(), e);
    }

    convertDeprecatedPropertyNames();
  }