diff --git a/core-java/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer2.java b/core-java/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer2.java index 03ce233ce9..172d8036de 100644 --- a/core-java/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer2.java +++ b/core-java/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer2.java @@ -58,19 +58,18 @@ public class AsyncEchoServer2 { @Override public void completed(Integer result, Map attachment) { - Map actionInfo = attachment; - String action = (String) actionInfo.get("action"); + String action = (String) attachment.get("action"); if ("read".equals(action)) { - ByteBuffer buffer = (ByteBuffer) actionInfo.get("buffer"); + ByteBuffer buffer = (ByteBuffer) attachment.get("buffer"); buffer.flip(); - actionInfo.put("action", "write"); - clientChannel.write(buffer, actionInfo, this); + attachment.put("action", "write"); + clientChannel.write(buffer, attachment, this); buffer.clear(); } else if ("write".equals(action)) { ByteBuffer buffer = ByteBuffer.allocate(32); - actionInfo.put("action", "read"); - actionInfo.put("buffer", buffer); - clientChannel.read(buffer, actionInfo, this); + attachment.put("action", "read"); + attachment.put("buffer", buffer); + clientChannel.read(buffer, attachment, this); } } diff --git a/core-java/src/test/java/com/baeldung/java/nio2/async/AsyncFileTest.java b/core-java/src/test/java/com/baeldung/java/nio2/async/AsyncFileTest.java index 948c93ff0b..fcffc524b1 100644 --- a/core-java/src/test/java/com/baeldung/java/nio2/async/AsyncFileTest.java +++ b/core-java/src/test/java/com/baeldung/java/nio2/async/AsyncFileTest.java @@ -60,7 +60,7 @@ public class AsyncFileTest { @Test public void givenPathAndContent_whenWritesToFileWithFuture_thenCorrect() throws IOException, ExecutionException, InterruptedException { String fileName = UUID.randomUUID().toString(); - Path path = Paths.get(fileName); + Path path = Paths.get(Paths.get(HOME)); AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.WRITE, StandardOpenOption.CREATE,StandardOpenOption.DELETE_ON_CLOSE); ByteBuffer buffer = ByteBuffer.allocate(1024);