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
History
using 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 void
flush()
Flush all items to persistent storage.java.io.File
getFile()
void
load()
Load history from file, e.g.void
load(java.io.File file)
void
load(java.io.InputStream input)
void
load(java.io.Reader reader)
void
purge()
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.IOException
Load 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.IOException
Create 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.IOException
Load 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.IOException
Description copied from interface:PersistentHistory
Flush all items to persistent storage.- Specified by:
flush
in interfacejava.io.Flushable
- Specified by:
flush
in interfacePersistentHistory
- Throws:
java.io.IOException
- Flush failed
-
purge
public void purge() throws java.io.IOException
Description copied from interface:PersistentHistory
Purge persistent storage andHistory.clear()
.- Specified by:
purge
in interfacePersistentHistory
- Throws:
java.io.IOException
- Purge failed
-
-