Очередная война с валидатором... Помогите, пожалуйста, разобраться, почему валидатор выдаёт ошибку "Программа работала слишком долго и была закрыта!"?
package com.javarush.task.task18.task1803;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.StringJoiner;
public class Solution {
public static void main(String[] args) throws Exception {
File file = setFile();
byte[] fileBytes = setFileBytes(file);
HashMap<Byte, Integer> bytesOccurrence = new HashMap<>();
int count = 1;
for (Byte key : fileBytes) {
if (bytesOccurrence.containsKey(key)) {
int value = bytesOccurrence.get(key) + 1 ;
bytesOccurrence.put(key, value);
if (value > count) count = value;
} else {
bytesOccurrence.put(key, 1);
}
}
StringJoiner result = new StringJoiner(" ");
for (Map.Entry<Byte, Integer> entry : bytesOccurrence.entrySet()) {
if (entry.getValue() == count) result.add(entry.getKey().toString());
}
System.out.println(result);
}
private static File setFile() throws IOException{
File file;
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(System.in))) {
String fileName = reader.readLine();
file = new File(fileName);
}
return file;
}
private static byte[] setFileBytes(File file) throws IOException{
byte[] bytes = new byte[(int) file.length()];
try (FileInputStream fis = new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
int read;
while ((read = fis.read(bytes)) != -1) {
bos.write(bytes, 0, read);
}
}
return bytes;
}
}