-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathTask01Main.java
More file actions
33 lines (24 loc) · 934 Bytes
/
Task01Main.java
File metadata and controls
33 lines (24 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.example.task01;
import java.io.IOException;
import java.io.InputStream;
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 {
if (inputStream == null) {
throw new IllegalArgumentException();
}
int result = 0;
int b, c;
while ((b = inputStream.read()) != -1) {
c = Integer.rotateLeft(result, 1);
result = c ^ b;
}
return result;
}
}