<commit_before>/**
 * Copyright (c) 2015-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
package com.facebook.react.modules.blob;

import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.webkit.MimeTypeMap;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.network.NetworkingModule;
import com.facebook.react.modules.websocket.WebSocketModule;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import okio.ByteString;

@ReactModule(name = BlobModule.NAME)
public class BlobModule extends ReactContextBaseJavaModule {

  protected static final String NAME = "BlobModule";

  private final Map<String, byte[]> mBlobs = new HashMap<>();

  private final WebSocketModule.ContentHandler mWebSocketContentHandler =
    new WebSocketModule.ContentHandler() {
      @Override
      public void onMessage(String text, WritableMap params) {
        params.putString("data", text);
      }

      @Override
      public void onMessage(ByteString bytes, WritableMap params) {
        byte[] data = bytes.toByteArray();

        WritableMap blob = Arguments.createMap();

        blob.putString("blobId", store(data));
        blob.putInt("offset", 0);
        blob.putInt("size", data.length);

        params.putMap("data", blob);
        params.putString("type", "blob");
      }
    };

  private final NetworkingModule.UriHandler mNetworkingUriHandler =
    new NetworkingModule.UriHandler() {
      @Override
      public boolean supports(Uri uri, String responseType) {
        String scheme = uri.getScheme();
        boolean isRemote = scheme.equals("http") || scheme.equals("https");

        return (!isRemote && responseType.equals("blob"));
      }

      @Override
      public WritableMap fetch(Uri uri) throws IOException {
        byte[] data = getBytesFromUri(uri);

        WritableMap blob = Arguments.createMap();
        blob.putString("blobId", store(data));
        blob.putInt("offset", 0);
        blob.putInt("size", data.length);
        blob.putString("type", getMimeTypeFromUri(uri));

        // Needed for files
        blob.putString("name", getNameFromUri(uri));
        blob.putDouble("lastModified", getLastModifiedFromUri(uri));
<commit_msg>Switch equality check in BlobModule.java<commit_after>/**
 * Copyright (c) 2015-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
package com.facebook.react.modules.blob;

import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.webkit.MimeTypeMap;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.network.NetworkingModule;
import com.facebook.react.modules.websocket.WebSocketModule;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import okio.ByteString;

@ReactModule(name = BlobModule.NAME)
public class BlobModule extends ReactContextBaseJavaModule {

  protected static final String NAME = "BlobModule";

  private final Map<String, byte[]> mBlobs = new HashMap<>();

  private final WebSocketModule.ContentHandler mWebSocketContentHandler =
    new WebSocketModule.ContentHandler() {
      @Override
      public void onMessage(String text, WritableMap params) {
        params.putString("data", text);
      }

      @Override
      public void onMessage(ByteString bytes, WritableMap params) {
        byte[] data = bytes.toByteArray();

        WritableMap blob = Arguments.createMap();

        blob.putString("blobId", store(data));
        blob.putInt("offset", 0);
        blob.putInt("size", data.length);

        params.putMap("data", blob);
        params.putString("type", "blob");
      }
    };

  private final NetworkingModule.UriHandler mNetworkingUriHandler =
    new NetworkingModule.UriHandler() {
      @Override
      public boolean supports(Uri uri, String responseType) {
        String scheme = uri.getScheme();
        boolean isRemote = "http".equals(scheme) || "https".equals(scheme);

        return (!isRemote && responseType.equals("blob"));
      }

      @Override
      public WritableMap fetch(Uri uri) throws IOException {
        byte[] data = getBytesFromUri(uri);

        WritableMap blob = Arguments.createMap();
        blob.putString("blobId", store(data));
        blob.putInt("offset", 0);
        blob.putInt("size", data.length);
        blob.putString("type", getMimeTypeFromUri(uri));

        // Needed for files
        blob.putString("name", getNameFromUri(uri));
        blob.putDouble("lastModified", getLastModifiedFromUri(uri));

{'fraction_non_alphanumeric': 0.11006813020439062, 'fraction_numerical': 0.002725208175624527, 'mean_word_length': 4.152886115444618, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3958560', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1834, 'n_words': 422}