<commit_before>package com.github.dreamhead.moco.extractor;

import com.github.dreamhead.moco.HttpRequest;
import com.github.dreamhead.moco.HttpRequestExtractor;
import com.github.dreamhead.moco.model.MessageContent;
import com.google.common.base.Optional;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;

import static com.google.common.base.Optional.absent;
import static com.google.common.base.Optional.of;

public class JsonPathRequestExtractor extends HttpRequestExtractor<Object> {
    private final ContentRequestExtractor extractor = new ContentRequestExtractor();
    private final JsonPath jsonPath;

    public JsonPathRequestExtractor(final String jsonPath) {
        this.jsonPath = JsonPath.compile(jsonPath);
    }

    @Override
    protected Optional<Object> doExtract(final HttpRequest request) {
        Optional<MessageContent> requestBody = extractor.extract(request);
        try {
            if (!requestBody.isPresent()) {
                return absent();
            }

            MessageContent content = requestBody.get();
            Object jsonPathContent = jsonPath.read(new ByteArrayInputStream(content.getContent()),
                    content.getCharset().toString(),
                    Configuration.defaultConfiguration());
            if (jsonPathContent == null) {
                return absent();
            }
            return of(toStringArray(jsonPathContent));
        } catch (PathNotFoundException | IOException e) {<commit_msg>added missing final to json path request extractor<commit_after>package com.github.dreamhead.moco.extractor;

import com.github.dreamhead.moco.HttpRequest;
import com.github.dreamhead.moco.HttpRequestExtractor;
import com.github.dreamhead.moco.model.MessageContent;
import com.google.common.base.Optional;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;

import static com.google.common.base.Optional.absent;
import static com.google.common.base.Optional.of;

public final class JsonPathRequestExtractor extends HttpRequestExtractor<Object> {
    private final ContentRequestExtractor extractor = new ContentRequestExtractor();
    private final JsonPath jsonPath;

    public JsonPathRequestExtractor(final String jsonPath) {
        this.jsonPath = JsonPath.compile(jsonPath);
    }

    @Override
    protected Optional<Object> doExtract(final HttpRequest request) {
        Optional<MessageContent> requestBody = extractor.extract(request);
        try {
            if (!requestBody.isPresent()) {
                return absent();
            }

            MessageContent content = requestBody.get();
            Object jsonPathContent = jsonPath.read(new ByteArrayInputStream(content.getContent()),
                    content.getCharset().toString(),
                    Configuration.defaultConfiguration());
            if (jsonPathContent == null) {
                return absent();
            }
            return of(toStringArray(jsonPathContent));
        } catch (PathNotFoundException | IOException e) {
{'fraction_non_alphanumeric': 0.08990110878034162, 'fraction_numerical': 0.0, 'mean_word_length': 3.3978919631093545, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4268587', 'n_tokens_mistral': 864, 'n_tokens_neox': 837, 'n_words': 174}