<commit_before>package info.idgst.digest.reader;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializer;
import info.idgst.digest.Digest;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;
import java.util.Date;

/**
 * Implementation of {@link DigestReader} for reading {@link Digest}s from JSON Files.
 *
 * @author <NAME>
 */
@Service
public class JsonDigestReader implements DigestReader {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());


    @NotNull
    private Gson getGson() {
        // Creates the json object which will manage the information received
        GsonBuilder builder = new GsonBuilder();

        // Register an adapter to manage the date types as long values
        JsonDeserializer jsonDeserializer = (json, typeOfT, context) -> new Date(json.getAsJsonPrimitive()
                                                                                     .getAsLong());
        builder.registerTypeAdapter(Date.class, jsonDeserializer);
        return builder.create();
    }

    @Override
    public Digest readDigest(byte[] bytes){
        String jsonString = null;
        try {
            jsonString = new String(bytes, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            logger.error("Error while converting bytes to String", e);
        }
        logger.debug("Deserializing Digest from json " + jsonString);
        return getGson().fromJson(jsonString, Digest.class);
    }
}<commit_msg>Issue #65 POC: Migrate to Java    - code formatting.<commit_after>package info.idgst.digest.reader;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializer;
import info.idgst.digest.Digest;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;
import java.util.Date;

/**
 * Implementation of {@link DigestReader} for reading {@link Digest}s from JSON Files.
 *
 * @author <NAME>
 */
@Service
public class JsonDigestReader implements DigestReader {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());


    @NotNull
    private Gson getGson() {
        // Creates the json object which will manage the information received
        GsonBuilder builder = new GsonBuilder();

        // Register an adapter to manage the date types as long values
        JsonDeserializer jsonDeserializer = (json, typeOfT, context) -> new Date(json.getAsJsonPrimitive()
                                                                                     .getAsLong());
        builder.registerTypeAdapter(Date.class, jsonDeserializer);
        return builder.create();
    }

    @Override
    public Digest readDigest(byte[] bytes) {
        String jsonString = null;
        try {
            jsonString = new String(bytes, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            logger.error("Error while converting bytes to String", e);
        }
        logger.debug("Deserializing Digest from json " + jsonString);
        return getGson().fromJson(jsonString, Digest.class);
    }
}
{'fraction_non_alphanumeric': 0.09399167162403331, 'fraction_numerical': 0.002379535990481856, 'mean_word_length': 2.8, 'pattern_counts': {'":': 0, '<': 5, '<?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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '136179', 'n_tokens_mistral': 915, 'n_tokens_neox': 897, 'n_words': 243}