Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Unterrainer committed Aug 17, 2021
2 parents 296acc2 + 4222ccc commit 56ec6a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<modelVersion>4.0.0</modelVersion>
<artifactId>jre-utils</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>
<name>JreUtils</name>
<packaging>jar</packaging>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,26 @@ private DoubleBufferedFileData getNewestForReadAccess() throws IOException {
return path2;
}

private DoubleBufferedFileData getOldestForReadAccess() throws IOException {
path1.probe();
path2.probe();
if (!path1.exists() && !path2.exists())
throw new IOException("There is no file to read from, because both files are missing.");
if (!path1.exists || !path2.exists())
throw new IOException("There is no file to read from, because the second file is missing.");

if (!path1.readable() && !path2.readable())
throw new IOException("Both files are locked for read-access.");
if (!path1.readable() || !path2.readable())
throw new IOException("The second file is locked for read-access.");

if (path1.modified() == null || path2.modified() == null)
throw new IOException("Could not read the modified-date from one of the files.");
if (path1.modified().compareTo(path2.modified()) > 0)
return path2;
return path1;
}

public void write(final ConsumerWithIoException<BufferedWriter> writeContentDelegate) throws IOException {
DoubleBufferedFileData p = getOldestForWriteAccess();
if (p.exists())
Expand All @@ -226,4 +246,9 @@ public String read() throws IOException {
DoubleBufferedFileData p = getNewestForReadAccess();
return Files.readString(p.path());
}

public String readOther() throws IOException {
DoubleBufferedFileData p = getOldestForReadAccess();
return Files.readString(p.path());
}
}

0 comments on commit 56ec6a4

Please sign in to comment.