diff --git a/core-java-modules/README.md b/core-java-modules/README.md index 55dacca916..fa77846b45 100644 --- a/core-java-modules/README.md +++ b/core-java-modules/README.md @@ -5,6 +5,5 @@ This module contains modules about core Java ## Relevant articles: - [Multi-Module Maven Application with Java Modules](https://www.baeldung.com/maven-multi-module-project-java-jpms) -- [Guide to Java FileChannel](https://www.baeldung.com/java-filechannel) - [Understanding the NumberFormatException in Java](https://www.baeldung.com/java-number-format-exception) - [Will an Error Be Caught by Catch Block in Java?](https://www.baeldung.com/java-error-catch) diff --git a/core-java-modules/core-java-io/README.md b/core-java-modules/core-java-io/README.md index 34b2f371e1..2a68e861e8 100644 --- a/core-java-modules/core-java-io/README.md +++ b/core-java-modules/core-java-io/README.md @@ -13,22 +13,11 @@ This module contains articles about core Java input and output (IO) - [Differences Between the Java WatchService API and the Apache Commons IO Monitor Library](http://www.baeldung.com/java-watchservice-vs-apache-commons-io-monitor-library) - [File Size in Java](http://www.baeldung.com/java-file-size) - [Comparing getPath(), getAbsolutePath(), and getCanonicalPath() in Java](http://www.baeldung.com/java-path) -- [Using Java MappedByteBuffer](http://www.baeldung.com/java-mapped-byte-buffer) - [How to Copy a File with Java](http://www.baeldung.com/java-copy-file) - [Java – Append Data to a File](http://www.baeldung.com/java-append-to-file) - [FileNotFoundException in Java](http://www.baeldung.com/java-filenotfound-exception) - [How to Read a File in Java](http://www.baeldung.com/reading-file-in-java) -- [A Guide To NIO2 Asynchronous File Channel](http://www.baeldung.com/java-nio2-async-file-channel) -- [A Guide To NIO2 FileVisitor](http://www.baeldung.com/java-nio2-file-visitor) -- [A Guide To NIO2 File Attribute APIs](http://www.baeldung.com/java-nio2-file-attribute) -- [Introduction to the Java NIO2 File API](http://www.baeldung.com/java-nio-2-file-api) - [Zipping and Unzipping in Java](http://www.baeldung.com/java-compress-and-uncompress) -- [Java NIO2 Path API](http://www.baeldung.com/java-nio-2-path) -- [A Guide to WatchService in Java NIO2](http://www.baeldung.com/java-nio2-watchservice) -- [Guide to Java NIO2 Asynchronous Channel APIs](http://www.baeldung.com/java-nio-2-async-channels) -- [A Guide to NIO2 Asynchronous Socket Channel](http://www.baeldung.com/java-nio2-async-socket-channel) -- [Download a File From an URL in Java](http://www.baeldung.com/java-download-file) -- [Create a Symbolic Link with Java](http://www.baeldung.com/java-symlink) - [Quick Use of FilenameFilter](http://www.baeldung.com/java-filename-filter) - [Read a File into an ArrayList](https://www.baeldung.com/java-file-to-arraylist) - [Guide to Java OutputStream](https://www.baeldung.com/java-outputstream) @@ -40,6 +29,5 @@ This module contains articles about core Java input and output (IO) - [How to Write to a CSV File in Java](https://www.baeldung.com/java-csv) - [List Files in a Directory in Java](https://www.baeldung.com/java-list-directory-files) - [Java InputStream to Byte Array and ByteBuffer](https://www.baeldung.com/convert-input-stream-to-array-of-bytes) -- [Introduction to the Java NIO Selector](https://www.baeldung.com/java-nio-selector) - [How to Avoid the Java FileNotFoundException When Loading Resources](https://www.baeldung.com/java-classpath-resource-cannot-be-opened) - [[More -->]](/core-java-modules/core-java-io-2) diff --git a/core-java-modules/core-java-io/pom.xml b/core-java-modules/core-java-io/pom.xml index 3478f71286..393ab5e318 100644 --- a/core-java-modules/core-java-io/pom.xml +++ b/core-java-modules/core-java-io/pom.xml @@ -27,12 +27,6 @@ ${hsqldb.version} runtime - - - org.asynchttpclient - async-http-client - ${async-http-client.version} - com.opencsv opencsv @@ -155,7 +149,6 @@ 3.0.0-M1 2.4.0 - 2.4.5 1.18 0.1.5 diff --git a/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/README.md b/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/README.md deleted file mode 100644 index b28aae1397..0000000000 --- a/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/README.md +++ /dev/null @@ -1,2 +0,0 @@ -###Relevant Articles: -- [Introduction to the Java NIO Selector](http://www.baeldung.com/java-nio-selector) diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/filechannel/FileChannelUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/filechannel/FileChannelUnitTest.java deleted file mode 100644 index 6964ba80e3..0000000000 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/filechannel/FileChannelUnitTest.java +++ /dev/null @@ -1,165 +0,0 @@ -package com.baeldung.filechannel; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.ByteBuffer; -import java.nio.MappedByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; -import java.nio.charset.StandardCharsets; - -import org.junit.Test; - -public class FileChannelUnitTest { - - @Test - public void givenFile_whenReadWithFileChannelUsingRandomAccessFile_thenCorrect() throws IOException { - - try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r"); - FileChannel channel = reader.getChannel(); - ByteArrayOutputStream out = new ByteArrayOutputStream();) { - - int bufferSize = 1024; - if (bufferSize > channel.size()) { - bufferSize = (int) channel.size(); - } - ByteBuffer buff = ByteBuffer.allocate(bufferSize); - - while (channel.read(buff) > 0) { - out.write(buff.array(), 0, buff.position()); - buff.clear(); - } - - String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8); - - assertEquals("Hello world", fileContent); - } - } - - @Test - public void givenFile_whenReadWithFileChannelUsingFileInputStream_thenCorrect() throws IOException { - - try (ByteArrayOutputStream out = new ByteArrayOutputStream(); - FileInputStream fin = new FileInputStream("src/test/resources/test_read.in"); - FileChannel channel = fin.getChannel();) { - - int bufferSize = 1024; - if (bufferSize > channel.size()) { - bufferSize = (int) channel.size(); - } - ByteBuffer buff = ByteBuffer.allocate(bufferSize); - - while (channel.read(buff) > 0) { - out.write(buff.array(), 0, buff.position()); - buff.clear(); - } - String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8); - - assertEquals("Hello world", fileContent); - } - } - - @Test - public void givenFile_whenReadAFileSectionIntoMemoryWithFileChannel_thenCorrect() throws IOException { - - try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r"); - FileChannel channel = reader.getChannel(); - ByteArrayOutputStream out = new ByteArrayOutputStream();) { - - MappedByteBuffer buff = channel.map(FileChannel.MapMode.READ_ONLY, 6, 5); - - if (buff.hasRemaining()) { - byte[] data = new byte[buff.remaining()]; - buff.get(data); - assertEquals("world", new String(data, StandardCharsets.UTF_8)); - } - } - } - - @Test - public void whenWriteWithFileChannelUsingRandomAccessFile_thenCorrect() throws IOException { - String file = "src/test/resources/test_write_using_filechannel.txt"; - try (RandomAccessFile writer = new RandomAccessFile(file, "rw"); - FileChannel channel = writer.getChannel();) { - ByteBuffer buff = ByteBuffer.wrap("Hello world".getBytes(StandardCharsets.UTF_8)); - - channel.write(buff); - - // now we verify whether the file was written correctly - RandomAccessFile reader = new RandomAccessFile(file, "r"); - assertEquals("Hello world", reader.readLine()); - reader.close(); - } - } - - @Test - public void givenFile_whenWriteAFileUsingLockAFileSectionWithFileChannel_thenCorrect() throws IOException { - try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "rw"); - FileChannel channel = reader.getChannel(); - FileLock fileLock = channel.tryLock(6, 5, Boolean.FALSE);) { - - assertNotNull(fileLock); - } - } - - @Test - public void givenFile_whenReadWithFileChannelGetPosition_thenCorrect() throws IOException { - - try (ByteArrayOutputStream out = new ByteArrayOutputStream(); - RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r"); - FileChannel channel = reader.getChannel();) { - - int bufferSize = 1024; - if (bufferSize > channel.size()) { - bufferSize = (int) channel.size(); - } - ByteBuffer buff = ByteBuffer.allocate(bufferSize); - - while (channel.read(buff) > 0) { - out.write(buff.array(), 0, buff.position()); - buff.clear(); - } - - // the original file is 11 bytes long, so that's where the position pointer should be - assertEquals(11, channel.position()); - - channel.position(4); - assertEquals(4, channel.position()); - } - } - - @Test - public void whenGetFileSize_thenCorrect() throws IOException { - - try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r"); - FileChannel channel = reader.getChannel();) { - - // the original file is 11 bytes long, so that's where the position pointer should be - assertEquals(11, channel.size()); - } - } - - @Test - public void whenTruncateFile_thenCorrect() throws IOException { - String input = "this is a test input"; - - FileOutputStream fout = new FileOutputStream("src/test/resources/test_truncate.txt"); - FileChannel channel = fout.getChannel(); - - ByteBuffer buff = ByteBuffer.wrap(input.getBytes()); - channel.write(buff); - buff.flip(); - - channel = channel.truncate(5); - assertEquals(5, channel.size()); - - fout.close(); - channel.close(); - } -} diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/README.md b/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/README.md deleted file mode 100644 index 569be82d27..0000000000 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/README.md +++ /dev/null @@ -1,11 +0,0 @@ -### Relevant Articles: -- [Introduction to the Java NIO2 File API](http://www.baeldung.com/java-nio-2-file-api) -- [Java NIO2 Path API](http://www.baeldung.com/java-nio-2-path) -- [A Guide To NIO2 Asynchronous File Channel](http://www.baeldung.com/java-nio2-async-file-channel) -- [Guide to Selenium with JUnit / TestNG](http://www.baeldung.com/java-selenium-with-junit-and-testng) -- [A Guide to NIO2 Asynchronous Socket Channel](http://www.baeldung.com/java-nio2-async-socket-channel) -- [A Guide To NIO2 FileVisitor](http://www.baeldung.com/java-nio2-file-visitor) -- [A Guide To NIO2 File Attribute APIs](http://www.baeldung.com/java-nio2-file-attribute) -- [How to use the Spring FactoryBean?](http://www.baeldung.com/spring-factorybean) -- [A Guide to WatchService in Java NIO2](http://www.baeldung.com/java-nio2-watchservice) -- [Guide to Java NIO2 Asynchronous Channel APIs](http://www.baeldung.com/java-nio-2-async-channels) diff --git a/core-java-modules/core-java-io/src/test/resources/test_truncate.txt b/core-java-modules/core-java-io/src/test/resources/test_truncate.txt deleted file mode 100644 index 26d3b38cdd..0000000000 --- a/core-java-modules/core-java-io/src/test/resources/test_truncate.txt +++ /dev/null @@ -1 +0,0 @@ -this \ No newline at end of file diff --git a/core-java-modules/core-java-io/src/test/resources/test_write_using_filechannel.txt b/core-java-modules/core-java-io/src/test/resources/test_write_using_filechannel.txt deleted file mode 100644 index 70c379b63f..0000000000 --- a/core-java-modules/core-java-io/src/test/resources/test_write_using_filechannel.txt +++ /dev/null @@ -1 +0,0 @@ -Hello world \ No newline at end of file diff --git a/core-java-modules/core-java-networking-2/README.md b/core-java-modules/core-java-networking-2/README.md index 7dc33b5e11..120b111ff5 100644 --- a/core-java-modules/core-java-networking-2/README.md +++ b/core-java-modules/core-java-networking-2/README.md @@ -4,10 +4,11 @@ This module contains articles about networking in Java ### Relevant Articles -- [Checking if a URL Exists in Java](https://www.baeldung.com/java-check-url-exists) -- [Making a JSON POST Request With HttpURLConnection](https://www.baeldung.com/httpurlconnection-post) +- [Checking If a URL Exists in Java](https://www.baeldung.com/java-check-url-exists) +- [Making a JSON POST Request with HttpURLConnection](https://www.baeldung.com/httpurlconnection-post) - [Using Curl in Java](https://www.baeldung.com/java-curl) -- [Do a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request) -- [Sending Emails with Java](http://www.baeldung.com/java-email) +- [Do a Simple HTTP Request in Java](https://www.baeldung.com/java-http-request) +- [Sending Emails with Java](https://www.baeldung.com/java-email) - [Authentication with HttpUrlConnection](https://www.baeldung.com/java-http-url-connection) +- [Download a File from an URL in Java](https://www.baeldung.com/java-download-file) - [[<-- Prev]](/core-java-modules/core-java-networking) diff --git a/core-java-modules/core-java-networking-2/pom.xml b/core-java-modules/core-java-networking-2/pom.xml index 2d404a553b..c3a5891066 100644 --- a/core-java-modules/core-java-networking-2/pom.xml +++ b/core-java-modules/core-java-networking-2/pom.xml @@ -6,9 +6,10 @@ jar - com.baeldung.core-java-modules - core-java-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java @@ -27,6 +28,11 @@ mail ${javax.mail.version} + + org.asynchttpclient + async-http-client + ${async-http-client.version} + @@ -36,5 +42,6 @@ 4.5.9 1.5.0-b01 + 2.4.5 diff --git a/core-java-modules/core-java-io/src/main/java/com/baeldung/download/FileDownload.java b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/download/FileDownload.java similarity index 99% rename from core-java-modules/core-java-io/src/main/java/com/baeldung/download/FileDownload.java rename to core-java-modules/core-java-networking-2/src/main/java/com/baeldung/download/FileDownload.java index a099406d4c..ebcf7a70f7 100644 --- a/core-java-modules/core-java-io/src/main/java/com/baeldung/download/FileDownload.java +++ b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/download/FileDownload.java @@ -4,7 +4,7 @@ import org.apache.commons.io.FileUtils; import org.asynchttpclient.*; import java.io.*; -import java.net.*; +import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.FileChannel; import java.nio.channels.ReadableByteChannel; diff --git a/core-java-modules/core-java-io/src/main/java/com/baeldung/download/ResumableDownload.java b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/download/ResumableDownload.java similarity index 100% rename from core-java-modules/core-java-io/src/main/java/com/baeldung/download/ResumableDownload.java rename to core-java-modules/core-java-networking-2/src/main/java/com/baeldung/download/ResumableDownload.java diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/download/FileDownloadIntegrationTest.java b/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/download/FileDownloadIntegrationTest.java similarity index 98% rename from core-java-modules/core-java-io/src/test/java/com/baeldung/download/FileDownloadIntegrationTest.java rename to core-java-modules/core-java-networking-2/src/test/java/com/baeldung/download/FileDownloadIntegrationTest.java index 81ac391958..16017ee482 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/download/FileDownloadIntegrationTest.java +++ b/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/download/FileDownloadIntegrationTest.java @@ -1,8 +1,10 @@ package com.baeldung.download; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; +import javax.xml.bind.DatatypeConverter; import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; @@ -11,11 +13,7 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.concurrent.ExecutionException; -import javax.xml.bind.DatatypeConverter; - -import org.junit.After; -import org.junit.BeforeClass; -import org.junit.Test; +import static org.junit.Assert.assertTrue; public class FileDownloadIntegrationTest { diff --git a/core-java-modules/core-java-nio-2/README.md b/core-java-modules/core-java-nio-2/README.md new file mode 100644 index 0000000000..8b29c97385 --- /dev/null +++ b/core-java-modules/core-java-nio-2/README.md @@ -0,0 +1,11 @@ +## Core Java NIO + +This module contains articles about core Java non-blocking input and output (IO) + +## Relevant Articles: + +- [A Guide to WatchService in Java NIO2](https://www.baeldung.com/java-nio2-watchservice) +- [Create a Symbolic Link with Java](https://www.baeldung.com/java-symlink) +- [Introduction to the Java NIO Selector](https://www.baeldung.com/java-nio-selector) +- [Using Java MappedByteBuffer](https://www.baeldung.com/java-mapped-byte-buffer) +- [[<-- Prev]](/core-java-modules/core-java-nio) \ No newline at end of file diff --git a/core-java-modules/core-java-nio-2/pom.xml b/core-java-modules/core-java-nio-2/pom.xml new file mode 100644 index 0000000000..c1fa423b38 --- /dev/null +++ b/core-java-modules/core-java-nio-2/pom.xml @@ -0,0 +1,17 @@ + + 4.0.0 + core-java-nio-2 + 0.1.0-SNAPSHOT + core-java-nio-2 + jar + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java + + + \ No newline at end of file diff --git a/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/EchoClient.java b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoClient.java similarity index 96% rename from core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/EchoClient.java rename to core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoClient.java index 61f339db58..dd0a15ac7e 100644 --- a/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/EchoClient.java +++ b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoClient.java @@ -1,4 +1,4 @@ -package com.baeldung.java.nio.selector; +package com.baeldung.selector; import java.io.IOException; import java.net.InetSocketAddress; diff --git a/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/EchoServer.java b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java similarity index 98% rename from core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/EchoServer.java rename to core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java index 7c1e291646..8cf2e941fe 100644 --- a/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio/selector/EchoServer.java +++ b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java @@ -1,4 +1,4 @@ -package com.baeldung.java.nio.selector; +package com.baeldung.selector; import java.io.File; import java.io.IOException; diff --git a/core-java-modules/core-java-io/src/main/java/com/baeldung/symlink/SymLinkExample.java b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/symlink/SymLinkExample.java similarity index 93% rename from core-java-modules/core-java-io/src/main/java/com/baeldung/symlink/SymLinkExample.java rename to core-java-modules/core-java-nio-2/src/main/java/com/baeldung/symlink/SymLinkExample.java index 63ee0f14b1..4c2c47e085 100644 --- a/core-java-modules/core-java-io/src/main/java/com/baeldung/symlink/SymLinkExample.java +++ b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/symlink/SymLinkExample.java @@ -6,9 +6,11 @@ import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import static java.nio.file.StandardOpenOption.*; import java.util.stream.IntStream; +import static java.nio.file.StandardOpenOption.CREATE; +import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; + public class SymLinkExample { public void createSymbolicLink(Path link, Path target) throws IOException { diff --git a/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/watcher/DirectoryWatcherExample.java b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/watcher/DirectoryWatcherExample.java similarity index 74% rename from core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/watcher/DirectoryWatcherExample.java rename to core-java-modules/core-java-nio-2/src/main/java/com/baeldung/watcher/DirectoryWatcherExample.java index 4c35ffdb22..e8a2a401ab 100644 --- a/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/watcher/DirectoryWatcherExample.java +++ b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/watcher/DirectoryWatcherExample.java @@ -1,13 +1,7 @@ -package com.baeldung.java.nio2.watcher; +package com.baeldung.watcher; import java.io.IOException; -import java.nio.file.FileSystems; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardWatchEventKinds; -import java.nio.file.WatchEvent; -import java.nio.file.WatchKey; -import java.nio.file.WatchService; +import java.nio.file.*; public class DirectoryWatcherExample { diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/mappedbytebuffer/MappedByteBufferUnitTest.java b/core-java-modules/core-java-nio-2/src/test/java/com/baeldung/mappedbytebuffer/MappedByteBufferUnitTest.java similarity index 100% rename from core-java-modules/core-java-io/src/test/java/com/baeldung/mappedbytebuffer/MappedByteBufferUnitTest.java rename to core-java-modules/core-java-nio-2/src/test/java/com/baeldung/mappedbytebuffer/MappedByteBufferUnitTest.java diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio/selector/NioEchoLiveTest.java b/core-java-modules/core-java-nio-2/src/test/java/com/baeldung/selector/NioEchoLiveTest.java similarity index 87% rename from core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio/selector/NioEchoLiveTest.java rename to core-java-modules/core-java-nio-2/src/test/java/com/baeldung/selector/NioEchoLiveTest.java index 0e1afa87a5..39deb798e5 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio/selector/NioEchoLiveTest.java +++ b/core-java-modules/core-java-nio-2/src/test/java/com/baeldung/selector/NioEchoLiveTest.java @@ -1,13 +1,15 @@ -package com.baeldung.java.nio.selector; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; +package com.baeldung.selector; +import com.baeldung.selector.EchoClient; +import com.baeldung.selector.EchoServer; import org.junit.After; import org.junit.Before; import org.junit.Test; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; + public class NioEchoLiveTest { private Process server; diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/symlink/SymLinkExampleManualTest.java b/core-java-modules/core-java-nio-2/src/test/java/com/baeldung/symlink/SymLinkExampleManualTest.java similarity index 100% rename from core-java-modules/core-java-io/src/test/java/com/baeldung/symlink/SymLinkExampleManualTest.java rename to core-java-modules/core-java-nio-2/src/test/java/com/baeldung/symlink/SymLinkExampleManualTest.java index caa7049475..e6723e719c 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/symlink/SymLinkExampleManualTest.java +++ b/core-java-modules/core-java-nio-2/src/test/java/com/baeldung/symlink/SymLinkExampleManualTest.java @@ -1,13 +1,13 @@ package com.baeldung.symlink; -import static org.junit.Assert.*; +import org.junit.Test; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import org.junit.Test; +import static org.junit.Assert.*; public class SymLinkExampleManualTest { diff --git a/core-java-modules/core-java-io/src/test/resources/fileToRead.txt b/core-java-modules/core-java-nio-2/src/test/resources/fileToRead.txt similarity index 100% rename from core-java-modules/core-java-io/src/test/resources/fileToRead.txt rename to core-java-modules/core-java-nio-2/src/test/resources/fileToRead.txt diff --git a/core-java-modules/core-java-io/src/test/resources/fileToWriteTo.txt b/core-java-modules/core-java-nio-2/src/test/resources/fileToWriteTo.txt similarity index 100% rename from core-java-modules/core-java-io/src/test/resources/fileToWriteTo.txt rename to core-java-modules/core-java-nio-2/src/test/resources/fileToWriteTo.txt diff --git a/core-java-modules/core-java-nio/README.md b/core-java-modules/core-java-nio/README.md index 727bd2546c..f37c8a3d38 100644 --- a/core-java-modules/core-java-nio/README.md +++ b/core-java-modules/core-java-nio/README.md @@ -5,4 +5,13 @@ This module contains articles about core Java non-blocking input and output (IO) ## Relevant Articles: - [Determine File Creation Date in Java](https://www.baeldung.com/java-file-creation-date) -- [Find the Number of Lines in a File Using Jav](https://www.baeldung.com/java-file-number-of-lines) +- [Find the Number of Lines in a File Using Java](https://www.baeldung.com/java-file-number-of-lines) +- [A Guide to NIO2 Asynchronous File Channel](https://www.baeldung.com/java-nio2-async-file-channel) +- [A Guide to NIO2 FileVisitor](https://www.baeldung.com/java-nio2-file-visitor) +- [Guide to Java FileChannel](https://www.baeldung.com/java-filechannel) +- [A Guide to NIO2 File Attribute APIs](https://www.baeldung.com/java-nio2-file-attribute) +- [Introduction to the Java NIO2 File API](https://www.baeldung.com/java-nio-2-file-api) +- [Java NIO2 Path API](https://www.baeldung.com/java-nio-2-path) +- [Guide to Java NIO2 Asynchronous Channel APIs](https://www.baeldung.com/java-nio-2-async-channels) +- [A Guide to NIO2 Asynchronous Socket Channel](https://www.baeldung.com/java-nio2-async-socket-channel) +- [[More -->]](/core-java-modules/core-java-nio-2) \ No newline at end of file diff --git a/core-java-modules/core-java-nio/pom.xml b/core-java-modules/core-java-nio/pom.xml index 31433e632f..da8759a956 100644 --- a/core-java-modules/core-java-nio/pom.xml +++ b/core-java-modules/core-java-nio/pom.xml @@ -13,4 +13,5 @@ 0.0.1-SNAPSHOT ../../parent-java + \ No newline at end of file diff --git a/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/visitor/FileSearchExample.java b/core-java-modules/core-java-nio/src/main/java/com/baeldung/filevisitor/FileSearchExample.java similarity index 97% rename from core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/visitor/FileSearchExample.java rename to core-java-modules/core-java-nio/src/main/java/com/baeldung/filevisitor/FileSearchExample.java index b1b790f541..b49d6eb570 100644 --- a/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/visitor/FileSearchExample.java +++ b/core-java-modules/core-java-nio/src/main/java/com/baeldung/filevisitor/FileSearchExample.java @@ -1,4 +1,4 @@ -package com.baeldung.java.nio2.visitor; +package com.baeldung.filevisitor; import java.io.IOException; import java.nio.file.*; diff --git a/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/visitor/FileVisitorImpl.java b/core-java-modules/core-java-nio/src/main/java/com/baeldung/filevisitor/FileVisitorImpl.java similarity index 94% rename from core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/visitor/FileVisitorImpl.java rename to core-java-modules/core-java-nio/src/main/java/com/baeldung/filevisitor/FileVisitorImpl.java index aa769b5091..d86264720f 100644 --- a/core-java-modules/core-java-io/src/main/java/com/baeldung/java/nio2/visitor/FileVisitorImpl.java +++ b/core-java-modules/core-java-nio/src/main/java/com/baeldung/filevisitor/FileVisitorImpl.java @@ -1,4 +1,4 @@ -package com.baeldung.java.nio2.visitor; +package com.baeldung.filevisitor; import java.io.IOException; import java.nio.file.FileVisitResult; diff --git a/core-java-modules/core-java-nio/src/main/java/com/baeldung/file/Main.java b/core-java-modules/core-java-nio/src/main/java/com/baeldung/lines/Main.java similarity index 62% rename from core-java-modules/core-java-nio/src/main/java/com/baeldung/file/Main.java rename to core-java-modules/core-java-nio/src/main/java/com/baeldung/lines/Main.java index d8800dd881..5aa0968ab9 100644 --- a/core-java-modules/core-java-nio/src/main/java/com/baeldung/file/Main.java +++ b/core-java-modules/core-java-nio/src/main/java/com/baeldung/lines/Main.java @@ -1,13 +1,13 @@ -package com.baeldung.file; +package com.baeldung.lines; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingApacheCommonsIO; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingBufferedReader; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingGoogleGuava; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingLineNumberReader; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingNIOFileChannel; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingNIOFiles; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingNIOFilesReadAllLines; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingScanner; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingApacheCommonsIO; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingBufferedReader; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingGoogleGuava; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingLineNumberReader; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingNIOFileChannel; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingNIOFiles; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingNIOFilesReadAllLines; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingScanner; public class Main { diff --git a/core-java-modules/core-java-nio/src/main/java/com/baeldung/file/NumberOfLineFinder.java b/core-java-modules/core-java-nio/src/main/java/com/baeldung/lines/NumberOfLineFinder.java similarity index 99% rename from core-java-modules/core-java-nio/src/main/java/com/baeldung/file/NumberOfLineFinder.java rename to core-java-modules/core-java-nio/src/main/java/com/baeldung/lines/NumberOfLineFinder.java index 3abf82f3fa..b355295dab 100644 --- a/core-java-modules/core-java-nio/src/main/java/com/baeldung/file/NumberOfLineFinder.java +++ b/core-java-modules/core-java-nio/src/main/java/com/baeldung/lines/NumberOfLineFinder.java @@ -1,4 +1,4 @@ -package com.baeldung.file; +package com.baeldung.lines; import java.io.BufferedReader; import java.io.File; diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoClient.java b/core-java-modules/core-java-nio/src/test/java/com/baeldung/async/AsyncEchoClient.java similarity index 98% rename from core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoClient.java rename to core-java-modules/core-java-nio/src/test/java/com/baeldung/async/AsyncEchoClient.java index ebab715306..f42f5cdeca 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoClient.java +++ b/core-java-modules/core-java-nio/src/test/java/com/baeldung/async/AsyncEchoClient.java @@ -1,4 +1,4 @@ -package com.baeldung.java.nio2.async; +package com.baeldung.async; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoIntegrationTest.java b/core-java-modules/core-java-nio/src/test/java/com/baeldung/async/AsyncEchoIntegrationTest.java similarity index 95% rename from core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoIntegrationTest.java rename to core-java-modules/core-java-nio/src/test/java/com/baeldung/async/AsyncEchoIntegrationTest.java index 3cfac0e90f..42053cea96 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoIntegrationTest.java +++ b/core-java-modules/core-java-nio/src/test/java/com/baeldung/async/AsyncEchoIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.java.nio2.async; +package com.baeldung.async; import org.junit.After; import org.junit.Before; diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer.java b/core-java-modules/core-java-nio/src/test/java/com/baeldung/async/AsyncEchoServer.java similarity index 98% rename from core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer.java rename to core-java-modules/core-java-nio/src/test/java/com/baeldung/async/AsyncEchoServer.java index 01873b344a..b3f8151b7e 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer.java +++ b/core-java-modules/core-java-nio/src/test/java/com/baeldung/async/AsyncEchoServer.java @@ -1,4 +1,4 @@ -package com.baeldung.java.nio2.async; +package com.baeldung.async; import java.io.File; import java.io.IOException; diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer2.java b/core-java-modules/core-java-nio/src/test/java/com/baeldung/async/AsyncEchoServer2.java similarity index 98% rename from core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer2.java rename to core-java-modules/core-java-nio/src/test/java/com/baeldung/async/AsyncEchoServer2.java index 663fc4f2ed..15b98cbf6e 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncEchoServer2.java +++ b/core-java-modules/core-java-nio/src/test/java/com/baeldung/async/AsyncEchoServer2.java @@ -1,4 +1,4 @@ -package com.baeldung.java.nio2.async; +package com.baeldung.async; import java.io.File; import java.io.IOException; diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncFileIntegrationTest.java b/core-java-modules/core-java-nio/src/test/java/com/baeldung/asyncfilechannel/AsyncFileChannelIntegrationTest.java similarity index 98% rename from core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncFileIntegrationTest.java rename to core-java-modules/core-java-nio/src/test/java/com/baeldung/asyncfilechannel/AsyncFileChannelIntegrationTest.java index cf37b92565..68f0afec95 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/async/AsyncFileIntegrationTest.java +++ b/core-java-modules/core-java-nio/src/test/java/com/baeldung/asyncfilechannel/AsyncFileChannelIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.java.nio2.async; +package com.baeldung.asyncfilechannel; import org.junit.Test; @@ -16,7 +16,7 @@ import java.util.concurrent.Future; import static org.junit.Assert.assertEquals; -public class AsyncFileIntegrationTest { +public class AsyncFileChannelIntegrationTest { @Test public void givenPath_whenReadsContentWithFuture_thenCorrect() throws IOException, ExecutionException, InterruptedException { diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/attributes/BasicAttribsIntegrationTest.java b/core-java-modules/core-java-nio/src/test/java/com/baeldung/attributes/BasicAttribsIntegrationTest.java similarity index 98% rename from core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/attributes/BasicAttribsIntegrationTest.java rename to core-java-modules/core-java-nio/src/test/java/com/baeldung/attributes/BasicAttribsIntegrationTest.java index 4b6302e93c..a1f05d107f 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/attributes/BasicAttribsIntegrationTest.java +++ b/core-java-modules/core-java-nio/src/test/java/com/baeldung/attributes/BasicAttribsIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.java.nio2.attributes; +package com.baeldung.attributes; import org.junit.BeforeClass; import org.junit.Test; diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/FileIntegrationTest.java b/core-java-modules/core-java-nio/src/test/java/com/baeldung/file/FileIntegrationTest.java similarity index 99% rename from core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/FileIntegrationTest.java rename to core-java-modules/core-java-nio/src/test/java/com/baeldung/file/FileIntegrationTest.java index d1cf81e4ce..1ae84a4dcf 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/FileIntegrationTest.java +++ b/core-java-modules/core-java-nio/src/test/java/com/baeldung/file/FileIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.java.nio2; +package com.baeldung.file; import org.apache.commons.io.FileUtils; import org.junit.AfterClass; diff --git a/core-java-modules/core-java-nio/src/test/java/com/baeldung/file/NumberOfLineFinderUnitTest.java b/core-java-modules/core-java-nio/src/test/java/com/baeldung/lines/NumberOfLineFinderUnitTest.java similarity index 71% rename from core-java-modules/core-java-nio/src/test/java/com/baeldung/file/NumberOfLineFinderUnitTest.java rename to core-java-modules/core-java-nio/src/test/java/com/baeldung/lines/NumberOfLineFinderUnitTest.java index 40ed6d6bba..661b42accd 100644 --- a/core-java-modules/core-java-nio/src/test/java/com/baeldung/file/NumberOfLineFinderUnitTest.java +++ b/core-java-modules/core-java-nio/src/test/java/com/baeldung/lines/NumberOfLineFinderUnitTest.java @@ -1,13 +1,13 @@ -package com.baeldung.file; +package com.baeldung.lines; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingApacheCommonsIO; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingBufferedReader; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingGoogleGuava; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingLineNumberReader; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingNIOFileChannel; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingNIOFiles; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingNIOFilesReadAllLines; -import static com.baeldung.file.NumberOfLineFinder.getTotalNumberOfLinesUsingScanner; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingApacheCommonsIO; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingBufferedReader; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingGoogleGuava; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingLineNumberReader; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingNIOFileChannel; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingNIOFiles; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingNIOFilesReadAllLines; +import static com.baeldung.lines.NumberOfLineFinder.getTotalNumberOfLinesUsingScanner; import static org.junit.Assert.assertEquals; import org.junit.Test; diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/PathManualTest.java b/core-java-modules/core-java-nio/src/test/java/com/baeldung/path/PathManualTest.java similarity index 97% rename from core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/PathManualTest.java rename to core-java-modules/core-java-nio/src/test/java/com/baeldung/path/PathManualTest.java index 969dff1da2..7017fd42e7 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/java/nio2/PathManualTest.java +++ b/core-java-modules/core-java-nio/src/test/java/com/baeldung/path/PathManualTest.java @@ -1,8 +1,6 @@ -package com.baeldung.java.nio2; +package com.baeldung.path; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import org.junit.Test; import java.io.IOException; import java.net.URI; @@ -10,7 +8,7 @@ import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.nio.file.Paths; -import org.junit.Test; +import static org.junit.Assert.*; public class PathManualTest { diff --git a/core-java-modules/core-java-nio/src/test/resources/.gitignore b/core-java-modules/core-java-nio/src/test/resources/.gitignore deleted file mode 100644 index 83c05e60c8..0000000000 --- a/core-java-modules/core-java-nio/src/test/resources/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -*.class - -#folders# -/target -/neoDb* -/data -/src/main/webapp/WEB-INF/classes -*/META-INF/* - -# Packaged files # -*.jar -*.war -*.ear \ No newline at end of file diff --git a/core-java-modules/core-java-nio/src/test/resources/file.txt b/core-java-modules/core-java-nio/src/test/resources/file.txt new file mode 100644 index 0000000000..558d8bbf35 --- /dev/null +++ b/core-java-modules/core-java-nio/src/test/resources/file.txt @@ -0,0 +1 @@ +baeldung.com \ No newline at end of file diff --git a/pom.xml b/pom.xml index 88aa7011d0..100158b4f3 100644 --- a/pom.xml +++ b/pom.xml @@ -424,6 +424,7 @@ core-java-modules/core-java-io core-java-modules/core-java-io-files core-java-modules/core-java-nio + core-java-modules/core-java-nio-2 core-java-modules/core-java-security core-java-modules/core-java-exceptions core-java-modules/core-java-lang-syntax @@ -1198,6 +1199,7 @@ core-java-modules/core-java-io core-java-modules/core-java-io-files core-java-modules/core-java-nio + core-java-modules/core-java-nio-2 core-java-modules/core-java-security core-java-modules/core-java-exceptions core-java-modules/core-java-lang-syntax