Class LockingReaderWriter
- java.lang.Object
-
- net.adoptopenjdk.icedteaweb.lockingfile.LockingReaderWriter
-
- Direct Known Subclasses:
UnsignedAppletActionStorageImpl
public abstract class LockingReaderWriter extends java.lang.ObjectProcess-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.
-
-
Field Summary
Fields Modifier and Type Field Description private LockableFilelockableFile
-
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 voiddoLocked(java.lang.Runnable r)java.io.FilegetBackingFile()Get the underlying file.booleanisReadOnly()voidlock()Lock the underlying storage.protected voidreadContents()Reads contents from file.protected abstract voidreadLine(java.lang.String line)voidunlock()Unlock the underlying storage.protected abstract voidwriteContent(java.io.BufferedWriter writer)protected voidwriteContents()Writes stored contents to file.protected voidwriteContentsLocked()Write contents to the file, first acquiring a lock.
-
-
-
Field Detail
-
lockableFile
private final LockableFile lockableFile
-
-
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.IOExceptionWrites stored contents to file. Assumes lock is held.- Throws:
java.io.IOException
-
readContents
protected void readContents() throws java.io.IOExceptionReads contents from file. Assumes lock is held.- Throws:
java.io.IOException
-
writeContentsLocked
protected void writeContentsLocked() throws java.io.IOExceptionWrite 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)
-
-