FileSnapshot fileSnapshot = FileSnapshot.save(path);
byte[] content = Files.readAllBytes(path);
...
FileSnapshot newSnapshot = oldSnapshot.reload(path);
if (newSnapshot == fileSnapshot) {
// File was not modified
} else {
// File may have been modified
fileSnapshot = newSnapshot;
content = Files.readAllBytes(path);
}
File modifications that occur quicker than the resolution of the system's "last modified" timestamp of a file cannot be detected reliably. This implementation assumes a worst-case filesystem timestamp resolution of 2 seconds (as it exists on FAT file systems). A snapshot taken within 2 seconds since the last modified time is considered "racily clean" only: the file will be considered potentially modified even if the metadata matches.
| Modifier and Type | Field and Description |
|---|---|
| private final Object | |
| private final FileTime | |
| public static final FileSnapshot | NO_FILE
A |
| private final long | |
| private final Instant | |
| public static final long | UNKNOWN_SIZE
A value indicating an unknown file size. |
| private static final Duration |
| Access | Constructor and Description |
|---|---|
| protected | FileSnapshot(Instant
the snapTime, FileTime Instant the snapshot was takenthe "last modified" lastModified, long FileTimethe file size size, Object the file key fileKey)Creates a new |
| Modifier and Type | Method and Description |
|---|---|
| protected Object | Returns: the file key, may benullRetrieves the file key as recorded in this |
| protected FileTime | |
| protected long | Returns: the size,UNKNOWN_SIZE for a snapshot of a non-existing fileRetrieves the file size as recorded in this |
| protected Instant | |
| protected boolean | Returns: true if so, false otherwiseDetermines whether this |
| public FileSnapshot | reload(Path
to take the snapshot of file, LinkOption... LinkOptions to useReload the |
| public boolean | Returns: true if the two snapshots have the same file metadata, false otherwiseFileSnapshot to compare to (should be for the same Path)Compares the snapshots' file metadata. |
| public static FileSnapshot | save(Path
to take the snapshot of file, LinkOption... LinkOptions to useCreates a new |
| fileKey | back to summary |
|---|---|
| private final Object fileKey | |
| lastModified | back to summary |
|---|---|
| private final FileTime lastModified | |
| NO_FILE | back to summary |
|---|---|
| public static final FileSnapshot NO_FILE A | |
| size | back to summary |
|---|---|
| private final long size | |
| snapTime | back to summary |
|---|---|
| private final Instant snapTime | |
| UNKNOWN_SIZE | back to summary |
|---|---|
| public static final long UNKNOWN_SIZE A value indicating an unknown file size. | |
| WORST_CASE_TIMESTAMP_RESOLUTION | back to summary |
|---|---|
| private static final Duration WORST_CASE_TIMESTAMP_RESOLUTION | |
| FileSnapshot | back to summary |
|---|---|
| protected FileSnapshot(Instant snapTime, FileTime lastModified, long size, Object fileKey) Creates a new | |
| getFileKey | back to summary |
|---|---|
| protected Object getFileKey() Retrieves the file key as recorded in this
| |
| getLastModified | back to summary |
|---|---|
| protected FileTime getLastModified() Retrieves the "last modified" time as recorded in this | |
| getSize | back to summary |
|---|---|
| protected long getSize() Retrieves the file size as recorded in this
| |
| getTime | back to summary |
|---|---|
| protected Instant getTime() Retrieves the time this | |
| mayBeRacilyClean | back to summary |
|---|---|
| protected boolean mayBeRacilyClean() Determines whether this
| |
| reload | back to summary |
|---|---|
| public FileSnapshot reload(Path file, LinkOption... options) throws IOException Reload the
| |
| same | back to summary |
|---|---|
| public boolean same(FileSnapshot other) Compares the snapshots' file metadata.
| |
| save | back to summary |
|---|---|
| public static FileSnapshot save(Path file, LinkOption... options) throws IOException Creates a new
| |