gt:                 reader = new BufferedReader(new FileReader(adminDataFile));
context: /* File:        $Id$
   * Revision:    $Revision$
   * Author:      $Author$
   * Date:        $Date$
   *
   * The Netarchive Suite - Software to harvest and preserve websites
   * Copyright 2004-2012 The Royal Danish Library, the Danish State and
   * University Library, the National Library of France and the Austrian
   * National Library.
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
   * This library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this library; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
   *  USA
   */
  
  package dk.netarkivet.archive.arcrepositoryadmin;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import dk.netarkivet.archive.ArchiveSettings;
  import dk.netarkivet.archive.arcrepository.distribute.StoreMessage;
  import dk.netarkivet.common.distribute.arcrepository.ReplicaStoreState;
  import dk.netarkivet.common.distribute.arcrepository.Replica;
  import dk.netarkivet.common.exceptions.ArgumentNotValid;
  import dk.netarkivet.common.exceptions.IOFailure;
  import dk.netarkivet.common.exceptions.UnknownID;
  import dk.netarkivet.common.utils.ApplicationUtils;
  import dk.netarkivet.common.utils.Settings;
  
  /**
   * Class for accessing and manipulating the administrative data for
   * the ArcRepository.
   * In the current implementation, it consists of a file with a number of lines
   * of the form: <filename/> <checksum/> <state/> 
   * <timestamp-for-last-state-change/> [,<bitarchive/> <storestatus/> 
   * <timestamp-for-last-state-change/>]*
   *
   * This abstract class is overridden to give either a read/write or a readonly
   * version of this class.
   * 
   * @deprecated Use the DatabaseAdmin instead.
   */
  @Deprecated
  public abstract class AdminData {
      /** The log.*/
      private Log log = LogFactory.getLog(AdminData.class.getName());
  
      /** Admindata version.
       * VersionNumber is the current version.
       */
      public static final String VERSION_NUMBER = "0.4";
      /**
       * Admindata version.
       * oldVersionNumber is the earlier but still valid version.
       */
      private static final String OLD_VERSION_NUMBER = "0.3";
      /**
       * Map containing a mapping from arcfilename to ArcRepositoryEntry.
       */
      protected Map<String, ArcRepositoryEntry> storeEntries
              = new HashMap<String, ArcRepositoryEntry>();
      /**
       * General delimiter.
       * TODO add constants class where these constants are placed.
       */
      private static final String GENERAL_DELIMITER = " ";
  
      /** The directory where the admin data resides, currently the directory:
       * Settings.DIRS_ARCREPOSITORY_ADMIN. */
      protected File adminDir;
      
      /** The name of the admin file. */
      protected static final String ADMIN_FILE_NAME = "admin.data";
  
      /** List containing the names of all knownBitArchives.
       * This list is updated in the setState() method
       * But only used in the toString() method.
       */
      protected List<String> knownBitArchives = new ArrayList<String>();
  
      /** The File object for the admin data file. */
      protected final File adminDataFile;
  
      /** 
       * Common constructor for admin data. Reads current admin data from admin
       * data file.
       */
      protected AdminData() {
          this.adminDir = new File(Settings.get(
                  ArchiveSettings.DIRS_ARCREPOSITORY_ADMIN));
          ApplicationUtils.dirMustExist(adminDir);
  
          adminDataFile = new File(adminDir, AdminData.ADMIN_FILE_NAME);
          log.info("Using admin data file '" + adminDataFile.getAbsolutePath()
                  + "'");
  
          if (adminDataFile.exists()) {
              read(); // Load admindata into StoreEntries Map
          } else {
              log.warn("AdminDataFile (" + adminDataFile.getPath()
                      + ") was not found.");
          }
      }
  
      /**
       * Returns the one and only AdminData instance.
       * @return the one and only AdminData instance.
       */
      public static synchronized UpdateableAdminData getUpdateableInstance() {
          return UpdateableAdminData.getInstance();
      }
  
      /**
       * Returns a read-only AdminData instance.
       * @return a read-only AdminData instance.
       */
      public static synchronized ReadOnlyAdminData getReadOnlyInstance() {
          // no Singleton returned
          return new ReadOnlyAdminData();
      }
  
      /**
       * Check, if there is an entry for a certain arcfile?
       * @param arcfileName A given arcfile
       * @return true, if there is an entry for the given arcfile
       */
      public boolean hasEntry(String arcfileName) {
          ArgumentNotValid.checkNotNullOrEmpty(arcfileName, "arcfileName");
          return storeEntries.containsKey(arcfileName);
      }
  
      /**
       * Return the ArcRepositoryEntry for a certain arcfileName.
       * Returns null, if not found.
       * @param arcfileName a certain filename
       * @return the ArcRepositoryEntry for a certain arcfileName
       */
      public ArcRepositoryEntry getEntry(String arcfileName) {
          return storeEntries.get(arcfileName);
      }
  
      /**
       * Tells whether there is a replyInfo associated with
       * the given arcfile. If the file is not registered,
       * a warning is logged and false is returned.
       *
       * @param arcfileName The arc file we want to reply a store request for.
       * @return Whether setReplyInfo() has been called
       *         (and the replyInfo hasn't been removed since).
       */
      public boolean hasReplyInfo(String arcfileName) {
          ArgumentNotValid.checkNotNullOrEmpty(arcfileName, "arcfileName");
          ArcRepositoryEntry entry = storeEntries.get(arcfileName);
          if (entry == null) {
              log.warn("No entry found in storeEntries for arcfilename: "
                      + arcfileName);
          }
          return entry != null && entry.hasReplyInfo();
      }
  
      /**
       * Returns whether or not a BitArchiveStoreState is registered for the given
       * ARC file at the given bit archive.
       *
       * @param arcfileName The file to retrieve the state for
       * @param replicaChannelName  The name of the identification channel for 
       * the replica the state should be retrieved for.
       * @return true if BitArchiveStoreState is registered, false otherwise.
       */
      public boolean hasState(String arcfileName, String replicaChannelName) {
          ArgumentNotValid.checkNotNullOrEmpty(arcfileName, "String arcfileName");
          ArgumentNotValid.checkNotNullOrEmpty(replicaChannelName, 
                  "String replicaChannelName");
          ArcRepositoryEntry entry = storeEntries.get(arcfileName);
          if (entry == null) {
              log.warn("No entry found in storeEntries for arcfilename: "
                      + arcfileName);
          }
          return entry != null && entry.hasStoreState(replicaChannelName);
      }
  
      /**
       * Retrieves the storage state of a file for a specific replica.
       *
       * @param arcfileName The file to retrieve the state for.
       * @param replicaChannelName  The name of the identification channel for 
       * the replica the state should be retrieved for.
       * @return The storage state.
       * @throws UnknownID When no record exists.
       */
      public ReplicaStoreState getState(String arcfileName, 
              String replicaChannelName) throws UnknownID {
          ArgumentNotValid.checkNotNullOrEmpty(arcfileName, "String arcfileName");
          ArgumentNotValid.checkNotNullOrEmpty(replicaChannelName, 
          "String replicaChannelName");
          if (!hasState(arcfileName, replicaChannelName)) {
              throw new UnknownID("No store state recorded for '"
                      + arcfileName + "' in '" + replicaChannelName + "'");
          }
          return storeEntries.get(arcfileName).getStoreState(replicaChannelName);
      }
  
      /**
       * Get Checksum for a given arcfile.
       * @param arcfileName Unique reference to file for which to
       *  retrieve checksum
       * @return checksum the latest registered reference checksum or null,
       *         if no reference checksum is available
       * @throws UnknownID if the file is not registered
       * @throws ArgumentNotValid If the arcFileName is either null or the empty
       * string. 
       */
      public String getCheckSum(String arcfileName) throws ArgumentNotValid, 
              UnknownID {
          ArgumentNotValid.checkNotNullOrEmpty(arcfileName, "arcfileName");
          if (!hasEntry(arcfileName)) {
              throw new UnknownID("Don't know anything about file '"
                      + arcfileName + "'");
          }
          return storeEntries.get(arcfileName).getChecksum();
      }
  
      /**
       * Reads the admin data from a file. If the data read is a valid old version
       * the it is converted to the new version and written to disk.
       * @throws IOFailure on trouble reading from file
       */
      protected void read() throws IOFailure {
          try {
              BufferedReader reader = null;
              try {
  