<commit_before>package com.intellij.xml.actions.xmlbeans;


import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NonNls;

import java.io.*;

/**
 * @author <NAME>
 */
public class FileUtils {
  @NonNls
  public static final String CLASS_RESOURCE_STRING = "*?.class";
  @NonNls
  private static final String SOAP_ADDRESS = "soap:address";

  private FileUtils() {
  }

  public static File saveStreamContentAsFile(String fullFileName, InputStream stream) throws IOException {
    fullFileName = findFreeFileName(fullFileName);
    OutputStream ostream = new FileOutputStream(fullFileName);
    byte[] buf = new byte[8192];

    while(true) {
      int read = stream.read(buf,0,buf.length);
      if (read == -1) break;
      ostream.write(buf,0,read);
    }
    ostream.flush();
    ostream.close();
    return new File(fullFileName);
  }

  private static String findFreeFileName(String filename) {
    File f = new File(filename);
    if (! f.exists()) return filename;
    int dot = filename.lastIndexOf('.'); // we believe file has some ext. For instance,  ".wsdl"
    String name = filename.substring(0, dot);
    String ext = filename.substring(dot);
    int num = 0;
    do {
      f = new File(name + ++num + ext);
    } while (f.exists());
    return name + num + ext;
  }


  public static void saveText(VirtualFile virtualFile, String text) throws IOException {
    OutputStream outputStream = virtualFile.getOutputStream(virtualFile);
    FileUtil.copy(new ByteArrayInputStream(text.getBytes(virtualFile.getCharset().name())), outputStream);
    outputStream.close();
  }

  public static boolean copyFile(File in, File out) {
    try {
      FileInputStream fis = new FileInputStream(in);
      FileOutputStream fos = new FileOutputStream(out);
      byte[] buf = new byte[1024];
      int i;
      while ((i = fis.read(buf)) != -1) {
        fos.write(buf, 0, i);
      }
      fis.close();
      fos.close();
      return true;
    } catch (Exception e) {
      return false;<commit_msg>close streams in finally blocks<commit_after>package com.intellij.xml.actions.xmlbeans;


import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NonNls;

import java.io.*;

/**
 * @author <NAME>
 */
public class FileUtils {
  @NonNls
  public static final String CLASS_RESOURCE_STRING = "*?.class";
  @NonNls
  private static final String SOAP_ADDRESS = "soap:address";

  private FileUtils() {
  }

  public static File saveStreamContentAsFile(String fullFileName, InputStream stream) throws IOException {
    fullFileName = findFreeFileName(fullFileName);
    OutputStream ostream = new FileOutputStream(fullFileName);
    byte[] buf = new byte[8192];

    while(true) {
      int read = stream.read(buf,0,buf.length);
      if (read == -1) break;
      ostream.write(buf,0,read);
    }
    ostream.flush();
    ostream.close();
    return new File(fullFileName);
  }

  private static String findFreeFileName(String filename) {
    File f = new File(filename);
    if (! f.exists()) return filename;
    int dot = filename.lastIndexOf('.'); // we believe file has some ext. For instance,  ".wsdl"
    String name = filename.substring(0, dot);
    String ext = filename.substring(dot);
    int num = 0;
    do {
      f = new File(name + ++num + ext);
    } while (f.exists());
    return name + num + ext;
  }


  public static void saveText(VirtualFile virtualFile, String text) throws IOException {
    OutputStream outputStream = virtualFile.getOutputStream(virtualFile);
    try {
      FileUtil.copy(new ByteArrayInputStream(text.getBytes(virtualFile.getCharset().name())), outputStream);
    }
    finally {
      outputStream.close();
    }
  }

  public static boolean copyFile(File in, File out) {
    try {
      FileInputStream fis = new FileInputStream(in);
      FileOutputStream fos = new FileOutputStream(out);
      byte[] buf = new byte[1024];
      int i;
      while ((i = fis.read(buf)) != -1) {
        fos.write(buf, 0, i);
      }
      fis.close();
      fos.close();
      return true;
    } catch (Exception e) {
      return false;
{'fraction_non_alphanumeric': 0.12184673964778676, 'fraction_numerical': 0.007139457401237506, 'mean_word_length': 3.249747219413549, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '5711170', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1252, 'n_words': 335}