<commit_before>/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2011 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the GNU Affero
 * General Public License. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */
package org.geomajas.testdata;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import org.junit.Assert;
import org.springframework.core.io.Resource;

/**
 * Abstract class to check binary stream equality. Implementors should provide access to actual and expected data by
 * implementing the methods generateActual() and getExpected().
 * 
 * @author <NAME>
 * 
 */
public abstract class BinaryStreamAssert {

	/**
	 * Assert that the generated stream is binary equal to the specified binary resource.
	 * 
	 * @param resourceName
	 *            name part of resource
	 * @param baae
	 *            accessor to actual and expected binary data
	 * @param rewrite
	 *            if true, the expected will be rewritten
	 * @throws Exception 
	 */
	public void assertEqual(String resourceName, boolean rewrite) throws Exception {
		assertEqual("resource " + resourceName + " not equal or writable", resourceName, rewrite);
	}

	/**
	 * Assert that the generated stream is binary equal to the specified binary resource.
	 * 
	 * @param message
	 *            message for the world if assert fails
	 * @param resourceName
	 *            name part of resource
	 * @param baae
	 *            accessor to actual and expected binary data
	 * @param rewrite
	 *            if true, the expected will be rewritten
	 * @throws Exception 
	 */
	public void assertEqual(String message, String resourceName, boolean rewrite) throws Exception {
		if (rewrite) {
			File file;
				file = getExpected(resourceName, rewrite).getFile();
				FileOutputStream fos;
				fos = new FileOutputStream(file);
				generateActual(fos);
				fos.flush();
				fos.close();
				Assert.fail("could not write expected");
		} else {
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				generateActual(baos);
				baos.flush();
				baos.close();
				ByteArrayOutputStream bos = new ByteArrayOutputStream();
				InputStream is = getExpected(resourceName, false).getInputStream();
				byte[] buf = new byte[1024];
				int len;
				while ((len = is.read(buf, 0, 1024)) != -1) {
					bos.write(buf, 0, len);
				}
				is.close();
				byte[] expecteds = bos.toByteArray();
				Assert.assertArrayEquals(message, expecteds, baos.toByteArray());
		}<commit_msg>RAST-19: forgot to remove fail<commit_after>/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2011 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the GNU Affero
 * General Public License. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */
package org.geomajas.testdata;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import org.junit.Assert;
import org.springframework.core.io.Resource;

/**
 * Abstract class to check binary stream equality. Implementors should provide access to actual and expected data by
 * implementing the methods generateActual() and getExpected().
 * 
 * @author <NAME>
 * 
 */
public abstract class BinaryStreamAssert {

	/**
	 * Assert that the generated stream is binary equal to the specified binary resource.
	 * 
	 * @param resourceName
	 *            name part of resource
	 * @param baae
	 *            accessor to actual and expected binary data
	 * @param rewrite
	 *            if true, the expected will be rewritten
	 * @throws Exception 
	 */
	public void assertEqual(String resourceName, boolean rewrite) throws Exception {
		assertEqual("resource " + resourceName + " not equal or writable", resourceName, rewrite);
	}

	/**
	 * Assert that the generated stream is binary equal to the specified binary resource.
	 * 
	 * @param message
	 *            message for the world if assert fails
	 * @param resourceName
	 *            name part of resource
	 * @param baae
	 *            accessor to actual and expected binary data
	 * @param rewrite
	 *            if true, the expected will be rewritten
	 * @throws Exception 
	 */
	public void assertEqual(String message, String resourceName, boolean rewrite) throws Exception {
		if (rewrite) {
			File file;
			file = getExpected(resourceName, rewrite).getFile();
			FileOutputStream fos;
			fos = new FileOutputStream(file);
			generateActual(fos);
			fos.flush();
			fos.close();
		} else {
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				generateActual(baos);
				baos.flush();
				baos.close();
				ByteArrayOutputStream bos = new ByteArrayOutputStream();
				InputStream is = getExpected(resourceName, false).getInputStream();
				byte[] buf = new byte[1024];
				int len;
				while ((len = is.read(buf, 0, 1024)) != -1) {
					bos.write(buf, 0, len);
				}
				is.close();
				byte[] expecteds = bos.toByteArray();
				Assert.assertArrayEquals(message, expecteds, baos.toByteArray());
		}
{'fraction_non_alphanumeric': 0.09431900946831755, 'fraction_numerical': 0.007283321194464676, 'mean_word_length': 3.3217938630999213, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '5938640', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1444, 'n_words': 538}