@@ -0,0 +1,1964 @@
+package com.samhg.authentication.persistence.counter;%0A%0Aimport java.io.IOException;%0Aimport java.nio.ByteBuffer;%0Aimport java.nio.channels.AsynchronousFileChannel;%0Aimport java.nio.file.Path;%0Aimport java.util.Arrays;%0Aimport java.util.Map;%0Aimport java.util.stream.Collectors;%0Aimport java.util.stream.Stream;%0A%0Aimport static java.nio.file.StandardOpenOption.*;%0A%0Apublic final class TextFileCounterPersistence implements CounterPersistenceStrategy %7B%0A%0A    private final Path path;%0A%0A    public TextFileCounterPersistence(Path path) %7B%0A        this.path = path;%0A    %7D%0A%0A    @Override%0A    public Long persist(CounterUpdate counterUpdate) %7B%0A        try (AsynchronousFileChannel channel = AsynchronousFileChannel.open(path, READ, WRITE)) %7B%0A%0A            int fileSize = (int) channel.size();%0A            ByteBuffer readBuffer = ByteBuffer.allocate(fileSize);%0A            channel.read(readBuffer, 0);%0A%0A            String%5B%5D linesArray = new String(readBuffer.array()).split(%22%5Cn%22);%0A            Stream%3CString%3E lines = Arrays.stream(linesArray).parallel();%0A%0A            Map%3CString, String%3E entries = lines%0A                    .filter(l -%3E l.matches(%22%5C%5Cw+:%5C%5Cw+%22))%0A                    .map(l -%3E l.split(%22:%22))%0A                    .collect(Collectors.toMap(l -%3E l%5B0%5D, l -%3E l%5B1%5D));%0A%0A            entries.compute(counterUpdate.getRequest().getIdentifier(),%0A                    (k, v) -%3E Long.toString(counterUpdate.getNewCounter()));%0A%0A            String newFile = entries.entrySet()%0A                    .parallelStream()%0A                    .map(e -%3E e.getKey() + %22:%22 + e.getValue() + %22%5Cn%22)%0A                    .reduce(String::concat)%0A                    .orElseThrow();%0A%0A            ByteBuffer writeBuffer = ByteBuffer.wrap(newFile.getBytes());%0A            channel.write(writeBuffer, 0);%0A%0A            return counterUpdate.getNewCounter();%0A%0A        %7D catch (IOException e) %7B%0A            throw new RuntimeException(%22IO error occurred whilst accessing %22 + path.getFileName(), e);%0A        %7D%0A    %7D%0A%7D

Add naive counter persistence