<commit_before>package org.handwerkszeug.riak.pbc;

import java.io.IOException;

import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.node.ArrayNode;
import org.handwerkszeug.riak.RiakException;
import org.handwerkszeug.riak.mapreduce.MapReduceResponse;
import org.handwerkszeug.riak.nls.Messages;
import org.handwerkszeug.riak.pbc.Riakclient.RpbMapRedResp;

import com.google.protobuf.ByteString;

/**
 * @author taichi
 */
public class PbcMapReduceResponse implements MapReduceResponse {

	final RpbMapRedResp resp;

	public PbcMapReduceResponse(RpbMapRedResp resp) {
		this.resp = resp;
	}

	@Override
	public Integer getPhase() {
		if (this.resp.hasPhase()) {
			return this.resp.getPhase();
		}
		return null;
	}

	@Override
	public ArrayNode getResponse() {
		if (this.resp.hasResponse()) {
			ByteString bs = this.resp.getResponse();
			JsonFactory factory = new JsonFactory(new ObjectMapper());
			try {
				JsonParser parser = factory.createJsonParser(bs.toStringUtf8());
				JsonNode jn = parser.readValueAsTree();
				if (jn instanceof ArrayNode) {<commit_msg>change from String to InputStream.<commit_after>package org.handwerkszeug.riak.pbc;

import java.io.IOException;

import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.node.ArrayNode;
import org.handwerkszeug.riak.RiakException;
import org.handwerkszeug.riak.mapreduce.MapReduceResponse;
import org.handwerkszeug.riak.nls.Messages;
import org.handwerkszeug.riak.pbc.Riakclient.RpbMapRedResp;

import com.google.protobuf.ByteString;

/**
 * @author taichi
 */
public class PbcMapReduceResponse implements MapReduceResponse {

	final RpbMapRedResp resp;

	public PbcMapReduceResponse(RpbMapRedResp resp) {
		this.resp = resp;
	}

	@Override
	public Integer getPhase() {
		if (this.resp.hasPhase()) {
			return this.resp.getPhase();
		}
		return null;
	}

	@Override
	public ArrayNode getResponse() {
		if (this.resp.hasResponse()) {
			ByteString bs = this.resp.getResponse();
			JsonFactory factory = new JsonFactory(new ObjectMapper());
			try {
				JsonParser parser = factory.createJsonParser(bs.newInput());
				JsonNode jn = parser.readValueAsTree();
				if (jn instanceof ArrayNode) {
{'fraction_non_alphanumeric': 0.1078310783107831, 'fraction_numerical': 0.0004100041000410004, 'mean_word_length': 5.03960396039604, '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': '1886380', 'n_tokens_mistral': 870, 'n_tokens_neox': 807, 'n_words': 152}