<commit_before>package org.literacybridge.acm.io;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.channels.FileChannel;
import java.util.List;

import android.util.Pair;

public class DiskUtils {

  public final static String TBMountDirectory = "/data/media/0/usbStorage/sda1";
  private final static String TBDevDirectory = "/dev/block/sda1";

  /**
   * Performs an "rsync", which means that this method will try to copy the
   * current state of source to the target by making the least amount of
   * IOOperations.
   * 
   * @param source
   *          The source folder on the Phone's/Tablet's local storage.
   * @param targetPath
   *          Relative path on the connected external USB device.
   */
  public static void rsync(File source, String targetPath) throws IOException {

  }

  private static void copy(List<Pair<File, File>> filesToCopy)
      throws IOException {
    for (Pair<File, File> file : filesToCopy) {
      copy(file.first, file.second);
    }
  }

  public static void copy(File from, File to) throws IOException {
    if (from.isDirectory()) {
      if (!to.exists()) {
        to.mkdirs();
      }
      
      File[] subFiles = from.listFiles();
      for (File f : subFiles) {
        copy(f, new File(to, f.getName()));
      }
    } else {
      
      if (to.exists()) {
        if (to.length() == from.length()
            && to.lastModified() == from.lastModified()) {
          // avoid copying - files are identical
          return;
        }
  
        to.delete();
      }
  
      if (!to.exists()) {
        to.createNewFile();
      }
  
      FileChannel source = null;
      FileChannel destination = null;
  
      try {
        source = new FileInputStream(to).getChannel();
        destination = new FileOutputStream(from).getChannel();
        destination.transferFrom(source, 0, source.size());
      } finally {
        if (source != null) {
          source.close();
        }
        if (destination != null) {
          destination.close();
        }
      }
    }
  }

  public static void formatDevice() throws IOException {
    runAsRoot("mkdir" + TBMountDirectory, "/system/bin/umount "
        + TBMountDirectory, "/system/xbin/mkfs.vfat -v " + TBDevDirectory,
        "/system/bin/mount -t vfat -o rw " + TBDevDirectory + " "
            + TBMountDirectory);

  }

  public static boolean checkDisk(boolean repair) throws IOException {
    // TODO: use repair flag
    return runAsRoot("/system/bin/fsck.exfat -R " + TBDevDirectory);
  }

  public static void unmount() throws IOException {

    runAsRoot("/system/bin/umount " + TBMountDirectory);

  }

  public static boolean runAsRoot(String... cmds) throws IOException {
    Process p = Runtime.getRuntime().exec("su");
    DataOutputStream os = new DataOutputStream(p.getOutputStream());
    for (String tmpCmd : cmds) {
      os.writeBytes(tmpCmd + "\n");
    }
    os.writeBytes("exit\n");
    os.flush();
    try {
      return p.waitFor() == 0;
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new IOException(e);
    }
  }

  static void consumeProcessOutput(Process proc, boolean listenToStdErr)
      throws IOException {
    InputStream stderr = listenToStdErr ? proc.getErrorStream() : proc
        .getInputStream();
    InputStreamReader isr = new InputStreamReader(stderr);
    BufferedReader br = new BufferedReader(isr);
    String line = null;

    while ((line = br.readLine()) != null)
      ;
  }

}
<commit_msg>Update checkdisk for Nexus7<commit_after>package org.literacybridge.acm.io;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.channels.FileChannel;
import java.util.List;

import android.util.Pair;

public class DiskUtils {

  public final static String TBMountDirectory = "/data/media/0/usbStorage/sda1";
  private final static String TBDevDirectory = "/dev/block/sda1";

  /**
   * Performs an "rsync", which means that this method will try to copy the
   * current state of source to the target by making the least amount of
   * IOOperations.
   * 
   * @param source
   *          The source folder on the Phone's/Tablet's local storage.
   * @param targetPath
   *          Relative path on the connected external USB device.
   */
  public static void rsync(File source, String targetPath) throws IOException {

  }

  private static void copy(List<Pair<File, File>> filesToCopy)
      throws IOException {
    for (Pair<File, File> file : filesToCopy) {
      copy(file.first, file.second);
    }
  }

  public static void copy(File from, File to) throws IOException {
    if (from.isDirectory()) {
      if (!to.exists()) {
        to.mkdirs();
      }
      
      File[] subFiles = from.listFiles();
      for (File f : subFiles) {
        copy(f, new File(to, f.getName()));
      }
    } else {
      
      if (to.exists()) {
        if (to.length() == from.length()
            && to.lastModified() == from.lastModified()) {
          // avoid copying - files are identical
          return;
        }
  
        to.delete();
      }
  
      if (!to.exists()) {
        to.createNewFile();
      }
  
      FileChannel source = null;
      FileChannel destination = null;
  
      try {
        source = new FileInputStream(to).getChannel();
        destination = new FileOutputStream(from).getChannel();
        destination.transferFrom(source, 0, source.size());
      } finally {
        if (source != null) {
          source.close();
        }
        if (destination != null) {
          destination.close();
        }
      }
    }
  }

  public static void formatDevice() throws IOException {
    runAsRoot("mkdir" + TBMountDirectory, "/system/bin/umount "
        + TBMountDirectory, "/system/xbin/mkfs.vfat -v " + TBDevDirectory,
        "/system/bin/mount -t vfat -o rw " + TBDevDirectory + " "
            + TBMountDirectory);

  }

  public static boolean checkDisk(boolean repair) throws IOException {
    String repairParam = "n";
    if (repair == true){
      repairParam = "y";
    }
    return runAsRoot("/system/bin/fsck_msdos -" + repairParam + " " + TBDevDirectory);
  }

  public static void unmount() throws IOException {

    runAsRoot("/system/bin/umount " + TBMountDirectory);

  }

  public static boolean runAsRoot(String... cmds) throws IOException {
    Process p = Runtime.getRuntime().exec("su");
    DataOutputStream os = new DataOutputStream(p.getOutputStream());
    for (String tmpCmd : cmds) {
      os.writeBytes(tmpCmd + "\n");
    }
    os.writeBytes("exit\n");
    os.flush();
    try {
      return p.waitFor() == 0;
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new IOException(e);
    }
  }

  static void consumeProcessOutput(Process proc, boolean listenToStdErr)
      throws IOException {
    InputStream stderr = listenToStdErr ? proc.getErrorStream() : proc
        .getInputStream();
    InputStreamReader isr = new InputStreamReader(stderr);
    BufferedReader br = new BufferedReader(isr);
    String line = null;

    while ((line = br.readLine()) != null)
      ;
  }

}

{'fraction_non_alphanumeric': 0.11781953885112621, 'fraction_numerical': 0.0014660802345728375, 'mean_word_length': 2.5801526717557253, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '672675', 'n_tokens_mistral': 2228, 'n_tokens_neox': 2174, 'n_words': 573}