private static void compressStream(Map<Byte, byte[]> dictionary,
                                       OutputStream outs) throws IOException {
        int current_pos = 0;
        byte[] byteStream = new byte[dictionary.size()*2];
        boolean patternExistTwice = false;
        for (Byte key : dictionary.keySet()) {
            patternExistTwice =
                    doesPatternExistTwice(dictionary, dictionary.get(key));

            // If the pattern already exists twice in the dictionary then it is
            // definitely the end of the dictionary
            if (patternExistTwice && key == dictionary.size()) {
                if (dictionary.get(key).length == 1) {
                    byteStream[current_pos] = 0;
                    current_pos++;
                } else {
                    int realKey =
                            getKeyOfSubstring(dictionary, dictionary.get(key));
                    byteStream[current_pos] = (byte) realKey;
                    current_pos++;
                }
                byteStream[current_pos] = Util.getLastByte(dictionary.get(key));
                current_pos++;
                break;
            }

            // Write Node number following by last byte of the corresponding
            // value.
            else {
                if (dictionary.get(key).length == 1) {
                    byteStream[current_pos] = 0;
                    current_pos++;
                } else {
                    int realKey =
                            getKeyOfSubstring(dictionary, dictionary.get(key));
                    byteStream[current_pos] = (byte) realKey;
                    current_pos++;
                }
                byteStream[current_pos] = Util.getLastByte(dictionary.get(key));
                current_pos++;
            }
        }

        outs.write(byteStream);
    }