Package jline.console.history
Class FileHistory
- java.lang.Object
-
- jline.console.history.MemoryHistory
-
- jline.console.history.FileHistory
-
- All Implemented Interfaces:
java.io.Flushable,java.lang.Iterable<History.Entry>,History,PersistentHistory
public class FileHistory extends MemoryHistory implements PersistentHistory, java.io.Flushable
Historyusing a file for persistent backing. Implementers should install shutdown hook to callflush()to save history to disk.- Since:
- 2.0
- Author:
- Jason Dillon
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jline.console.history.History
History.Entry
-
-
Field Summary
-
Fields inherited from class jline.console.history.MemoryHistory
DEFAULT_MAX_SIZE
-
-
Constructor Summary
Constructors Constructor Description FileHistory(java.io.File file)Load a history file into memory, truncating to default max size.FileHistory(java.io.File file, boolean doInit)Create a FileHistory, but only initialize if doInit is true.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidflush()Flush all items to persistent storage.java.io.FilegetFile()voidload()Load history from file, e.g.voidload(java.io.File file)voidload(java.io.InputStream input)voidload(java.io.Reader reader)voidpurge()Purge persistent storage andHistory.clear().-
Methods inherited from class jline.console.history.MemoryHistory
add, clear, current, entries, entries, get, getMaxSize, index, internalAdd, isAutoTrim, isEmpty, isIgnoreDuplicates, iterator, moveTo, moveToEnd, moveToFirst, moveToLast, next, previous, remove, removeFirst, removeLast, replace, set, setAutoTrim, setIgnoreDuplicates, setMaxSize, size, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Constructor Detail
-
FileHistory
public FileHistory(java.io.File file) throws java.io.IOExceptionLoad a history file into memory, truncating to default max size.- Throws:
java.io.IOException
-
FileHistory
public FileHistory(java.io.File file, boolean doInit) throws java.io.IOExceptionCreate a FileHistory, but only initialize if doInit is true. This allows setting maxSize or other settings; call load() before using if doInit is false.- Throws:
java.io.IOException
-
-
Method Detail
-
load
public void load() throws java.io.IOExceptionLoad history from file, e.g. if using delayed init.- Throws:
java.io.IOException
-
getFile
public java.io.File getFile()
-
load
public void load(java.io.File file) throws java.io.IOException- Throws:
java.io.IOException
-
load
public void load(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
load
public void load(java.io.Reader reader) throws java.io.IOException- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOExceptionDescription copied from interface:PersistentHistoryFlush all items to persistent storage.- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin interfacePersistentHistory- Throws:
java.io.IOException- Flush failed
-
purge
public void purge() throws java.io.IOExceptionDescription copied from interface:PersistentHistoryPurge persistent storage andHistory.clear().- Specified by:
purgein interfacePersistentHistory- Throws:
java.io.IOException- Purge failed
-
-