<commit_before>package de.cosmocode.json;

import java.io.IOException;
import java.io.Writer;

import org.json.JSONException;
import org.json.JSONWriter;
import org.json.extension.JSONConstructor;

/**
 * Implementation of the {@link JSONConstructor} interface
 * which uses most of the functionality provided
 * by {@link JSONRenderer} by wrapping an instance of it.
 *
 * @author <NAME>
 */
final class JSONWriterConstructor implements JSONConstructor {

    private final JSONWriter json;
    private final Writer writer;

    public JSONWriterConstructor(JSONWriter json) {
        this.json = json;
        this.writer = JSON.stealWriter(json);
    }
    
    @Override
    public JSONConstructor array() throws JSONException {
        json.array();
        return this;
    }
    
    @Override
    public JSONConstructor endArray() throws JSONException {
        json.endArray();
        return this;
    }
    
    @Override
    public JSONConstructor object() throws JSONException {
        json.object();
        return this;
    }
    
    @Override
    public JSONConstructor endObject() throws JSONException {
        json.endObject();
        return this;
    }
    
    @Override
    public JSONConstructor key(String key) throws JSONException {
        json.key(key);
        return this;
    }
    
    @Override
    public JSONConstructor value(boolean value) throws JSONException {
        json.value(value);
        return this;
    }
    
    @Override
    public JSONConstructor value(long value) throws JSONException {
        json.value(value);
        return this;
    }
    
    @Override
    public JSONConstructor value(double value) throws JSONException {
        json.value(value);
        return this;
    }
    
    @Override
    public JSONConstructor value(Object value) throws JSONException {
        json.value(value);
        return this;
    }
    
    @Override
    public JSONConstructor plain(String value) throws JSONException {
        try {
            writer.write(value);
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        }
        return this;
    }
    
    @Override
    public String toString() {
        return json.toString();
    }
    
}<commit_msg>attempt to fix plain value bug in JSONWriterConstructor<commit_after>package de.cosmocode.json;

import java.io.Writer;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import org.json.extension.JSONConstructor;

/**
 * Implementation of the {@link JSONConstructor} interface
 * which uses most of the functionality provided
 * by {@link JSONRenderer} by wrapping an instance of it.
 *
 * @author <NAME>
 */
final class JSONWriterConstructor implements JSONConstructor {

    private final JSONWriter json;
    private final Writer writer;

    public JSONWriterConstructor(JSONWriter json) {
        this.json = json;
        this.writer = JSON.stealWriter(json);
    }
    
    @Override
    public JSONConstructor array() throws JSONException {
        json.array();
        return this;
    }
    
    @Override
    public JSONConstructor endArray() throws JSONException {
        json.endArray();
        return this;
    }
    
    @Override
    public JSONConstructor object() throws JSONException {
        json.object();
        return this;
    }
    
    @Override
    public JSONConstructor endObject() throws JSONException {
        json.endObject();
        return this;
    }
    
    @Override
    public JSONConstructor key(String key) throws JSONException {
        json.key(key);
        return this;
    }
    
    @Override
    public JSONConstructor value(boolean value) throws JSONException {
        json.value(value);
        return this;
    }
    
    @Override
    public JSONConstructor value(long value) throws JSONException {
        json.value(value);
        return this;
    }
    
    @Override
    public JSONConstructor value(double value) throws JSONException {
        json.value(value);
        return this;
    }
    
    @Override
    public JSONConstructor value(Object value) throws JSONException {
        json.value(value);
        return this;
    }
    
    @Override
    public JSONConstructor plain(String value) throws JSONException {
        if (value == null) {
            return value(null);
        } else if (value.startsWith("{")) {
            try {
                return value(new JSONObject(value));
            } catch (JSONException e) {
                throw new IllegalArgumentException(e);
            }
        } else if (value.startsWith("[")) {
            try {
                return value(new JSONArray(value));
            } catch (JSONException e) {
                throw new IllegalArgumentException(e);
            }
        } else {
            throw new IllegalArgumentException("Illegal plain value '" + value + "'");
        }
    }
    
    @Override
    public String toString() {
        return json.toString();
    }
    
}
{'fraction_non_alphanumeric': 0.08227091633466135, 'fraction_numerical': 0.0, 'mean_word_length': 2.231016731016731, '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': '3869529', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1271, 'n_words': 367}