<commit_before>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.testFramework;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;

public class TempFiles {
  private final Collection<File> myFilesToDelete;

  public TempFiles(Collection<File> filesToDelete) {
    myFilesToDelete = filesToDelete;
  }

  public VirtualFile createVFile(String prefix) throws IOException {
    return getVFileByFile(createTempFile(prefix));
  }

  public VirtualFile createVFile(String prefix, String postfix) throws IOException {
    return getVFileByFile(createTempFile(prefix, postfix));
  }

  public File createTempFile(String prefix) throws IOException {
    return createTempFile(prefix, "_Temp_File_");
  }

  public File createTempFile(String prefix, String postfix) throws IOException {
    File tempFile = FileUtil.createTempFile(prefix, postfix);
    tempFileCreated(tempFile);
    return tempFile;
  }

  private void tempFileCreated(File tempFile) {
    myFilesToDelete.add(tempFile);
    tempFile.deleteOnExit();
  }

  public static VirtualFile getVFileByFile(File tempFile) {
    refreshVfs();
    return LocalFileSystem.getInstance().findFileByIoFile(tempFile);
  }

  public static void refreshVfs() {
    ApplicationManager.getApplication().runWriteAction(new Runnable() {
      @Override
      public void run() {
        VirtualFileManager.getInstance().refresh(false);
      }
    });
  }

  public File createTempDir() throws IOException {
    return createTempDir("dir");
  }

  private File createTempDir(String prefix) throws IOException {
    File dir = FileUtil.createTempDirectory(prefix, "test");
    tempFileCreated(dir);
    return dir;
  }

  public VirtualFile createTempVDir() throws IOException {
    return createTempVDir("dir");
  }

  public VirtualFile createTempVDir(String prefix) throws IOException {
    return getVFileByFile(createTempDir(prefix));
  }

  public File createTempSubDir(File content) {
    File subDir = new File(content, "source");
    if (!subDir.mkdir()) throw new RuntimeException(subDir.toString());
    tempFileCreated(subDir);
    return subDir;
  }

  public String createTempPath() throws IOException {
    File tempFile = createTempFile("xxx");
    String absolutePath = tempFile.getAbsolutePath();
    tempFile.delete();
    return absolutePath;
  }

  public void deleteAll() {
    for (Iterator<File> iterator = myFilesToDelete.iterator(); iterator.hasNext();) {
      File file = iterator.next();
      file.delete();
    }
  }

  public VirtualFile createVFile(VirtualFile parentDir, String name, String text) throws IOException {
    final VirtualFile virtualFile = parentDir.createChildData(this, name);
    VfsUtil.saveText(virtualFile, text + "\n");
    return virtualFile;
  }
}
<commit_msg>IOException wrapped with RuntimeException for tests<commit_after>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.testFramework;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;

import java.io.File;
import java.io.IOException;
import java.util.Collection;

public class TempFiles {
  private final Collection<File> myFilesToDelete;

  public TempFiles(Collection<File> filesToDelete) {
    myFilesToDelete = filesToDelete;
  }

  public VirtualFile createVFile(String prefix) {
    return getVFileByFile(createTempFile(prefix));
  }

  public VirtualFile createVFile(String prefix, String postfix) {
    return getVFileByFile(createTempFile(prefix, postfix));
  }

  public File createTempFile(String prefix) {
    return createTempFile(prefix, "_Temp_File_");
  }

  public File createTempFile(String prefix, String postfix) {
    try {
      File tempFile = FileUtil.createTempFile(prefix, postfix);
      tempFileCreated(tempFile);
      return tempFile;
    }
    catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  private void tempFileCreated(File tempFile) {
    myFilesToDelete.add(tempFile);
    tempFile.deleteOnExit();
  }

  public static VirtualFile getVFileByFile(File tempFile) {
    refreshVfs();
    return LocalFileSystem.getInstance().findFileByIoFile(tempFile);
  }

  public static void refreshVfs() {
    ApplicationManager.getApplication().runWriteAction(new Runnable() {
      @Override
      public void run() {
        VirtualFileManager.getInstance().refresh(false);
      }
    });
  }

  public File createTempDir() {
    return createTempDir("dir");
  }

  private File createTempDir(String prefix) {
    try {
      File dir = FileUtil.createTempDirectory(prefix, "test");
      tempFileCreated(dir);
      return dir;
    }
    catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  public VirtualFile createTempVDir() {
    return createTempVDir("dir");
  }

  public VirtualFile createTempVDir(String prefix) {
    return getVFileByFile(createTempDir(prefix));
  }

  public File createTempSubDir(File content) {
    File subDir = new File(content, "source");
    if (!subDir.mkdir()) throw new RuntimeException(subDir.toString());
    tempFileCreated(subDir);
    return subDir;
  }

  public String createTempPath() {
    File tempFile = createTempFile("xxx");
    String absolutePath = tempFile.getAbsolutePath();
    tempFile.delete();
    return absolutePath;
  }

  public void deleteAll() {
    for (File file : myFilesToDelete) {
      FileUtil.delete(file);
    }
  }

  public VirtualFile createVFile(VirtualFile parentDir, String name, String text) {
    try {
      final VirtualFile virtualFile = parentDir.createChildData(this, name);
      VfsUtil.saveText(virtualFile, text + "\n");
      return virtualFile;
    }
    catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
}

{'fraction_non_alphanumeric': 0.0947539650264335, 'fraction_numerical': 0.0032533550223668157, 'mean_word_length': 4.0638297872340425, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '6203336', 'n_tokens_mistral': 2143, 'n_tokens_neox': 2090, 'n_words': 566}