<commit_before>/*
 * Copyright (c) 2016 <NAME>. All rights reserved.
 *
 * The use and distribution terms for this software are covered by the
 * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
 * which can be found in the file LICENSE at the root of this distribution.
 *
 * By using this software in any fashion, you are agreeing to be bound by
 * the terms of this license.
 *
 * You must not remove this notice, or any other, from this software.
 */
package com.hypirion.bencode;

import java.io.*;
import java.util.*;

/**
 * A BencodeWriter writes Bencoded values into an {@link OutputStream}.
 *
 * @since 0.1.0
 */
public final class BencodeWriter implements Closeable {
    private OutputStream out;

    /**
     * Creates a new <code>BencodeWriter</code> out of <code>out</code>.
     *
     * @since 0.1.0
     * @param out the <code>OutputStream</code> to write to
     */
    public BencodeWriter(OutputStream out) {
        this.out = out;
    }

    /**
     * Closes the underlying <code>OutputStream</code>.
     *
     * @exception IOException if an IO exception occurs when closing
     */
    public void close() throws IOException {
        out.close();
    }

    /**
     * Writes a bencoded string to the <code>OutputStream</code>.
     *
     * @exception NullPointerException if <code>s</code> is <code>null</code>
     * @exception IOException if an IO exception occurs when writing
     */
    public void writeString(String s) throws IOException {
        byte[] bs = s.getBytes("UTF-8");
        byte[] bsLen = new Integer(bs.length).toString().getBytes("UTF-8");
        out.write(bsLen);
        out.write(':');<commit_msg>Add flushing for bencode writer<commit_after>/*
 * Copyright (c) 2016 <NAME>. All rights reserved.
 *
 * The use and distribution terms for this software are covered by the
 * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
 * which can be found in the file LICENSE at the root of this distribution.
 *
 * By using this software in any fashion, you are agreeing to be bound by
 * the terms of this license.
 *
 * You must not remove this notice, or any other, from this software.
 */
package com.hypirion.bencode;

import java.io.*;
import java.util.*;

/**
 * A BencodeWriter writes Bencoded values into an {@link OutputStream}.
 *
 * @since 0.1.0
 */
public final class BencodeWriter implements Closeable, Flushable {
    private OutputStream out;

    /**
     * Creates a new <code>BencodeWriter</code> out of <code>out</code>.
     *
     * @since 0.1.0
     * @param out the <code>OutputStream</code> to write to
     */
    public BencodeWriter(OutputStream out) {
        this.out = out;
    }

    /**
     * Closes the underlying <code>OutputStream</code>.
     *
     * @exception IOException if an IO exception occurs when closing
     */
    public void close() throws IOException {
        out.close();
    }

    /**
     * Flushes the underlying <code>OutputStream</code>.
     *
     * @exception IOException if an IO exception occurs when flushing
     */
    public void flush() throws IOException {
        out.flush();
    }

    /**
     * Writes a bencoded string to the <code>OutputStream</code>.
     *
     * @exception NullPointerException if <code>s</code> is <code>null</code>
     * @exception IOException if an IO exception occurs when writing
     */
    public void writeString(String s) throws IOException {
        byte[] bs = s.getBytes("UTF-8");
        byte[] bsLen = new Integer(bs.length).toString().getBytes("UTF-8");
        out.write(bsLen);
        out.write(':');
{'fraction_non_alphanumeric': 0.1143646408839779, 'fraction_numerical': 0.008839779005524863, 'mean_word_length': 2.7562240663900415, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7649205', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1011, 'n_words': 369}