From 95c1422857d0709c7b18ed96cdfed5905079c031 Mon Sep 17 00:00:00 2001 From: "Task-1.1" Date: Sun, 27 Dec 2020 09:22:42 +0500 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=207.?= =?UTF-8?q?1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/example/task01/Task01Main.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/07-java-io/task01/src/com/example/task01/Task01Main.java b/07-java-io/task01/src/com/example/task01/Task01Main.java index fcbd7c247..73fcd4d70 100644 --- a/07-java-io/task01/src/com/example/task01/Task01Main.java +++ b/07-java-io/task01/src/com/example/task01/Task01Main.java @@ -1,21 +1,32 @@ package com.example.task01; - import java.io.IOException; import java.io.InputStream; - -public class Task01Main { - public static void main(String[] args) throws IOException { +public class Task01Main +{ + public static void main(String[] args) throws IOException + { //здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат // например вот так: - /* System.out.println(checkSumOfStream(new ByteArrayInputStream(new byte[]{0x33, 0x45, 0x01}))); */ - } - public static int checkSumOfStream(InputStream inputStream) throws IOException { + public static int checkSumOfStream(InputStream inputStream) throws IOException + { // your implementation here return 0; + if (inputStream == null) + { + throw new IllegalArgumentException(); + } + int checkSum = 0; + int stream_byte = inputStream.read(); + while (stream_byte != -1) + { + checkSum = Integer.rotateLeft(checkSum, 1) ^ stream_byte; + stream_byte = inputStream.read(); + } + return checkSum; } -} +} \ No newline at end of file