mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Use Java 7 Files to delete and rename.
This commit is contained in:
Regular → Executable
+11
-4
@@ -203,12 +203,19 @@ public class FilePerKeyMap implements Map<String, String>, Closeable {
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
tmpFile.renameTo(file);
|
||||
try {
|
||||
Files.move(tmpFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteFile(Path path) {
|
||||
File key = path.toFile();
|
||||
key.delete();
|
||||
try {
|
||||
Files.deleteIfExists(path);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
@@ -297,7 +304,7 @@ public class FilePerKeyMap implements Map<String, String>, Closeable {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (kind == StandardWatchEventKinds.ENTRY_CREATE) {
|
||||
if (kind == StandardWatchEventKinds.ENTRY_CREATE) {
|
||||
Path p = dirPath.resolve(fileName);
|
||||
try {
|
||||
String mapVal = getFileContents0(p);
|
||||
|
||||
Regular → Executable
+3
-1
@@ -31,13 +31,15 @@ public class FilePerKeyMapTest {
|
||||
public void testMapMethods() throws InterruptedException {
|
||||
String val = map.put("one", "test1");
|
||||
assertEquals(val, null);
|
||||
Thread.sleep(5);
|
||||
Thread.sleep(10);
|
||||
|
||||
//After the entry has been written the value returned should be
|
||||
//the previous value
|
||||
val = map.put("one", "test2");
|
||||
assertEquals(val, "test1");
|
||||
|
||||
Thread.sleep(10);
|
||||
|
||||
//Check that get returns the latest value
|
||||
val = map.get("one");
|
||||
assertEquals("test2", val);
|
||||
|
||||
Reference in New Issue
Block a user