My idea was, like, to put read bytes to an array list. Then take the first element to memory variable, and then iterate through the whole array to count repeated times. And after iterating, when repeated counter has value 1. I wanted to assign value from variable "memory" to “not Repeated list”, and reset counter to take another element from the working list. But like you see, my first two element go well, and the third one go fail. It threw out an exception.
default: [49, 49, 51, 49, 49, 52, 49, 49]

external InMemory: 49(index 0)

internal loop: 49?49 is repeat 1
internal loop: 49?49 is repeat 2
internal loop: 49?49 is repeat 3
internal loop: 49?49 is repeat 4
internal loop: 49?49 is repeat 5
internal loop: 49?49 is repeat 6

external InMemory: 49(index 1)

internal loop: 49?49 is repeat 1
internal loop: 49?49 is repeat 2
internal loop: 49?49 is repeat 3
internal loop: 49?49 is repeat 4
internal loop: 49?49 is repeat 5
internal loop: 49?49 is repeat 6

external InMemory: 51(index 2)

internal loop: 51?51 is repeat 1
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 8, Size: 8
	at java.util.ArrayList.rangeCheck(ArrayList.java:657)
	at java.util.ArrayList.get(ArrayList.java:433)
	at pl.codegym.task.task18.task1804.Solution.main(Solution.java:56)

Process finished with exit code 1