File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
src/main/java/info/unterrainer/commons/jreutils Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 1010
1111 <modelVersion >4.0.0</modelVersion >
1212 <artifactId >jre-utils</artifactId >
13- <version >0.2.2 </version >
13+ <version >0.2.3 </version >
1414 <name >JreUtils</name >
1515 <packaging >jar</packaging >
1616
Original file line number Diff line number Diff line change @@ -211,6 +211,26 @@ private DoubleBufferedFileData getNewestForReadAccess() throws IOException {
211211 return path2 ;
212212 }
213213
214+ private DoubleBufferedFileData getOldestForReadAccess () throws IOException {
215+ path1 .probe ();
216+ path2 .probe ();
217+ if (!path1 .exists () && !path2 .exists ())
218+ throw new IOException ("There is no file to read from, because both files are missing." );
219+ if (!path1 .exists || !path2 .exists ())
220+ throw new IOException ("There is no file to read from, because the second file is missing." );
221+
222+ if (!path1 .readable () && !path2 .readable ())
223+ throw new IOException ("Both files are locked for read-access." );
224+ if (!path1 .readable () || !path2 .readable ())
225+ throw new IOException ("The second file is locked for read-access." );
226+
227+ if (path1 .modified () == null || path2 .modified () == null )
228+ throw new IOException ("Could not read the modified-date from one of the files." );
229+ if (path1 .modified ().compareTo (path2 .modified ()) > 0 )
230+ return path2 ;
231+ return path1 ;
232+ }
233+
214234 public void write (final ConsumerWithIoException <BufferedWriter > writeContentDelegate ) throws IOException {
215235 DoubleBufferedFileData p = getOldestForWriteAccess ();
216236 if (p .exists ())
@@ -226,4 +246,9 @@ public String read() throws IOException {
226246 DoubleBufferedFileData p = getNewestForReadAccess ();
227247 return Files .readString (p .path ());
228248 }
249+
250+ public String readOther () throws IOException {
251+ DoubleBufferedFileData p = getOldestForReadAccess ();
252+ return Files .readString (p .path ());
253+ }
229254}
You can’t perform that action at this time.
0 commit comments