public void save(OutputStream os) throws IOException {
        os.write(("# NgramProfile generated at " + new Date() +
                " for Apache Tika Language Identification\n").getBytes(UTF_8));

        // And then each ngram

        // First dispatch ngrams in many lists depending on their size
        // (one list for each size, in order to store MAX_SIZE ngrams for each
        // size of ngram)
        List<NGramEntry> list = new ArrayList<>();
        List<NGramEntry> sublist = new ArrayList<>();
        NGramEntry[] entries = ngrams.values().toArray(new NGramEntry[0]);
        for (int i = minLength; i <= maxLength; i++) {
            for (NGramEntry entry : entries) {
                if (entry.getSeq().length() == i) {
                    sublist.add(entry);
                }
            }
            Collections.sort(sublist);
            if (sublist.size() > MAX_SIZE) {
                sublist = sublist.subList(0, MAX_SIZE);
            }
            list.addAll(sublist);
            sublist.clear();
        }
        for (NGramEntry e : list) {
            String line = e.toString() + " " + e.getCount() + "\n";
            os.write(line.getBytes(UTF_8));
        }
        os.flush();
    }
Writes NGramProfile content into OutputStream, content is outputted with
UTF-8 encoding

@param os the Stream to output to
@throws IOException
tika-langdetect/tika-langdetect-tika/src/main/java/org/apache/tika/langdetect/tika/LanguageProfilerBuilder.java