<commit_before>/*
 *                      Nividic development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the microarray platform
 * of the cole Normale Suprieure and the individual authors.
 * These should be listed in @author doc comments.
 *
 * For more information on the Nividic project and its aims,
 * or to join the Nividic mailing list, visit the home page
 * at:
 *
 *      http://www.transcriptome.ens.fr/nividic
 *
 */

package fr.ens.transcriptome.nividic.om.io;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Iterator;

import fr.ens.transcriptome.nividic.NividicRuntimeException;
import fr.ens.transcriptome.nividic.om.BiologicalList;

public class SimpleBiologicalListWriter implements BiologicalListWriter {

  private OutputStream os;

  /**
   * Write the Biological List.
   * @param list Biological List to write
   */
  public void write(final BiologicalList list) {

    if (this.os == null)
      throw new NividicRuntimeException("The stream to read is null");

    final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
        this.os));

    Iterator it = list.iterator();

    try {

      while (it.hasNext())
        out.write(it.next() + "\n");

    } catch (IOException e) {
      throw new NividicRuntimeException("Error while writing the stream");
    }

  }

  //
  // Constructors
  //

  /**
   * Public constructor.
   * @param os InputStream to write
   */
  public SimpleBiologicalListWriter(final OutputStream os) {
    this.os = os;
  }

  /**
   * Public constructor.
   * @param file File to write
   * @throws FileNotFoundException if an error occurs while creating the stream
   */
  public SimpleBiologicalListWriter(final File file)
      throws FileNotFoundException {

    this(new FileOutputStream(file));
  }

  /**<commit_msg>Fix: Now close stream at the end of the write() method in SimpleBiologicalListWriter<commit_after>/*
 *                      Nividic development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the microarray platform
 * of the cole Normale Suprieure and the individual authors.
 * These should be listed in @author doc comments.
 *
 * For more information on the Nividic project and its aims,
 * or to join the Nividic mailing list, visit the home page
 * at:
 *
 *      http://www.transcriptome.ens.fr/nividic
 *
 */

package fr.ens.transcriptome.nividic.om.io;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Iterator;

import fr.ens.transcriptome.nividic.NividicRuntimeException;
import fr.ens.transcriptome.nividic.om.BiologicalList;

public class SimpleBiologicalListWriter implements BiologicalListWriter {

  private OutputStream os;

  /**
   * Write the Biological List.
   * @param list Biological List to write
   */
  public void write(final BiologicalList list) {

    if (this.os == null)
      throw new NividicRuntimeException("The stream to read is null");

    final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
        this.os));

    Iterator it = list.iterator();

    try {

      while (it.hasNext())
        out.write(it.next() + "\n");

      out.close();

    } catch (IOException e) {
      throw new NividicRuntimeException("Error while writing the stream");
    }

  }

  //
  // Constructors
  //

  /**
   * Public constructor.
   * @param os InputStream to write
   */
  public SimpleBiologicalListWriter(final OutputStream os) {
    this.os = os;
  }

  /**
   * Public constructor.
   * @param file File to write
   * @throws FileNotFoundException if an error occurs while creating the stream
   */
  public SimpleBiologicalListWriter(final File file)
      throws FileNotFoundException {

    this(new FileOutputStream(file));
  }

  /**
{'fraction_non_alphanumeric': 0.08947713848173267, 'fraction_numerical': 0.0, 'mean_word_length': 3.1868131868131866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3113157', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1274, 'n_words': 431}