File tree 2 files changed +26
-1
lines changed
src/main/java/info/unterrainer/commons/jreutils
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 10
10
11
11
<modelVersion >4.0.0</modelVersion >
12
12
<artifactId >jre-utils</artifactId >
13
- <version >0.2.2 </version >
13
+ <version >0.2.3 </version >
14
14
<name >JreUtils</name >
15
15
<packaging >jar</packaging >
16
16
Original file line number Diff line number Diff line change @@ -211,6 +211,26 @@ private DoubleBufferedFileData getNewestForReadAccess() throws IOException {
211
211
return path2 ;
212
212
}
213
213
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
+
214
234
public void write (final ConsumerWithIoException <BufferedWriter > writeContentDelegate ) throws IOException {
215
235
DoubleBufferedFileData p = getOldestForWriteAccess ();
216
236
if (p .exists ())
@@ -226,4 +246,9 @@ public String read() throws IOException {
226
246
DoubleBufferedFileData p = getNewestForReadAccess ();
227
247
return Files .readString (p .path ());
228
248
}
249
+
250
+ public String readOther () throws IOException {
251
+ DoubleBufferedFileData p = getOldestForReadAccess ();
252
+ return Files .readString (p .path ());
253
+ }
229
254
}
You can’t perform that action at this time.
0 commit comments