Package org.codelibs.fess.dict.synonym
Class SynonymFile.SynonymUpdater
java.lang.Object
org.codelibs.fess.dict.synonym.SynonymFile.SynonymUpdater
- All Implemented Interfaces:
Closeable,AutoCloseable
- Enclosing class:
SynonymFile
An inner class for updating the synonym file.
This class handles the process of writing changes to a temporary file
and then replacing the original file upon successful commit.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanA flag indicating whether the changes have been committed.protected SynonymItemThe synonym item being added or updated.protected FileThe temporary file to write changes to.protected WriterThe writer for the temporary file. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSynonymUpdater(SynonymItem newItem) Constructs a new updater for a synonym item. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()commit()Commits the changes to the dictionary file.voidWrites a raw line to the temporary file.write(SynonymItem oldItem) Writes a synonym item to the temporary file.
-
Field Details
-
isCommit
protected boolean isCommitA flag indicating whether the changes have been committed. -
newFile
The temporary file to write changes to. -
writer
The writer for the temporary file. -
item
The synonym item being added or updated.
-
-
Constructor Details
-
SynonymUpdater
Constructs a new updater for a synonym item.- Parameters:
newItem- The item to be added or updated.- Throws:
DictionaryException- if the temporary file cannot be created.
-
-
Method Details
-
write
Writes a synonym item to the temporary file. If the item is being updated, it writes the new version.- Parameters:
oldItem- The original item from the dictionary.- Returns:
- The written item, or null if the item was deleted.
- Throws:
DictionaryException- if the file was updated concurrently.
-
write
Writes a raw line to the temporary file.- Parameters:
line- The line to write.- Throws:
DictionaryException- if an I/O error occurs.
-
commit
Commits the changes to the dictionary file. If there is a pending new item, it is written to the file.- Returns:
- The committed item, or null if no item was committed.
- Throws:
DictionaryException- if an I/O error occurs.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-