@Override
    protected BitSet processHeader(BitSet bits){
        BitSet headerBits = new BitSet();
        int offset = 0;
        if (!symbols_sorted.isEmpty()){
             Iterator<Entry<BitSet, Integer>> it = symbols_sorted.entrySet().iterator(); 
             long maxSize = it.next().getValue();
             long maxValue = 1;
             int bitCount;
             for (bitCount = 1; bitCount <= 32; bitCount++){
                 maxValue *= 2;
                 if (maxSize < maxValue){
                     break;
                 }
             } 
             toBitSetLen(headerBits, bitCount, 0, 6);
             offset += 6; 
             
             toBitSetLen(headerBits, symbSize, offset, 5);
             offset += 5; 
             it = symbols_sorted.entrySet().iterator();
             int freq;
             BitSet symb;
             Entry<BitSet, Integer> pairs;
             while (it.hasNext()) {
                   pairs = it.next();
                   freq = pairs.getValue();
                   symb = pairs.getKey();
                   
                toBitSetLen(headerBits, freq, offset, bitCount);
                offset += bitCount;
                
                
                for (int i = 0; i < symbSize; i++){
                     headerBits.set(i + offset, symb.get(i));  
                }
                offset += symbSize;
              }
             freq = 0;//end of header
             toBitSetLen(headerBits, freq, offset, bitCount);
             offset += bitCount;
        }
        
        int size;
        if ((offset % 8) != 0){
            size = offset/8 + 1;
        }
        else{
            size = offset/8;
        }
        byte byteArray[] = new byte[size];
        byteArray = Arrays.copyOf(headerBits.toByteArray(), size);
        fileM.fileOutputBuffered(byteArray);
        if (size < 1024*5)
            System.out.println("Header Size is " + size + " bytes");
        else
            System.out.println("Header Size is " + size/1024 + " KB");
        header = false;
        return null;
    }