Class LockingReaderWriter

  • Direct Known Subclasses:
    UnsignedAppletActionStorageImpl

    public abstract class LockingReaderWriter
    extends java.lang.Object
    Process-locked string storage backed by a file. Each string is stored on its own line. Any new-lines must be encoded somehow if they are to be stored.
    • Constructor Summary

      Constructors 
      Constructor Description
      LockingReaderWriter​(java.io.File file)
      Create locking file-backed storage.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void doLocked​(java.lang.Runnable r)  
      java.io.File getBackingFile()
      Get the underlying file.
      boolean isReadOnly()  
      void lock()
      Lock the underlying storage.
      protected void readContents()
      Reads contents from file.
      protected abstract void readLine​(java.lang.String line)  
      void unlock()
      Unlock the underlying storage.
      protected abstract void writeContent​(java.io.BufferedWriter writer)  
      protected void writeContents()
      Writes stored contents to file.
      protected void writeContentsLocked()
      Write contents to the file, first acquiring a lock.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LockingReaderWriter

        public LockingReaderWriter​(java.io.File file)
        Create locking file-backed storage.
        Parameters:
        file - the storage file
    • Method Detail

      • getBackingFile

        public java.io.File getBackingFile()
        Get the underlying file. Any access to this file should use lock() and unlock().
        Returns:
        the file
      • isReadOnly

        public boolean isReadOnly()
      • lock

        public void lock()
        Lock the underlying storage. Lock is reentrant.
      • unlock

        public void unlock()
        Unlock the underlying storage. Lock is reentrant.
      • writeContents

        protected void writeContents()
                              throws java.io.IOException
        Writes stored contents to file. Assumes lock is held.
        Throws:
        java.io.IOException
      • readContents

        protected void readContents()
                             throws java.io.IOException
        Reads contents from file. Assumes lock is held.
        Throws:
        java.io.IOException
      • writeContentsLocked

        protected void writeContentsLocked()
                                    throws java.io.IOException
        Write contents to the file, first acquiring a lock.
        Throws:
        java.io.IOException
      • doLocked

        protected void doLocked​(java.lang.Runnable r)
      • writeContent

        protected abstract void writeContent​(java.io.BufferedWriter writer)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • readLine

        protected abstract void readLine​(java.lang.String line)