Class LocalStorage

  • All Implemented Interfaces:
    com.infinitekind.tiksync.SyncFolder, com.infinitekind.tiksync.SyncStorage, java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,​java.lang.String>

    public abstract class LocalStorage
    extends com.infinitekind.tiksync.SyncRecord
    implements com.infinitekind.tiksync.SyncStorage
    Created by sreilly - 01/08/2014 09:27
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected com.infinitekind.tiksync.SyncRecord authenticationCache  
    • Constructor Summary

      Constructors 
      Constructor Description
      LocalStorage()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void cacheAuthentication​(java.lang.String key, java.lang.String authVal)
      Used by OnlineService to cache authentication
      void clearAuthenticationCache​(java.lang.String prefix)
      Remove any stored passwords for the given service whose key begins with the given prefix
      abstract void delete​(java.lang.String filename)
      Deletes a local data file or folder.
      abstract boolean exists​(java.lang.String filename)
      Returns true iff a file exists at the given path in the safe storage.
      java.lang.String getCachedAuthentication​(java.lang.String key)
      Used by local modules to retrieve cached authentication and other secure information
      abstract boolean isFolder​(java.lang.String filename)
      Returns true iff a file at the given path exists and is a folder.
      static java.lang.String joinPath​(java.lang.String folder, java.lang.String file)  
      abstract java.util.List<java.lang.String> listFiles​(java.lang.String folderPath)
      Returns a list of files under the given folder path.
      abstract java.util.List<java.lang.String> listSubfolders​(java.lang.String folderPath)
      Returns a list of folders under the given folder path.
      abstract void moveFile​(java.lang.String fromFile, java.lang.String toFileOrFolder)
      Move or rename the given fromFile to the given file or folder.
      abstract java.io.InputStream openFileForReading​(java.lang.String filename)
      Reads from a local data file, decrypting as it goes.
      abstract java.io.OutputStream openFileForWriting​(java.lang.String filename)
      Returns a stream for writing to a local data file, encrypting as it goes.
      abstract long readFile​(java.lang.String filename, java.io.OutputStream sinkStream)
      Reads from a local data file, decrypting as it goes.
      abstract boolean save()
      Saves the key-value data to local storage
      abstract void writeFile​(java.lang.String filename, java.io.InputStream dataToWrite)
      Writes to a local data file, encrypting as it goes.
      abstract void writeToFileAtomically​(byte[] bytesToWrite, java.lang.String destinationFilename)
      Encrypts and writes to a local data file atomically.
      • Methods inherited from class com.infinitekind.tiksync.SyncRecord

        add, clone, createFrom, createFrom, getBoolean, getDouble, getInt, getIntArray, getLabel, getLong, getStr, getString, getStringList, getSublist, getSubset, printHumanReadableContents, put, put, put, put, put, put, put, put, put, put, readSet, readSet, removeSubset, setLabel, toMultilineHumanReadableString, toString, unescapeAndDecodeUTF8, writeSet, writeToBytes, writeToString
      • Methods inherited from class java.util.HashMap

        clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        equals, hashCode
      • Methods inherited from interface com.infinitekind.tiksync.SyncFolder

        encryptBytes, readFile, readUnencrypted, writeUnencryptedFile
      • Methods inherited from interface com.infinitekind.tiksync.SyncStorage

        getModified
    • Field Detail

      • authenticationCache

        protected com.infinitekind.tiksync.SyncRecord authenticationCache
    • Constructor Detail

      • LocalStorage

        public LocalStorage()
    • Method Detail

      • save

        public abstract boolean save()
        Saves the key-value data to local storage
      • exists

        public abstract boolean exists​(java.lang.String filename)
                                throws java.lang.Exception
        Returns true iff a file exists at the given path in the safe storage. If filename is a relative path (which it should be) it will be based on the safe root of the data folder.
        Specified by:
        exists in interface com.infinitekind.tiksync.SyncFolder
        Specified by:
        exists in interface com.infinitekind.tiksync.SyncStorage
        Throws:
        java.lang.Exception
      • isFolder

        public abstract boolean isFolder​(java.lang.String filename)
                                  throws java.lang.Exception
        Returns true iff a file at the given path exists and is a folder. If filename is a relative path (which it should be) it will be based on the safe root of the data folder.
        Specified by:
        isFolder in interface com.infinitekind.tiksync.SyncStorage
        Throws:
        java.lang.Exception
      • listFiles

        public abstract java.util.List<java.lang.String> listFiles​(java.lang.String folderPath)
        Returns a list of files under the given folder path. If folderPath is a relative path (which it should be) it will be based on the safe root of the data folder.
        Specified by:
        listFiles in interface com.infinitekind.tiksync.SyncFolder
        Specified by:
        listFiles in interface com.infinitekind.tiksync.SyncStorage
      • listSubfolders

        public abstract java.util.List<java.lang.String> listSubfolders​(java.lang.String folderPath)
        Returns a list of folders under the given folder path. If folderPath is a relative path (which it should be) it will be based on the safe root of the data folder.
        Specified by:
        listSubfolders in interface com.infinitekind.tiksync.SyncFolder
        Specified by:
        listSubfolders in interface com.infinitekind.tiksync.SyncStorage
      • openFileForReading

        public abstract java.io.InputStream openFileForReading​(java.lang.String filename)
                                                        throws java.lang.Exception
        Reads from a local data file, decrypting as it goes. If filename is a relative path (which it should be) it will be based on the safe root of the data folder.
        Specified by:
        openFileForReading in interface com.infinitekind.tiksync.SyncStorage
        Throws:
        java.lang.Exception
      • openFileForWriting

        public abstract java.io.OutputStream openFileForWriting​(java.lang.String filename)
                                                         throws java.lang.Exception
        Returns a stream for writing to a local data file, encrypting as it goes. If filename is a relative path (which it should be) it will be based on the safe root of the data folder.
        Specified by:
        openFileForWriting in interface com.infinitekind.tiksync.SyncStorage
        Throws:
        java.lang.Exception
      • writeFile

        public abstract void writeFile​(java.lang.String filename,
                                       java.io.InputStream dataToWrite)
                                throws java.lang.Exception
        Writes to a local data file, encrypting as it goes. The data to write is read from the given input stream. If filename is a relative path (which it should be) it will be based on the safe root of the data folder.
        Specified by:
        writeFile in interface com.infinitekind.tiksync.SyncFolder
        Specified by:
        writeFile in interface com.infinitekind.tiksync.SyncStorage
        Throws:
        java.lang.Exception
      • readFile

        public abstract long readFile​(java.lang.String filename,
                                      java.io.OutputStream sinkStream)
                               throws java.lang.Exception
        Reads from a local data file, decrypting as it goes. The data is read from the given local file, decrypted, and then written to the given output stream. If filename is a relative path (which it should be) it will be based on the safe root of the data folder. Returns the number of (decrypted) bytes read and copied.
        Specified by:
        readFile in interface com.infinitekind.tiksync.SyncStorage
        Throws:
        java.lang.Exception
      • delete

        public abstract void delete​(java.lang.String filename)
                             throws java.lang.Exception
        Deletes a local data file or folder. If filename is a relative path (which it should be) it will be based on the safe root of the data folder.
        Specified by:
        delete in interface com.infinitekind.tiksync.SyncFolder
        Specified by:
        delete in interface com.infinitekind.tiksync.SyncStorage
        Throws:
        java.lang.Exception
      • moveFile

        public abstract void moveFile​(java.lang.String fromFile,
                                      java.lang.String toFileOrFolder)
                               throws java.io.IOException
        Move or rename the given fromFile to the given file or folder.
        Specified by:
        moveFile in interface com.infinitekind.tiksync.SyncStorage
        Throws:
        java.io.IOException
      • writeToFileAtomically

        public abstract void writeToFileAtomically​(byte[] bytesToWrite,
                                                   java.lang.String destinationFilename)
                                            throws java.lang.Exception
        Encrypts and writes to a local data file atomically. The given data is saved to the file atomically. That is, it does everything possible to ensure the write will succeed before actually changing the target file. Any IO exceptions should be thrown before the target file is touched. If filename is a relative path (which it should be) it will be based on the safe root of the data folder.
        Specified by:
        writeToFileAtomically in interface com.infinitekind.tiksync.SyncStorage
        Throws:
        java.lang.Exception
      • cacheAuthentication

        public void cacheAuthentication​(java.lang.String key,
                                        java.lang.String authVal)
        Used by OnlineService to cache authentication
      • getCachedAuthentication

        public java.lang.String getCachedAuthentication​(java.lang.String key)
        Used by local modules to retrieve cached authentication and other secure information
      • clearAuthenticationCache

        public void clearAuthenticationCache​(java.lang.String prefix)
        Remove any stored passwords for the given service whose key begins with the given prefix
      • joinPath

        public static java.lang.String joinPath​(java.lang.String folder,
                                                java.lang.String file)