<commit_before>// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.net;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;

/**
 * A config for UrlRequestContext, which allows runtime configuration of
 * UrlRequestContext.
 */
public class UrlRequestContextConfig {
    private final JSONObject mConfig;

    /**
     * Default config enables SPDY, disables QUIC, SDCH and http cache.
     */
    public UrlRequestContextConfig() {
        mConfig = new JSONObject();
        enableLegacyMode(false);
        enableQUIC(false);
        enableHTTP2(true);
        enableSDCH(false);
        enableHttpCache(HTTP_CACHE_DISABLED, 0);
    }

    /**
     * Creates a config from a JSON string, which was serialized using
     * {@link #toString}.
     */
    public UrlRequestContextConfig(String json) throws JSONException {
        mConfig = new JSONObject(json);
    }

    /**
     * Overrides the user-agent header for all requests.
     * @return the config to facilitate chaining.
     */
    public UrlRequestContextConfig setUserAgent(String userAgent) {
        return putString(UrlRequestContextConfigList.USER_AGENT, userAgent);
    }

    String userAgent() {
        return mConfig.optString(UrlRequestContextConfigList.USER_AGENT);
    }

    /**
     * Sets directory for HTTP Cache and Cookie Storage. The directory must
     * exist.
     * @param value path to existing directory.
     * @return the config to facilitate chaining.
     */
    public UrlRequestContextConfig setStoragePath(String value) {
        if (!new File(value).isDirectory()) {
            throw new IllegalArgumentException(
                    "Storage path must be set to existing directory");
        }

        return putString(UrlRequestContextConfigList.STORAGE_PATH, value);
    }

    String storagePath() {
        return mConfig.optString(UrlRequestContextConfigList.STORAGE_PATH);
    }

    /**
     * Sets whether falling back to implementation based on system's
     * {@link java.net.HttpURLConnection} implementation is enabled.
     * Defaults to disabled.
     * @return the config to facilitate chaining.
     * @deprecated Not supported by the new API.
     */
    public UrlRequestContextConfig enableLegacyMode(boolean value) {
        return putBoolean(UrlRequestContextConfigList.ENABLE_LEGACY_MODE,
                          value);
    }

    boolean legacyMode() {
        return mConfig.optBoolean(
                UrlRequestContextConfigList.ENABLE_LEGACY_MODE);
    }
<commit_msg>Added @Deprecated annotation to fix errorprone error.<commit_after>// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.net;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;

/**
 * A config for UrlRequestContext, which allows runtime configuration of
 * UrlRequestContext.
 */
public class UrlRequestContextConfig {
    private final JSONObject mConfig;

    /**
     * Default config enables SPDY, disables QUIC, SDCH and http cache.
     */
    public UrlRequestContextConfig() {
        mConfig = new JSONObject();
        enableLegacyMode(false);
        enableQUIC(false);
        enableHTTP2(true);
        enableSDCH(false);
        enableHttpCache(HTTP_CACHE_DISABLED, 0);
    }

    /**
     * Creates a config from a JSON string, which was serialized using
     * {@link #toString}.
     */
    public UrlRequestContextConfig(String json) throws JSONException {
        mConfig = new JSONObject(json);
    }

    /**
     * Overrides the user-agent header for all requests.
     * @return the config to facilitate chaining.
     */
    public UrlRequestContextConfig setUserAgent(String userAgent) {
        return putString(UrlRequestContextConfigList.USER_AGENT, userAgent);
    }

    String userAgent() {
        return mConfig.optString(UrlRequestContextConfigList.USER_AGENT);
    }

    /**
     * Sets directory for HTTP Cache and Cookie Storage. The directory must
     * exist.
     * @param value path to existing directory.
     * @return the config to facilitate chaining.
     */
    public UrlRequestContextConfig setStoragePath(String value) {
        if (!new File(value).isDirectory()) {
            throw new IllegalArgumentException(
                    "Storage path must be set to existing directory");
        }

        return putString(UrlRequestContextConfigList.STORAGE_PATH, value);
    }

    String storagePath() {
        return mConfig.optString(UrlRequestContextConfigList.STORAGE_PATH);
    }

    /**
     * Sets whether falling back to implementation based on system's
     * {@link java.net.HttpURLConnection} implementation is enabled.
     * Defaults to disabled.
     * @return the config to facilitate chaining.
     * @deprecated Not supported by the new API.
     */
    @Deprecated
    public UrlRequestContextConfig enableLegacyMode(boolean value) {
        return putBoolean(UrlRequestContextConfigList.ENABLE_LEGACY_MODE,
                          value);
    }

    boolean legacyMode() {
        return mConfig.optBoolean(
                UrlRequestContextConfigList.ENABLE_LEGACY_MODE);
    }

{'fraction_non_alphanumeric': 0.07775735294117647, 'fraction_numerical': 0.0022058823529411764, 'mean_word_length': 2.775850104094379, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2147086', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1415, 'n_words': 431}