<commit_before>/*
 *  Copyright 2015 WebPipes contributors
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.hibnet.webpipes;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.StringTokenizer;

import org.hibnet.jsourcemap.SourceMap;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class WebpipeUtils {

    public static final Charset UTF8 = Charset.forName("UTF-8");

    private static final ObjectMapper SOURCEMAP_JSON_MAPPER = new ObjectMapper();

    static {
        SOURCEMAP_JSON_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        SOURCEMAP_JSON_MAPPER.getSerializationConfig().withSerializationInclusion(Include.NON_NULL);
    }

    public static MessageDigest buildSHA1Digest() {
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("SHA-1 is not supported", e);
        }
        return digest;
    }

    public static byte[] sha1(String content) {
        return buildSHA1Digest().digest(content.getBytes(UTF8));
    }

    public static String sha1HexEncoded(String content) {
        return hexEncode(sha1(content));
    }

    private static final char[] ALPHABET = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

    public static String hexEncode(byte[] data) {
        StringBuilder buffer = new StringBuilder(16);
        for (int i = 0; i < data.length; i++) {
            int highBits = (data[i] & 0xF0) >> 4;
            int lowBits = data[i] & 0x0F;
            buffer.append(ALPHABET[highBits]);
            buffer.append(ALPHABET[lowBits]);<commit_msg>fix null exclusions in json serialisation<commit_after>/*
 *  Copyright 2015 WebPipes contributors
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.hibnet.webpipes;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.StringTokenizer;

import org.hibnet.jsourcemap.SourceMap;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class WebpipeUtils {

    public static final Charset UTF8 = Charset.forName("UTF-8");

    private static final ObjectMapper SOURCEMAP_JSON_MAPPER = new ObjectMapper();

    static {
        SOURCEMAP_JSON_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        SOURCEMAP_JSON_MAPPER.setSerializationInclusion(Include.NON_NULL);
    }

    public static MessageDigest buildSHA1Digest() {
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("SHA-1 is not supported", e);
        }
        return digest;
    }

    public static byte[] sha1(String content) {
        return buildSHA1Digest().digest(content.getBytes(UTF8));
    }

    public static String sha1HexEncoded(String content) {
        return hexEncode(sha1(content));
    }

    private static final char[] ALPHABET = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

    public static String hexEncode(byte[] data) {
        StringBuilder buffer = new StringBuilder(16);
        for (int i = 0; i < data.length; i++) {
            int highBits = (data[i] & 0xF0) >> 4;
            int lowBits = data[i] & 0x0F;
            buffer.append(ALPHABET[highBits]);
            buffer.append(ALPHABET[lowBits]);
{'fraction_non_alphanumeric': 0.10473684210526316, 'fraction_numerical': 0.01263157894736842, 'mean_word_length': 3.6921810699588478, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2559136', 'n_tokens_mistral': 1714, 'n_tokens_neox': 1650, 'n_words': 460}