From ef4b3173d9026f042f238c5db3c2d5c6332e7674 Mon Sep 17 00:00:00 2001 From: esoe Date: Sun, 18 Sep 2022 14:39:51 +0300 Subject: [PATCH] qq --- .editorconfig | 17 ++ pom.xml | 173 ++++++++++++++++++ src/main/java/ru/molokoin/ExchangeServer.java | 52 ++++++ src/test/java/ru/molokoin/AppTest.java | 18 ++ 4 files changed, 260 insertions(+) create mode 100644 .editorconfig create mode 100644 pom.xml create mode 100644 src/main/java/ru/molokoin/ExchangeServer.java create mode 100644 src/test/java/ru/molokoin/AppTest.java diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e1d0ce7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# Editor configuration, see http://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true +max_line_length = 80 + +[*.sh] +end_of_line = lf + +[*.java] +indent_size = 4 +max_line_length = 120 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..8053350 --- /dev/null +++ b/pom.xml @@ -0,0 +1,173 @@ + + 4.0.0 + ru.molokoin + exchange-server + 0.1 + + 1.8 + 1.8 + UTF-8 + 5.6.0 + 3.0.0-M3 + 3.1.2 + 8.39 + 3.0.0-M5 + 0.8.4 + 3.0.0 + + 0% + 0% + 20 + 5 + + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${maven-enforcer-plugin.version} + + + + enforce + + + + + 3.6.3 + + + true + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + + + com.puppycrawl.tools + checkstyle + ${checkstyle.version} + + + com.github.ngeor + checkstyle-rules + 4.8.0 + + + + com/github/ngeor/checkstyle.xml + true + ${skipTests} + + + + checkstyle + validate + + check + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + org.jacoco + jacoco-maven-plugin + ${jacoco-maven-plugin.version} + + + pre-unit-test + + prepare-agent + + + + post-unit-test + test + + report + + + + check-unit-test + test + + check + + + ${project.build.directory}/jacoco.exec + + + BUNDLE + + + INSTRUCTION + COVEREDRATIO + ${jacoco.unit-tests.limit.instruction-ratio} + + + BRANCH + COVEREDRATIO + ${jacoco.unit-tests.limit.branch-ratio} + + + + + CLASS + + + COMPLEXITY + TOTALCOUNT + ${jacoco.unit-tests.limit.class-complexity} + + + + + METHOD + + + COMPLEXITY + TOTALCOUNT + ${jacoco.unit-tests.limit.method-complexity} + + + + + + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + + + diff --git a/src/main/java/ru/molokoin/ExchangeServer.java b/src/main/java/ru/molokoin/ExchangeServer.java new file mode 100644 index 0000000..50e470b --- /dev/null +++ b/src/main/java/ru/molokoin/ExchangeServer.java @@ -0,0 +1,52 @@ +package ru.molokoin; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.ServerSocket; +import java.net.Socket; +import java.nio.charset.StandardCharsets; + +public class ExchangeServer { + + public static void main(String[] args) { + try (ServerSocket serverSocket = new ServerSocket(8181)) { + System.out.println("Server started!"); + + while (true) { + // ожидаем подключения + Socket socket = serverSocket.accept(); + System.out.println("Client connected!"); + + // для подключившегося клиента открываем потоки + // чтения и записи + try (BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8)); + PrintWriter output = new PrintWriter(socket.getOutputStream())) { + + // ждем первой строки запроса + while (!input.ready()) ; + + // считываем и печатаем все что было отправлено клиентом + System.out.println(); + while (input.ready()) { + System.out.println(input.readLine()); + } + + // отправляем ответ + output.println("HTTP/1.1 200 OK"); + output.println("Content-Type: text/html; charset=utf-8"); + output.println(); + output.println("

hello-exchange!

"); + output.flush(); + + // по окончанию выполнения блока try-with-resources потоки, + // а вместе с ними и соединение будут закрыты + System.out.println("Client disconnected!"); + } + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } +} diff --git a/src/test/java/ru/molokoin/AppTest.java b/src/test/java/ru/molokoin/AppTest.java new file mode 100644 index 0000000..5d9a122 --- /dev/null +++ b/src/test/java/ru/molokoin/AppTest.java @@ -0,0 +1,18 @@ +package ru.molokoin; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Unit test for simple App. + */ +class AppTest { + /** + * Rigorous Test. + */ + @Test + void testApp() { + assertEquals(1, 1); + } +}