<commit_before>package de.unistuttgart.iste.rss.bugminer.coverage;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import sun.misc.IOUtils;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
 * Parses zip files created by {@link CoverageReportDeserializer} into {@link CoverageReport}
 * objects
 */
public class CoverageReportDeserializer {
	/**
	 * Reads the given zip file as as coverage report
	 * @param file the path to the zip file
	 * @return the coverage report
	 * @throws IOException error reading or invalid format
	 */
	public CoverageReport deserialize(Path file) throws IOException {
		try (FileInputStream in = new FileInputStream(file.toFile())) {
			return deserialize(in);
		}
	}

	/**
	 * Reads the given stream as coverage report
	 * @param in the input stream to read from
	 * @return the coverage report
	 * @throws IOException error reading or invalid format
	 */
	public CoverageReport deserialize(InputStream in) throws IOException {
		ObjectMapper mapper = new ObjectMapper();
		mapper.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false);
		CoverageReport report = null;
		byte[] data = null;

		try (ZipInputStream zip = new ZipInputStream(in)) {
			ZipEntry entry = zip.getNextEntry();
			while (entry != null) {
				switch (entry.getName()) {
					case "metadata.json":
						report = mapper.readValue(zip, CoverageReport.class);
						break;
					case "data.bin":
						data = IOUtils.readFully(zip, -1, true);
						break;
				}

				entry = zip.getNextEntry();
			}

			if (data == null) {
				throw new IOException("data.bin missing in coverage archive");
			}

			if (report == null) {<commit_msg>Coverage deserialization does not fail on unknown properties<commit_after>package de.unistuttgart.iste.rss.bugminer.coverage;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import jdk.nashorn.internal.parser.JSONParser;
import sun.misc.IOUtils;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
 * Parses zip files created by {@link CoverageReportDeserializer} into {@link CoverageReport}
 * objects
 */
public class CoverageReportDeserializer {
	/**
	 * Reads the given zip file as as coverage report
	 * @param file the path to the zip file
	 * @return the coverage report
	 * @throws IOException error reading or invalid format
	 */
	public CoverageReport deserialize(Path file) throws IOException {
		try (FileInputStream in = new FileInputStream(file.toFile())) {
			return deserialize(in);
		}
	}

	/**
	 * Reads the given stream as coverage report
	 * @param in the input stream to read from
	 * @return the coverage report
	 * @throws IOException error reading or invalid format
	 */
	public CoverageReport deserialize(InputStream in) throws IOException {
		ObjectMapper mapper = new ObjectMapper();
		mapper.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false);
		mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		CoverageReport report = null;
		byte[] data = null;

		try (ZipInputStream zip = new ZipInputStream(in)) {
			ZipEntry entry = zip.getNextEntry();
			while (entry != null) {
				switch (entry.getName()) {
					case "metadata.json":
						report = mapper.readValue(zip, CoverageReport.class);
						break;
					case "data.bin":
						data = IOUtils.readFully(zip, -1, true);
						break;
				}

				entry = zip.getNextEntry();
			}

			if (data == null) {
				throw new IOException("data.bin missing in coverage archive");
			}

			if (report == null) {
{'fraction_non_alphanumeric': 0.1014940752189593, 'fraction_numerical': 0.0005151983513652757, 'mean_word_length': 4.042857142857143, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, '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': '5049402', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1112, 'n_words': 333}