FileStore (Apache Tomcat 11.0.23 API Documentation)
Description: declaration: package: org.apache.catalina.session, class: FileStore

# Class FileStore

java.lang.Object
org.apache.catalina.util.LifecycleBase
org.apache.catalina.session.StoreBase
org.apache.catalina.session.FileStore

All Implemented Interfaces:
  `Lifecycle, Store`

public final class FileStore extends StoreBase
Concrete implementation of the Store interface that utilizes a file per saved Session in a configured directory. Sessions that are saved are still subject to being expired based on inactivity.

- ## Nested Class Summary

  ### Nested classes/interfaces inherited from interface Lifecycle

  `Lifecycle.SingleUse`

- ## Field Summary

  ### Fields inherited from class StoreBase

  `manager, support`

  ### Fields inherited from interface Lifecycle

  `AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FileStore()`
  Default constructor for FileStore.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  Remove all Sessions from this Store.
  `String`
  `getDirectory()`
  Returns the directory path where session files are stored.
  `int`
  `getSize()`
  Return the number of Sessions present in this Store.
  `String`
  `getStoreName()`
  Return the name for this Store, used for logging.
  `String`
  `getThreadName()`
  Returns the name used for the background thread that processes this store.
  `String[]`
  `keys()`
  Return an array containing the session identifiers of all Sessions currently saved in this Store.
  `Session`
  `load(String id)`
  Load and return the Session associated with the specified session identifier from this Store, without removing it.
  `void`
  `remove(String id)`
  Remove the Session with the specified session identifier from this Store, if present.
  `void`
  `save(Session session)`
  Save the specified Session into this Store.
  `void`
  `setDirectory(String path)`
  Set the directory path for this Store.

  ### Methods inherited from class StoreBase

  `addPropertyChangeListener, destroyInternal, expiredKeys, getManager, getObjectInputStream, initInternal, processExpires, removePropertyChangeListener, setManager, startInternal, stopInternal, toString`

  ### Methods inherited from class LifecycleBase

  `addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop`

  ### Methods inherited from class Object

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

- ## Constructor Details

  - ### FileStore

    public FileStore()
    Default constructor for FileStore.

- ## Method Details

  - ### getDirectory

    public String getDirectory()
    Returns the directory path where session files are stored.
    Returns:
      The directory path for this Store

  - ### setDirectory

    public void setDirectory(String path)
    Set the directory path for this Store.
    Parameters:
      `path` - The new directory path

  - ### getThreadName

    public String getThreadName()
    Returns the name used for the background thread that processes this store.
    Returns:
      The thread name for this Store

  - ### getStoreName

    public String getStoreName()
    Description copied from class: `StoreBase`
    Return the name for this Store, used for logging.
    Overrides:
      `getStoreName` in class `StoreBase`
    Returns:
      the store name

  - ### getSize

    public int getSize() throws IOException
    Description copied from interface: `Store`
    Return the number of Sessions present in this Store.
    Returns:
      the number of Sessions
    Throws:
      `IOException` - if an input/output error occurs

  - ### clear

    public void clear() throws IOException
    Description copied from interface: `Store`
    Remove all Sessions from this Store.
    Throws:
      `IOException` - if an input/output error occurs

  - ### keys

    public String[] keys() throws IOException
    Description copied from interface: `Store`
    Return an array containing the session identifiers of all Sessions currently saved in this Store. If there are no such Sessions, a zero-length array is returned.
    Returns:
      the session identifiers
    Throws:
      `IOException` - if an input/output error occurred

  - ### load

    public Session load(String id) throws ClassNotFoundException, IOException
    Description copied from interface: `Store`
    Load and return the Session associated with the specified session identifier from this Store, without removing it. If there is no such stored Session, return `null`.

    Implementations should expect, and correctly handle, concurrent calls to any method but in particular calls to `#load(String)`, `#save(Session)` and `#remove(String)` for the same session.

    The session ID is user provided so stores must treat it as untrusted data.

    Parameters:
      `id` - Session identifier of the session to load
    Returns:
      the loaded Session instance
    Throws:
      `ClassNotFoundException` - if a deserialization error occurs
      `IOException` - if an input/output error occurs

  - ### remove

    public void remove(String id) throws IOException
    Description copied from interface: `Store`
    Remove the Session with the specified session identifier from this Store, if present. If no such Session is present, this method takes no action.

    Implementations should expect, and correctly handle, concurrent calls to any method but in particular calls to `#load(String)`, `#save(Session)` and `#remove(String)` for the same session.

    The session ID is user provided so stores must treat it as untrusted data.

    Parameters:
      `id` - Session identifier of the Session to be removed
    Throws:
      `IOException` - if an input/output error occurs

  - ### save

    public void save(Session session) throws IOException
    Description copied from interface: `Store`
    Save the specified Session into this Store. Any previously saved information for the associated session identifier is replaced.

    Implementations should expect, and correctly handle, concurrent calls to any method but in particular calls to `#load(String)`, `#save(Session)` and `#remove(String)` for the same session.

    Parameters:
      `session` - Session to be saved
    Throws:
      `IOException` - if an input/output error occurs