<commit_before>package com.google.appengine.demos.mapreduce.randomcollisions;

import com.google.appengine.api.appidentity.AppIdentityServiceFactory;
import com.google.appengine.api.appidentity.AppIdentityServiceFailureException;
import com.google.appengine.api.memcache.MemcacheService;
import com.google.appengine.api.memcache.MemcacheServiceFactory;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.appengine.tools.mapreduce.GoogleCloudStorageFileSet;
import com.google.appengine.tools.mapreduce.MapReduceJob;
import com.google.appengine.tools.mapreduce.MapReduceSettings;
import com.google.appengine.tools.mapreduce.MapReduceSpecification;
import com.google.appengine.tools.mapreduce.Mapper;
import com.google.appengine.tools.mapreduce.Marshaller;
import com.google.appengine.tools.mapreduce.Marshallers;
import com.google.appengine.tools.mapreduce.Output;
import com.google.appengine.tools.mapreduce.Reducer;
import com.google.appengine.tools.mapreduce.inputs.ConsecutiveLongInput;
import com.google.appengine.tools.mapreduce.outputs.GoogleCloudStorageFileOutput;
import com.google.appengine.tools.mapreduce.outputs.MarshallingOutput;
import com.google.common.base.Strings;
import com.google.common.primitives.Ints;

import java.io.IOException;
import java.io.PrintWriter;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * This is an example Map Reduce that demos parallel computation.
 *
 *  <p>For the purposes of illustration this MapReduce looks for collisions in Java's Random number
 * generator. (It does not find any.)
 *
 *  <p>Here a collision is defined as multiple seed values that when next is called produce the same
 * output value.
 *
 *  <p>The input source is a range of numbers to test, and any collisions are logged and written out
 * to a file in Google Cloud Storage.
 */
@SuppressWarnings("serial")
public class CollisionFindingServlet extends HttpServlet {

  private static final Logger log = Logger.getLogger(CollisionFindingServlet.class.getName());

  private final MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
  private final UserService userService = UserServiceFactory.getUserService();
  private final SecureRandom random = new SecureRandom();

  private void writeResponse(HttpServletResponse resp) throws IOException {
    String xsrfToken = String.valueOf(random.nextLong() & Long.MAX_VALUE);
    memcache.put(userService.getCurrentUser().getUserId() + " " + xsrfToken, true);
    try (PrintWriter pw = new PrintWriter(resp.getOutputStream())) {
      pw.println("<html><body>" + "<form method='post' > <input type='hidden' name='token' value='"
          + xsrfToken
          + "'> Run a MapReduce that looks for seeds to java's Random that result in the "
          + "same initial number being created.  <div> <br />  GCS Bucket to store data:"
          + "<input name='gcs_bucket' /> (Leave empty to use the app's default bucket) <br />"
          + "Starting integer to test: <input value='0' name='start' /> <br />"
          + "Final integer to test: <input value='3000000' name='limit' />"
          + "(Must be greater than starting integer and less than 2^31-1) <br />"
          + "Number of shards <input value='10' name='shards' />"
          + "(Must be between 1 and 100) <br />"
          + "<input name='queue' value='mapreduce-workers'/><br />"
          + "<input name='module' value='mapreduce'/><br />"
          + "<input type='submit' value='Start MapReduce' />"
          + "</div> </form> </body></html>");
    }
  }

  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    if (userService.getCurrentUser() == null) {<commit_msg>Java: Add lables to new fields.<commit_after>package com.google.appengine.demos.mapreduce.randomcollisions;

import com.google.appengine.api.appidentity.AppIdentityServiceFactory;
import com.google.appengine.api.appidentity.AppIdentityServiceFailureException;
import com.google.appengine.api.memcache.MemcacheService;
import com.google.appengine.api.memcache.MemcacheServiceFactory;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.appengine.tools.mapreduce.GoogleCloudStorageFileSet;
import com.google.appengine.tools.mapreduce.MapReduceJob;
import com.google.appengine.tools.mapreduce.MapReduceSettings;
import com.google.appengine.tools.mapreduce.MapReduceSpecification;
import com.google.appengine.tools.mapreduce.Mapper;
import com.google.appengine.tools.mapreduce.Marshaller;
import com.google.appengine.tools.mapreduce.Marshallers;
import com.google.appengine.tools.mapreduce.Output;
import com.google.appengine.tools.mapreduce.Reducer;
import com.google.appengine.tools.mapreduce.inputs.ConsecutiveLongInput;
import com.google.appengine.tools.mapreduce.outputs.GoogleCloudStorageFileOutput;
import com.google.appengine.tools.mapreduce.outputs.MarshallingOutput;
import com.google.common.base.Strings;
import com.google.common.primitives.Ints;

import java.io.IOException;
import java.io.PrintWriter;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * This is an example Map Reduce that demos parallel computation.
 *
 *  <p>For the purposes of illustration this MapReduce looks for collisions in Java's Random number
 * generator. (It does not find any.)
 *
 *  <p>Here a collision is defined as multiple seed values that when next is called produce the same
 * output value.
 *
 *  <p>The input source is a range of numbers to test, and any collisions are logged and written out
 * to a file in Google Cloud Storage.
 */
@SuppressWarnings("serial")
public class CollisionFindingServlet extends HttpServlet {

  private static final Logger log = Logger.getLogger(CollisionFindingServlet.class.getName());

  private final MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
  private final UserService userService = UserServiceFactory.getUserService();
  private final SecureRandom random = new SecureRandom();

  private void writeResponse(HttpServletResponse resp) throws IOException {
    String xsrfToken = String.valueOf(random.nextLong() & Long.MAX_VALUE);
    memcache.put(userService.getCurrentUser().getUserId() + " " + xsrfToken, true);
    try (PrintWriter pw = new PrintWriter(resp.getOutputStream())) {
      pw.println("<html><body>" + "<form method='post' > <input type='hidden' name='token' value='"
          + xsrfToken
          + "'> Run a MapReduce that looks for seeds to java's Random that result in the "
          + "same initial number being created.  <div> <br />  GCS Bucket to store data:"
          + "<input name='gcs_bucket' /> (Leave empty to use the app's default bucket) <br />"
          + "Starting integer to test: <input value='0' name='start' /> <br />"
          + "Final integer to test: <input value='3000000' name='limit' />"
          + "(Must be greater than starting integer and less than 2^31-1) <br />"
          + "Number of shards <input value='10' name='shards' />"
          + "(Must be between 1 and 100) <br />"
          + "Queue name: <input name='queue' value='mapreduce-workers'/><br />"
          + "Module: <input name='module' value='mapreduce'/><br />"
          + "<input type='submit' value='Start MapReduce' />"
          + "</div> </form> </body></html>");
    }
  }

  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    if (userService.getCurrentUser() == null) {
{'fraction_non_alphanumeric': 0.11293582617483577, 'fraction_numerical': 0.004547751389590703, 'mean_word_length': 4.536363636363636, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, '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': '424970', 'n_tokens_mistral': 2275, 'n_tokens_neox': 2232, 'n_words': 582}