@@ -0,0 +1,2746 @@
+package frequencyanalyzer;%0A%0Aimport java.io.BufferedInputStream;%0Aimport java.io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.InputStream;%0Aimport java.io.IOException;%0Aimport java.io.PrintStream;%0Aimport java.util.Arrays;%0Aimport java.util.TreeMap;%0Aimport java.util.Iterator;%0A%0Apublic class Analyzer%0A%7B%0A  private int bufferSize;%0A  private long maxValue;%0A  private long minValue;%0A  private TreeMap%3CByte, Long%3E table = new TreeMap%3CByte, Long%3E();%0A%0A  public Analyzer(InputStream in, int bufferSize) throws IOException%0A  %7B%0A    this.bufferSize = bufferSize;%0A    analyze(in);%0A    setMaxAndMinValues();%0A  %7D%0A%0A  public Analyzer(InputStream in) throws IOException%0A  %7B%0A    this(in, 10240);%0A  %7D%0A%0A  private void analyze(InputStream in) throws IOException%0A  %7B%0A    byte%5B%5D buffer = new byte%5BbufferSize%5D;%0A%0A    int bytesRead = in.read(buffer);%0A    for (int i = 0; i %3C bytesRead; i++)%0A    %7B%0A      long currentValue = 1;%0A%0A      if (table.containsKey(buffer%5Bi%5D))%0A        currentValue = table.get(buffer%5Bi%5D) + 1;%0A%0A      table.put(buffer%5Bi%5D, currentValue);%0A    %7D%0A  %7D%0A%0A  private String createStringLine(int length)%0A  %7B%0A    StringBuilder line = new StringBuilder(length);%0A    for (int i = 0; i %3C length; i++)%0A      line.append(%22#%22);      %0A%0A    return line.toString();%0A  %7D%0A%0A  private void setMaxAndMinValues()%0A  %7B%0A    Long%5B%5D values = new Long%5Btable.size()%5D;%0A    table.values().toArray(values);%0A    %0A    Arrays.sort(values);%0A%0A    minValue = values%5B0%5D;%0A    maxValue = values%5Btable.size() - 1%5D;%0A  %7D%0A%0A  public long getMaxValue()%0A  %7B%0A    return maxValue;%0A  %7D%0A%0A  public long getMinValue()%0A  %7B%0A    return minValue;%0A  %7D%0A%0A  public void printAnalysis(PrintStream out, int maxLength) throws IOException%0A  %7B%0A    String line = createStringLine(maxLength);%0A%0A    Iterator%3CByte%3E keys = table.keySet().iterator();%0A    while (keys.hasNext())%0A    %7B%0A      byte key = keys.next();%0A      long value = table.get(key);%0A      int length = (int)(((double)value / (double)maxValue) * (double)maxLength);%0A%0A      out.printf(%22%5B%25x%5D %25c: %25s (%25d)%5Cn%22, key, key, line.substring(0, length), value);%0A    %7D%0A  %7D%0A%0A  public static void main(String%5B%5D args)%0A  %7B%0A    if (args.length %3E 0)%0A    %7B%0A      try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File(args%5B0%5D))))%0A      %7B%0A        Analyzer analyzer = new Analyzer(in); %0A        %0A        System.out.printf(%22Max value: %25d%5CnMin value: %25d%5Cn%22, analyzer.getMaxValue(),%0A                                                            analyzer.getMinValue());%0A%0A        int length = 20;%0A        if (args.length %3E 1)%0A          length = Integer.parseInt(args%5B1%5D);%0A%0A        analyzer.printAnalysis(System.out, length);%0A      %7D%0A      catch (Exception e)%0A      %7B%0A        System.err.println(e.getMessage());%0A        e.printStackTrace();%0A      %7D%0A    %7D%0A  %7D%0A%7D%0A

Implement a frequency analyzer