Verified Owner
Top Description Fields Constructors Methods
org.jabref.logic.util.io

public final Record FileSnapshot

extends Record
Class Inheritance
Annotations
@NullMarked
Record Components
exists:boolean
whether the file existed; when false, size and modification time carry no meaning
size:long
the file size in bytes, -1 when the file did not exist
lastModifiedTime:@Nullable FileTime
the modification time, null when the file did not exist
Imports
java.io.IOException, java.nio.file.Files, .NoSuchFileException, .Path, java.nio.file.attribute.BasicFileAttributes, .FileTime, org.jspecify.annotations.NullMarked, .Nullable, org.slf4j.Logger, .LoggerFactory

Existence, size, and modification time of a file at one point in time — a version stamp for optimistic concurrency control on files: capture a snapshot before a multi-step operation, compare against a fresh one before committing, and treat a mismatch as a concurrent modification by another process.

The comparison is best-effort: a concurrent write within the file system's timestamp resolution that also keeps the size identical goes undetected.

Field Summary

Modifier and TypeField and Description
private static final FileSnapshot
private final boolean
exists

Record Component accessed by exists().

whether the file existed; when false, size and modification time carry no meaning
private final @Nullable FileTime
lastModifiedTime

Record Component accessed by lastModifiedTime().

the modification time, null when the file did not exist
private static final Logger
private final long
size

Record Component accessed by size().

the file size in bytes, -1 when the file did not exist

Constructor Summary

AccessConstructor and Description
public
FileSnapshot(boolean exists, long size, @Nullable FileTime lastModifiedTime)

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public boolean
exists()

Record Component getter of exists.

Record Component whether the file existed; when false, size and modification time carry no meaning

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public @Nullable FileTime
lastModifiedTime()

Record Component getter of lastModifiedTime.

Record Component the modification time, null when the file did not exist

public boolean
matches(Path file)

Best-effort check whether the given file still is in the state captured by this snapshot.

public static @Nullable FileSnapshot

Returns:

the snapshot, or null when the attributes could not be read (detection should then be disabled rather than misreporting a conflict)
read
(Path file)

Captures the current state of the given file.

public long
size()

Record Component getter of size.

Record Component the file size in bytes, -1 when the file did not exist

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

ABSENTback to summary
private static final FileSnapshot ABSENT
existsback to summary
private final boolean exists

Record Component accessed by exists().

whether the file existed; when false, size and modification time carry no meaning

lastModifiedTimeback to summary
private final @Nullable FileTime lastModifiedTime

Record Component accessed by lastModifiedTime().

the modification time, null when the file did not exist

LOGGERback to summary
private static final Logger LOGGER
sizeback to summary
private final long size

Record Component accessed by size().

the file size in bytes, -1 when the file did not exist

Constructor Detail

FileSnapshotback to summary
public FileSnapshot(boolean exists, long size, @Nullable FileTime lastModifiedTime)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
existsback to summary
public boolean exists()

Record Component getter of exists.

Record Component
whether the file existed; when false, size and modification time carry no meaning
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

lastModifiedTimeback to summary
public @Nullable FileTime lastModifiedTime()

Record Component getter of lastModifiedTime.

Record Component
the modification time, null when the file did not exist
matchesback to summary
public boolean matches(Path file)

Best-effort check whether the given file still is in the state captured by this snapshot. An unreadable current state counts as a mismatch.

readback to summary
public static @Nullable FileSnapshot read(Path file)

Captures the current state of the given file. A missing file yields a snapshot with exists() == false.

Returns:@Nullable FileSnapshot

the snapshot, or null when the attributes could not be read (detection should then be disabled rather than misreporting a conflict)

sizeback to summary
public long size()

Record Component getter of size.

Record Component
the file size in bytes, -1 when the file did not exist
toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.