<commit_before>package org.flatland.drip;
import java.lang.reflect.Method;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.io.*;
import java.util.Map;
import java.util.HashMap;
import java.util.Scanner;
import java.util.LinkedList;
import java.util.List;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
  private List<Switchable> lazyStreams;
  private String mainClass;
  private File dir;
  private SwitchableOutputStream err;
  private SwitchableOutputStream out;
  private SwitchableInputStream  in;

  public Main(String mainClass, String dir) {
    this.mainClass = mainClass;
    this.dir = new File(dir);
  }

  private void killAfterTimeout() {
    String idleTimeStr = System.getenv("DRIP_SHUTDOWN"); // in minutes
    int idleTime;
    if (idleTimeStr == null) {
      idleTime = 4 * 60; // four hours
    } else {
      idleTime = Integer.parseInt(idleTimeStr);
    }

    try {
      Thread.sleep(idleTime * 60 * 1000); // convert minutes to ms
    } catch (InterruptedException e) {
      System.err.println("drip: Interrupted??");
      return; // I guess someone wanted to kill the timeout thread?
    }

    File lockDir = new File(dir, "lock");
    if (lockDir.mkdir()) {
      System.exit(0);
    } else {
      // someone is already connected; let the process finish
    }
  }

  private void startIdleKiller() {
    Thread idleKiller = new Thread() {
        public void run() {
          killAfterTimeout();
        }
      };

    idleKiller.setDaemon(true);
    idleKiller.start();
  }

  public static void main(String[] args) throws Exception {
    new Main(args[0], args[1]).start();
  }

  public void start() throws Exception {
    reopenStreams();

    Method main = mainMethod(mainClass);    
    Method init = mainMethod(System.getenv("DRIP_INIT_CLASS"));
    String initArgs = System.getenv("DRIP_INIT");
    if (initArgs != null) {
      invoke(init == null ? main : init, split(initArgs, "\n"));
    }
    startIdleKiller();

    Scanner fromBash = new Scanner(new File(dir, "control"));
    String mainArgs    = readString(fromBash);
    String runtimeArgs = readString(fromBash);
    String environment = readString(fromBash);
    fromBash.close();

    mergeEnv(parseEnv(environment));
    setProperties(runtimeArgs);
    switchStreams();

    invoke(main, split(mainArgs, "\u0000"));
  }
<commit_msg>Don't require empty DRIP_INIT just to use DRIP_INIT_CLASS<commit_after>package org.flatland.drip;
import java.lang.reflect.Method;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.io.*;
import java.util.Map;
import java.util.HashMap;
import java.util.Scanner;
import java.util.LinkedList;
import java.util.List;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
  private List<Switchable> lazyStreams;
  private String mainClass;
  private File dir;
  private SwitchableOutputStream err;
  private SwitchableOutputStream out;
  private SwitchableInputStream  in;

  public Main(String mainClass, String dir) {
    this.mainClass = mainClass;
    this.dir = new File(dir);
  }

  private void killAfterTimeout() {
    String idleTimeStr = System.getenv("DRIP_SHUTDOWN"); // in minutes
    int idleTime;
    if (idleTimeStr == null) {
      idleTime = 4 * 60; // four hours
    } else {
      idleTime = Integer.parseInt(idleTimeStr);
    }

    try {
      Thread.sleep(idleTime * 60 * 1000); // convert minutes to ms
    } catch (InterruptedException e) {
      System.err.println("drip: Interrupted??");
      return; // I guess someone wanted to kill the timeout thread?
    }

    File lockDir = new File(dir, "lock");
    if (lockDir.mkdir()) {
      System.exit(0);
    } else {
      // someone is already connected; let the process finish
    }
  }

  private void startIdleKiller() {
    Thread idleKiller = new Thread() {
        public void run() {
          killAfterTimeout();
        }
      };

    idleKiller.setDaemon(true);
    idleKiller.start();
  }

  public static void main(String[] args) throws Exception {
    new Main(args[0], args[1]).start();
  }

  public void start() throws Exception {
    reopenStreams();

    Method main = mainMethod(mainClass);    
    Method init = mainMethod(System.getenv("DRIP_INIT_CLASS"));
    String initArgs = System.getenv("DRIP_INIT");
    initArgs = initArgs == null ? "" : initArgs;
    invoke(init == null ? main : init, split(initArgs, "\n"));
    startIdleKiller();

    Scanner fromBash = new Scanner(new File(dir, "control"));
    String mainArgs    = readString(fromBash);
    String runtimeArgs = readString(fromBash);
    String environment = readString(fromBash);
    fromBash.close();

    mergeEnv(parseEnv(environment));
    setProperties(runtimeArgs);
    switchStreams();

    invoke(main, split(mainArgs, "\u0000"));
  }

{'fraction_non_alphanumeric': 0.11887827677301362, 'fraction_numerical': 0.006502743344848608, 'mean_word_length': 3.2911944202266783, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3199477', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1502, 'n_words': 384}