<commit_before>package org.prevayler.foundation;

import org.prevayler.foundation.serialization.Serializer;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

public class DeepCopier {

	/**
	 * Produce a deep copy of the given object. Serializes the entire object to a byte array in memory. Recommended for
	 * relatively small objects, such as individual transactions.
	 */
	public static Object deepCopy(Object original, Serializer serializer) throws IOException, ClassNotFoundException {
		ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
		serializer.writeObject(byteOut, original);
		ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
		return serializer.readObject(byteIn);
	}

	/**
	 * Produce a deep copy of the given object. Serializes the object through a pipe between two threads. Recommended for
	 * very large objects, such as an entire prevalent system. The current thread is used for serializing the original<commit_msg>DeepCopier.deepCopy(Object) without serializer parameter recreated.<commit_after>package org.prevayler.foundation;

import org.prevayler.foundation.serialization.JavaSerializer;
import org.prevayler.foundation.serialization.Serializer;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

public class DeepCopier {
	
	/**
	 * Same as deepCopy(original, new JavaSerializer()).
	 * @throws ClassNotFoundException
	 * @throws IOException
	 * 
	 */
	public static Object deepCopy(Object original) throws IOException, ClassNotFoundException {
		return deepCopy(original, new JavaSerializer());
	}

	/**
	 * Produce a deep copy of the given object. Serializes the entire object to a byte array in memory. Recommended for
	 * relatively small objects, such as individual transactions.
	 */
	public static Object deepCopy(Object original, Serializer serializer) throws IOException, ClassNotFoundException {
		ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
		serializer.writeObject(byteOut, original);
		ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
		return serializer.readObject(byteIn);
	}

	/**
	 * Produce a deep copy of the given object. Serializes the object through a pipe between two threads. Recommended for
	 * very large objects, such as an entire prevalent system. The current thread is used for serializing the original
{'fraction_non_alphanumeric': 0.07150964812712826, 'fraction_numerical': 0.0, 'mean_word_length': 5.4645476772616135, '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': '6265084', 'n_tokens_mistral': 696, 'n_tokens_neox': 658, 'n_words': 236}