<commit_before>/*
 * $Id$
 *
 * Copyright (c) 2007-2008 by <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License (LGPL) as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, copies are available 
 * at http://www.opensource.org.
 */
package VASSAL.tools.io;

import java.io.ByteArrayInputStream;
import java.io.BufferedInputStream;
import java.io.Closeable;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.zip.ZipFile;
import javax.imageio.stream.ImageInputStream;

import VASSAL.tools.logging.Logger;

/**
 * General I/O stream manipulation utilities. This class provides static
 * utility methods to reduce boilerplate I/O code.
 *
 * @author <NAME>
 * @since 3.1.0
 */ 
public class IOUtils {
  // Portions based on org.apache.commons.io.IOUtils.

  /** The default size for input buffers. */
  public static final int BUFFER_SIZE = 4096;

  /**
   * Copies bytes from an <code>InputStream</code> to an
   * <code>OutputStream</code> via a <code>byte</code> buffer. This
   * method buffers input internally, so the input stream should not
   * be a <code>BufferedInputStream</code>.
   *
   * @param in the source
   * @param out the destination
   * @param buffer the buffer
   * @throws IOException if one occurs while reading or writing.
   */
  public static void copy(InputStream in, OutputStream out, byte[] buffer)
      throws IOException {
    int n = 0;
    while ((n = in.read(buffer)) > 0) out.write(buffer, 0, n);
  }

  /**
   * Copies bytes from an <code>InputStream</code> to an
   * <code>OutputStream</code>. This method buffers input
   * internally, so the input stream should not be a
   * <code>BufferedInputStream</code>.
   *
   * @param in the source
   * @param out the destination
   * @throws IOException if one occurs while reading or writing.
   */
  public static void copy(InputStream in, OutputStream out)
      throws IOException {
    copy(in, out, new byte[BUFFER_SIZE]);
  }

  /**
   * Copies chars from a <code>Reader</code> to a <code>Writer</code>
   * via a <code>char</code> buffer. This method buffers input internally,
   * so the <code>Reader</code> should not be a <code>BufferedReader</code>.
   *
   * @param in the source 
   * @param out the destination
   * @param buffer the buffer
   * @throws IOException if one occurs while reading or writing.
   */
  public static void copy(Reader in, Writer out, char[] buffer)
      throws IOException {
    int n = 0;
    while ((n = in.read(buffer)) > 0) out.write(buffer, 0, n);
  }

  /**
   * Copies chars from a <code>Reader</code> to a <code>Writer</code>.
   * This method buffers input internally, so the <code>Reader</code>
   * should not be a <code>BufferedReader</code>.
   *
   * @param in the source 
   * @param out the destination
   * @throws IOException if one occurs while reading or writing.
   */
  public static void copy(Reader in, Writer out) throws IOException {<commit_msg>Bug: Don't stop copying until InputStream returns -1.<commit_after>/*
 * $Id$
 *
 * Copyright (c) 2007-2008 by <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License (LGPL) as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, copies are available 
 * at http://www.opensource.org.
 */
package VASSAL.tools.io;

import java.io.ByteArrayInputStream;
import java.io.BufferedInputStream;
import java.io.Closeable;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.zip.ZipFile;
import javax.imageio.stream.ImageInputStream;

import VASSAL.tools.logging.Logger;

/**
 * General I/O stream manipulation utilities. This class provides static
 * utility methods to reduce boilerplate I/O code.
 *
 * @author <NAME>
 * @since 3.1.0
 */ 
public class IOUtils {
  // Portions based on org.apache.commons.io.IOUtils.

  /** The default size for input buffers. */
  public static final int BUFFER_SIZE = 4096;

  /**
   * Copies bytes from an <code>InputStream</code> to an
   * <code>OutputStream</code> via a <code>byte</code> buffer. This
   * method buffers input internally, so the input stream should not
   * be a <code>BufferedInputStream</code>.
   *
   * @param in the source
   * @param out the destination
   * @param buffer the buffer
   * @throws IOException if one occurs while reading or writing.
   */
  public static void copy(InputStream in, OutputStream out, byte[] buffer)
      throws IOException {
    int n = 0;
    while ((n = in.read(buffer)) != 0) out.write(buffer, 0, n);
  }

  /**
   * Copies bytes from an <code>InputStream</code> to an
   * <code>OutputStream</code>. This method buffers input
   * internally, so the input stream should not be a
   * <code>BufferedInputStream</code>.
   *
   * @param in the source
   * @param out the destination
   * @throws IOException if one occurs while reading or writing.
   */
  public static void copy(InputStream in, OutputStream out)
      throws IOException {
    copy(in, out, new byte[BUFFER_SIZE]);
  }

  /**
   * Copies chars from a <code>Reader</code> to a <code>Writer</code>
   * via a <code>char</code> buffer. This method buffers input internally,
   * so the <code>Reader</code> should not be a <code>BufferedReader</code>.
   *
   * @param in the source 
   * @param out the destination
   * @param buffer the buffer
   * @throws IOException if one occurs while reading or writing.
   */
  public static void copy(Reader in, Writer out, char[] buffer)
      throws IOException {
    int n = 0;
    while ((n = in.read(buffer)) != 0) out.write(buffer, 0, n);
  }

  /**
   * Copies chars from a <code>Reader</code> to a <code>Writer</code>.
   * This method buffers input internally, so the <code>Reader</code>
   * should not be a <code>BufferedReader</code>.
   *
   * @param in the source 
   * @param out the destination
   * @throws IOException if one occurs while reading or writing.
   */
  public static void copy(Reader in, Writer out) throws IOException {
{'fraction_non_alphanumeric': 0.10140534582529623, 'fraction_numerical': 0.005924497106640948, 'mean_word_length': 3.4864029666254637, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3496286', 'n_tokens_mistral': 2129, 'n_tokens_neox': 2061, 'n_words': 821}