public static void compress(InputStream fins, OutputStream outs) {
        int value = 1;
        byte[] pattern = new byte[0];
        byte[] byteArray = new byte[8192];
        boolean isEmpty = true;
        Map<Byte, byte[]> dictionary = new TreeMap<>();
        boolean patternAlreadyExist;
        int numberOfBytesRead;

        try {
            // While the end of file is not reached.
            while ((numberOfBytesRead = fins.read(byteArray)) != -1) {
                for (int i = 0; i < numberOfBytesRead; i++) {
                    //Compress the stream if the dictionary size exceeds 127,
                    // and construct a new dictionary
                    if (dictionary.size() == Byte.MAX_VALUE) {
                        if (!isEmpty) {
                            dictionary.put((byte) value, pattern);
                        }
                        compressStream(dictionary, outs);
                        dictionary.clear();
                        value = 1;
                    }

                    // Read pattern corresponding to an array of bytes.
                    byte[] temp = Util.mergeBytes(pattern, byteArray[i]);
                    pattern = temp;
                    patternAlreadyExist = doesPatternExist(dictionary, pattern);

                    // Add the pattern to the dictionary if its doesn't exist.
                    if (!patternAlreadyExist) {
                        dictionary.put((byte) value, pattern.clone());
                        value++;
                        pattern = new byte[0];
                        isEmpty = true;

                    // If it already exists, read the next byte in the IS
                    } else {
                        isEmpty = false;
                        continue;
                    }
                }
            }

            // Insert the pattern in the dictionary if the end of the file is
            // reached and the pattern already exist.
            if (!isEmpty) {
                dictionary.put((byte) value, pattern.clone());
            }
            compressStream(dictionary, outs);
            outs.close();
        } catch (IOException e) {
            System.err.println("An error happened while decompressing.");
        }
    }