Package com.google.api.client.util.store
Class FileDataStoreFactory
- java.lang.Object
-
- com.google.api.client.util.store.AbstractDataStoreFactory
-
- com.google.api.client.util.store.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 classFileDataStoreFactory.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 (seeFileDataStoreFactory.FileDataStore.save()when changing values.
-
Field Summary
Fields Modifier and Type Field Description private java.io.FiledataDirectoryDirectory to store data.private static booleanIS_WINDOWS
-
Constructor Summary
Constructors Constructor Description FileDataStoreFactory(java.io.File dataDirectory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <V extends java.io.Serializable>
DataStore<V>createDataStore(java.lang.String id)Returns a new instance of a type-specific data store based on the given unique ID.java.io.FilegetDataDirectory()Returns the data directory.private static voidsetPermissionsToOwnerOnly(java.io.File file)Attempts to set the given file's permissions such that it can only be read, written, and executed by the file's owner.private static voidsetPermissionsToOwnerOnlyWindows(java.io.File file)-
Methods inherited from class com.google.api.client.util.store.AbstractDataStoreFactory
getDataStore
-
-
-
-
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:AbstractDataStoreFactoryReturns a new instance of a type-specific data store based on the given unique ID.The
DataStore.getId()must match theidparameter from this method.- Specified by:
createDataStorein classAbstractDataStoreFactory- 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.IOExceptionAttempts 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
-
-