Verified Owner
Top Description Fields Constructors Methods
org.jabref.logic.exporter

public Class AtomicFileWriter

extends OutputStreamWriter
Class Inheritance
Imports
java.io.IOException, .OutputStreamWriter, java.nio.charset.Charset, .CharsetEncoder, java.nio.file.Path, java.util.Collections, .Set, .TreeSet, org.jabref.logic.util.io.FileSnapshot, org.jspecify.annotations.Nullable

Writer that similar to the built-in java.io.FileWriter but uses the AtomicFileOutputStream as the underlying output stream. In this way, we make sure that the errors during the write process do not destroy the contents of the target file. Moreover, this writer checks if the chosen encoding supports all text that is written. Characters whose encoding was problematic can be retrieved by getEncodingProblems().

Field Summary

Modifier and TypeField and Description
private final CharsetEncoder
private final AtomicFileOutputStream
private final Set<Character>

Constructor Summary

AccessConstructor and Description
public
AtomicFileWriter(Path file, Charset encoding)

public
AtomicFileWriter(Path file, Charset encoding, boolean keepBackup)

public
private

Method Summary

Modifier and TypeMethod and Description
public void
abort()

Aborts the write without replacing the target file.

public @Nullable FileSnapshot
public Set<Character>
public boolean
public void
write(String str)

Overrides java.io.Writer.write.

Writes a string.

Inherited from java.io.OutputStreamWriter:
appendappendcloseflushgetEncodingwritewritewrite

Field Detail

encoderback to summary
private final CharsetEncoder encoder
outputStreamback to summary
private final AtomicFileOutputStream outputStream
problemCharactersback to summary
private final Set<Character> problemCharacters

Constructor Detail

AtomicFileWriterback to summary
public AtomicFileWriter(Path file, Charset encoding) throws IOException
AtomicFileWriterback to summary
public AtomicFileWriter(Path file, Charset encoding, boolean keepBackup) throws IOException
AtomicFileWriterback to summary
public AtomicFileWriter(Path file, Charset encoding, boolean keepBackup, @Nullable FileSnapshot expectedState) throws IOException
Parameters
expectedState:@Nullable FileSnapshot

see AtomicFileOutputStream#AtomicFileOutputStream(Path, boolean, FileSnapshot)

AtomicFileWriterback to summary
private AtomicFileWriter(AtomicFileOutputStream outputStream, Charset encoding)

Method Detail

abortback to summary
public void abort()

Aborts the write without replacing the target file.

getCommittedTargetFileStateback to summary
public @Nullable FileSnapshot getCommittedTargetFileState()

See AtomicFileOutputStream#getCommittedTargetFileState(); remains accessible after close().

getEncodingProblemsback to summary
public Set<Character> getEncodingProblems()
hasEncodingProblemsback to summary
public boolean hasEncodingProblems()
writeback to summary
public void write(String str) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a string.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs