com.jp.protection.pub
Class FileSecretStorage

java.lang.Object
  extended by com.jp.protection.pub.FileSecretStorage
All Implemented Interfaces:
SecretStorage

public class FileSecretStorage
extends java.lang.Object
implements SecretStorage

Default implementation of the SecretStorage interface that stores data in a local file using very simple encoding

See Also:
SecretStorage

Nested Class Summary
protected static class FileSecretStorage.DecodeInputStream
           
protected static class FileSecretStorage.EncodeOutputStream
           
static class FileSecretStorage.Provider
           
 
Field Summary
protected  boolean fDirty
           
protected  java.lang.String fFileName
           
protected  java.lang.String fFolder
           
protected  boolean fLoaded
           
protected  java.util.Properties fProperties
           
protected  boolean fSkipEncryption
           
protected  boolean fUserHomeRelative
           
protected  boolean fVerbose
           
 
Constructor Summary
FileSecretStorage()
          Creates a new instance of FileSecretStorage
FileSecretStorage(java.lang.String aFolder, java.lang.String aFileName)
          Creates a new instance of FileSecretStorage and initializes it
FileSecretStorage(java.lang.String aFolder, java.lang.String aFileName, boolean aUserHomeRelative)
          Creates a new instance of FileSecretStorage and initializes it
 
Method Summary
protected  void error(java.lang.Throwable ex)
           
 java.io.File getFile()
          Returns the secret storage file
 java.lang.String getFileName()
          Returns the name of the storage file
 java.lang.String getFolder()
          Returns the folder of the storage file
protected  java.io.InputStream getInputStream()
           
protected  java.io.OutputStream getOutputStream()
           
protected  java.util.Properties getProperties()
           
 java.lang.String getProperty(java.lang.String key)
          Gets property value by its key
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
          Gets property value by its key
 boolean isDirty()
          Checks whether secret storage is changed
protected  boolean isLoaded()
           
 boolean isSkipEncryption()
          Checks whether encryption should be skipped during storage saving
 boolean isUserHomeRelative()
          Checks whether folder to find storage file is relative to the user home.
 boolean isVerbose()
          Checks whether verbose output is enabled.
 void load()
          Loads the storage from some persistent state
 void save()
          Saves the storage to some persistent state
 void setDirty(boolean aDirty)
          Specifies that secret storage is changed
 void setFileName(java.lang.String aFileName)
          Specifies the name of the storage file
 void setFolder(java.lang.String aFolder)
          Specifies the folder of the storage file
protected  void setLoaded(boolean aLoaded)
           
 java.lang.Object setProperty(java.lang.String key, java.lang.String value)
          Specifies property value for the given key
 void setSkipEncryption(boolean aSkipEncryption)
          Specifies that encryption should be skipped during storage saving
 void setUserHomeRelative(boolean aUserHomeRelative)
          Specifies that folder to find storage file is relative to the user home.
 void setVerbose(boolean aVerbose)
          Specifies that verbose output is enabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fFileName

protected java.lang.String fFileName

fFolder

protected java.lang.String fFolder

fUserHomeRelative

protected boolean fUserHomeRelative

fProperties

protected java.util.Properties fProperties

fDirty

protected boolean fDirty

fLoaded

protected boolean fLoaded

fVerbose

protected boolean fVerbose

fSkipEncryption

protected boolean fSkipEncryption
Constructor Detail

FileSecretStorage

public FileSecretStorage()
Creates a new instance of FileSecretStorage


FileSecretStorage

public FileSecretStorage(java.lang.String aFolder,
                         java.lang.String aFileName)
Creates a new instance of FileSecretStorage and initializes it

Parameters:
aFolder - a folder to locate secret storage file
aFileName - a name of secret storage file

FileSecretStorage

public FileSecretStorage(java.lang.String aFolder,
                         java.lang.String aFileName,
                         boolean aUserHomeRelative)
Creates a new instance of FileSecretStorage and initializes it

Parameters:
aFolder - folder to locate secret storage file
aFileName - a name of secret storage file
aUserHomeRelative - specifies whether a folder is user HOME folder relative
Method Detail

isUserHomeRelative

public boolean isUserHomeRelative()
Checks whether folder to find storage file is relative to the user home.

Returns:
true if folder to find storage file is relative to the user home; false otherwise.

getFileName

public java.lang.String getFileName()
Returns the name of the storage file

Returns:
the name of the storage file

setFileName

public void setFileName(java.lang.String aFileName)
Specifies the name of the storage file

Parameters:
aFileName - a name of the storage file to assign

getFolder

public java.lang.String getFolder()
Returns the folder of the storage file

Returns:
the folder of the storage file

setFolder

public void setFolder(java.lang.String aFolder)
Specifies the folder of the storage file

Parameters:
aFolder - a folder of the storage file to assign

setUserHomeRelative

public void setUserHomeRelative(boolean aUserHomeRelative)
Specifies that folder to find storage file is relative to the user home.

Parameters:
aUserHomeRelative - true if folder to find storage file is relative to the user home; false otherwise.

isVerbose

public boolean isVerbose()
Checks whether verbose output is enabled.

Returns:
true if verbose output is enabled; false otherwise.

setVerbose

public void setVerbose(boolean aVerbose)
Specifies that verbose output is enabled.

Parameters:
aVerbose - true if verbose output should be enabled; false otherwise.

setLoaded

protected void setLoaded(boolean aLoaded)

getProperties

protected java.util.Properties getProperties()

getProperty

public java.lang.String getProperty(java.lang.String key)
Description copied from interface: SecretStorage
Gets property value by its key

Specified by:
getProperty in interface SecretStorage
Parameters:
key - identifies value to return
Returns:
property value

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue)
Description copied from interface: SecretStorage
Gets property value by its key

Specified by:
getProperty in interface SecretStorage
Parameters:
key - identifies value to be return
defaultValue - a value should be returned if there is no value for the given key
Returns:
property value

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    java.lang.String value)
Description copied from interface: SecretStorage
Specifies property value for the given key

Specified by:
setProperty in interface SecretStorage
Parameters:
key - identifies value to specify
value - value to be associated with the key
Returns:
previous property value

isLoaded

protected boolean isLoaded()

isDirty

public boolean isDirty()
Checks whether secret storage is changed

Returns:
true if secret storage is changed; false otherwise

setDirty

public void setDirty(boolean aDirty)
Specifies that secret storage is changed

Parameters:
aDirty - true if secret storage should be marked as changed; false otherwise

load

public void load()
Description copied from interface: SecretStorage
Loads the storage from some persistent state

Specified by:
load in interface SecretStorage

save

public void save()
Description copied from interface: SecretStorage
Saves the storage to some persistent state

Specified by:
save in interface SecretStorage

isSkipEncryption

public boolean isSkipEncryption()
Checks whether encryption should be skipped during storage saving

Returns:
true if encryption should be skipped during storage saving; false otherwise

setSkipEncryption

public void setSkipEncryption(boolean aSkipEncryption)
Specifies that encryption should be skipped during storage saving

Parameters:
aSkipEncryption - true if encryption should be skipped during storage saving; false otherwise

getFile

public java.io.File getFile()
Returns the secret storage file

Returns:
a secret storage file

getInputStream

protected java.io.InputStream getInputStream()

getOutputStream

protected java.io.OutputStream getOutputStream()

error

protected void error(java.lang.Throwable ex)