net.i2p.router.peermanager

## Class ProfilePersistenceHelper

- java.lang.Object
- - net.i2p.router.peermanager.ProfilePersistenceHelper

-     class ProfilePersistenceHelper
      extends Object

  Write profiles to disk at shutdown, read at startup. The files are gzip compressed, we previously stored them with a ".dat" extension instead of ".txt.gz", so it wasn't apparent. Now migrated to a ".txt.gz" extension.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `DEFAULT_PEER_PROFILE_DIR`
    `static String` | `PROP_PEER_PROFILE_DIR`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ProfilePersistenceHelper(RouterContext ctx)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `deleteOldProfiles(long age)` Delete profile files with timestamps older than 'age' ago
    `(package private) static long` | `getLong(Properties props, String key)`
    `void` | `purgeExcessProfiles(Set<Hash> keepPeers, int maxProfiles)` Delete profile files not in 'keepPeers', if total file count > maxProfiles.
    `PeerProfile` | `readProfile(File file, long cutoff)`
    `List<PeerProfile>` | `readProfiles()`
    `void` | `setUs(Hash routerIdentHash)`
    `boolean` | `writeProfile(PeerProfile profile)` write out the data from the profile to the file
    `void` | `writeProfile(PeerProfile profile, OutputStream out)` write out the data from the profile to the stream includes comments
    `void` | `writeProfile(PeerProfile profile, OutputStream out, boolean addComments)` write out the data from the profile to the stream

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_PEER_PROFILE_DIR

          public static final String DEFAULT_PEER_PROFILE_DIR

      See Also:
        Constant Field Values

    - #### PROP_PEER_PROFILE_DIR

          public static final String PROP_PEER_PROFILE_DIR

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ProfilePersistenceHelper

          public ProfilePersistenceHelper(RouterContext ctx)

  - ### Method Detail

    - #### deleteOldProfiles

          public int deleteOldProfiles(long age)

      Delete profile files with timestamps older than 'age' ago
      Returns:
        number deleted

    - #### getLong

          static long getLong(Properties props,
                              String key)

    - #### purgeExcessProfiles

          public void purgeExcessProfiles(Set<Hash> keepPeers,
                                          int maxProfiles)

      Delete profile files not in 'keepPeers', if total file count > maxProfiles. Prioritizes keeping profiles with recent lastHeardFrom activity.

    - #### readProfile

          public PeerProfile readProfile(File file,
                                         long cutoff)

      Parameters:
        `cutoff` - delete and return null if older than this (absolute time)

    - #### readProfiles

          public List<PeerProfile> readProfiles()

    - #### setUs

          public void setUs(Hash routerIdentHash)

    - #### writeProfile

          public boolean writeProfile(PeerProfile profile)

      write out the data from the profile to the file
      Returns:
        success

    - #### writeProfile

          public void writeProfile(PeerProfile profile,
                                   OutputStream out)
                            throws IOException

      write out the data from the profile to the stream includes comments
      Throws:
        `IOException`

    - #### writeProfile

          public void writeProfile(PeerProfile profile,
                                   OutputStream out,
                                   boolean addComments)
                            throws IOException

      write out the data from the profile to the stream
      Parameters:
        `addComments` - add comment lines to the output
      Throws:
        `IOException`