<commit_before>package org.prevayler.util;

import java.io.*;

import javax.xml.transform.stream.*;

import org.prevayler.implementation.SnapshotManager;

import com.skaringa.javaxml.*;

/**
 * @author Alexandre
 *
 * Writes and reads snapshots to/from XML files.
 * @see org.prevayler.implementation.SnapshotManager
 */
public class XmlSnapshotManager extends SnapshotManager {

	private final ObjectTransformer trans;
	
	public XmlSnapshotManager() throws IOException {
		this("PrevalenceBase");
	}

	public XmlSnapshotManager(String snapshotDirectoryName) throws IOException {
		super(snapshotDirectoryName);
		try {
			this.trans = ObjectTransformerFactory.getInstance().getImplementation();
//			trans.setProperty(javax.xml.transform.OutputKeys.INDENT, "yes");
//			trans.setProperty(javax.xml.transform.OutputKeys.ENCODING, "ISO-8859-1");
//			trans.setProperty(com.skaringa.javaxml.PropertyKeys.OMIT_XSI_TYPE, "true");
		}
		catch (NoImplementationException nie) {
			throw new IOException("Unable to start Skaringa: " + nie.getMessage());
		}
	}


	/**
	 * @see org.prevayler.implementation.SnapshotManager#readSnapshot(File)
	 */
	protected Object readSnapshot(InputStream in) throws IOException {
		Object system = null;
		StreamSource source = new StreamSource(in);
		try {
			system = this.trans.deserialize(source);
		}
		catch (DeserializerException se) {
			throw new IOException("Unable to deserialize with Skaringa: " + se.getMessage());
		}
		finally {
			source.getInputStream().close();
		}
		return system;
	}

	/**
	 * @see org.prevayler.implementation.SnapshotManager#suffix()
	 */
	protected String suffix() {
		return "xml";
	}

	/**
	 * @see org.prevayler.implementation.SnapshotManager#writeSnapshot(Object, File)
	 */
	protected void writeSnapshot(Object prevalentSystem, OutputStream out) throws IOException {
		StreamResult result = new StreamResult(out);
		try {
			this.trans.serialize(prevalentSystem, result);
		}
		catch (SerializerException se) {
			throw new IOException("Unable to serialize with Skaringa: " + se.getMessage());
		}
		finally {
			result.getOutputStream().close();
		}
	}
}<commit_msg>minor changes to Javadoc to get rid of warnings.  a couple of @see statements were pointing to methods with only package access.  I modified these to point to the methods with protected access.  I think the ones I am pointing to now are the ones that were meant to be pointed to in the first place anyway.<commit_after>package org.prevayler.util;

import java.io.*;

import javax.xml.transform.stream.*;

import org.prevayler.implementation.SnapshotManager;

import com.skaringa.javaxml.*;

/**
 * @author Alexandre
 *
 * Writes and reads snapshots to/from XML files.
 * @see org.prevayler.implementation.SnapshotManager
 */
public class XmlSnapshotManager extends SnapshotManager {

	private final ObjectTransformer trans;
	
	public XmlSnapshotManager() throws IOException {
		this("PrevalenceBase");
	}

	public XmlSnapshotManager(String snapshotDirectoryName) throws IOException {
		super(snapshotDirectoryName);
		try {
			this.trans = ObjectTransformerFactory.getInstance().getImplementation();
//			trans.setProperty(javax.xml.transform.OutputKeys.INDENT, "yes");
//			trans.setProperty(javax.xml.transform.OutputKeys.ENCODING, "ISO-8859-1");
//			trans.setProperty(com.skaringa.javaxml.PropertyKeys.OMIT_XSI_TYPE, "true");
		}
		catch (NoImplementationException nie) {
			throw new IOException("Unable to start Skaringa: " + nie.getMessage());
		}
	}


	/**
	 * @see org.prevayler.implementation.SnapshotManager#readSnapshot(InputStream)
	 */
	protected Object readSnapshot(InputStream in) throws IOException {
		Object system = null;
		StreamSource source = new StreamSource(in);
		try {
			system = this.trans.deserialize(source);
		}
		catch (DeserializerException se) {
			throw new IOException("Unable to deserialize with Skaringa: " + se.getMessage());
		}
		finally {
			source.getInputStream().close();
		}
		return system;
	}

	/**
	 * @see org.prevayler.implementation.SnapshotManager#suffix()
	 */
	protected String suffix() {
		return "xml";
	}

	/**
	 * @see org.prevayler.implementation.SnapshotManager#writeSnapshot(Object, OutputStream)
	 */
	protected void writeSnapshot(Object prevalentSystem, OutputStream out) throws IOException {
		StreamResult result = new StreamResult(out);
		try {
			this.trans.serialize(prevalentSystem, result);
		}
		catch (SerializerException se) {
			throw new IOException("Unable to serialize with Skaringa: " + se.getMessage());
		}
		finally {
			result.getOutputStream().close();
		}
	}
}
{'fraction_non_alphanumeric': 0.11232279171210469, 'fraction_numerical': 0.0021810250817884407, 'mean_word_length': 4.565533980582524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '4115630', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1319, 'n_words': 318}