Class FileDataStoreFactory

  • All Implemented Interfaces:
    DataStoreFactory

    public class FileDataStoreFactory
    extends AbstractDataStoreFactory
    Thread-safe file implementation of a credential store.

    For security purposes, the file's permissions are set such that the file is only accessible by the file's owner.

    Note: this class is not compatible with Android lower than API level 26 (Oreo). For an implementation compatible with Android < 26, please use com.google.api.client.extensions.android.util.store.FileDataStoreFactory which is provided by com.google.http-client:google-http-client-android.

    Since:
    1.16
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  FileDataStoreFactory.FileDataStore<V extends java.io.Serializable>
      File data store that inherits from the abstract memory data store because the key-value pairs are stored in a memory cache, and saved in the file (see FileDataStoreFactory.FileDataStore.save() when changing values.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.File dataDirectory
      Directory to store data.
      private static boolean IS_WINDOWS  
    • Constructor Summary

      Constructors 
      Constructor Description
      FileDataStoreFactory​(java.io.File dataDirectory)  
    • Field Detail

      • IS_WINDOWS

        private static final boolean IS_WINDOWS
      • dataDirectory

        private final java.io.File dataDirectory
        Directory to store data.
    • Constructor Detail

      • FileDataStoreFactory

        public FileDataStoreFactory​(java.io.File dataDirectory)
                             throws java.io.IOException
        Parameters:
        dataDirectory - data directory
        Throws:
        java.io.IOException
    • Method Detail

      • getDataDirectory

        public final java.io.File getDataDirectory()
        Returns the data directory.
      • createDataStore

        protected <V extends java.io.Serializable> DataStore<V> createDataStore​(java.lang.String id)
                                                                         throws java.io.IOException
        Description copied from class: AbstractDataStoreFactory
        Returns a new instance of a type-specific data store based on the given unique ID.

        The DataStore.getId() must match the id parameter from this method.

        Specified by:
        createDataStore in class AbstractDataStoreFactory
        Type Parameters:
        V - serializable type of the mapped value
        Parameters:
        id - unique ID to refer to typed data store
        Throws:
        java.io.IOException
      • setPermissionsToOwnerOnly

        private static void setPermissionsToOwnerOnly​(java.io.File file)
                                               throws java.io.IOException
        Attempts to set the given file's permissions such that it can only be read, written, and executed by the file's owner.
        Parameters:
        file - the file's permissions to modify
        Throws:
        java.io.IOException - if the permissions can't be set
      • setPermissionsToOwnerOnlyWindows

        private static void setPermissionsToOwnerOnlyWindows​(java.io.File file)
                                                      throws java.io.IOException
        Throws:
        java.io.IOException