<commit_before>// Copyright (c) 2003-2009, Jodd Team (jodd.org). All Rights Reserved.

package jodd.madvoc.result;

import jodd.madvoc.ActionRequest;
import jodd.madvoc.ScopeType;
import jodd.madvoc.meta.In;
import jodd.madvoc.component.MadvocConfig;
import jodd.util.CharUtil;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.io.IOException;

/**
 * Raw results directly writes byte context to the output.
 * Output is closed after writing.
 */
public class RawResult extends ActionResult {

	public static final String NAME = "raw";

	public RawResult() {
		super(NAME);
	}

	@In(scope = ScopeType.CONTEXT)
	protected MadvocConfig madvocConfig;

	@Override
	public void render(ActionRequest actionRequest, Object resultObject, String resultValue, String resultPath) throws IOException {
		if (resultObject == null) {
			return;
		}
		if (resultObject instanceof RawResultData != true) {
			char[] chars = resultValue.toCharArray();
			resultObject = new RawResultData(CharUtil.toByteArray(chars), madvocConfig.getEncoding());
		}

		RawResultData result = (RawResultData) resultObject;
		byte[] data = result.getBytes();

		HttpServletResponse response = actionRequest.getHttpServletResponse();
		response.setContentType(result.getMime());
		response.setContentLength(data.length);

		OutputStream os = response.getOutputStream();
		try {
			os.write(data);
		} finally {
			os.close();
		}
	}
}<commit_msg>what I've ment is flushing, not closing;)<commit_after>// Copyright (c) 2003-2009, Jodd Team (jodd.org). All Rights Reserved.

package jodd.madvoc.result;

import jodd.madvoc.ActionRequest;
import jodd.madvoc.ScopeType;
import jodd.madvoc.meta.In;
import jodd.madvoc.component.MadvocConfig;
import jodd.util.CharUtil;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.io.IOException;

/**
 * Raw results directly writes byte context to the output.
 * Output is closed after writing.
 */
public class RawResult extends ActionResult {

	public static final String NAME = "raw";

	public RawResult() {
		super(NAME);
	}

	@In(scope = ScopeType.CONTEXT)
	protected MadvocConfig madvocConfig;

	@Override
	public void render(ActionRequest actionRequest, Object resultObject, String resultValue, String resultPath) throws IOException {
		if (resultObject == null) {
			return;
		}
		if (resultObject instanceof RawResultData != true) {
			char[] chars = resultValue.toCharArray();
			resultObject = new RawResultData(CharUtil.toByteArray(chars), madvocConfig.getEncoding());
		}

		RawResultData result = (RawResultData) resultObject;
		byte[] data = result.getBytes();

		HttpServletResponse response = actionRequest.getHttpServletResponse();
		response.setContentType(result.getMime());
		response.setContentLength(data.length);

		OutputStream os = response.getOutputStream();
		os.write(data);
		os.flush();
	}
}
{'fraction_non_alphanumeric': 0.10766045548654245, 'fraction_numerical': 0.005521048999309869, 'mean_word_length': 5.0020703933747415, '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': '820274', 'n_tokens_mistral': 936, 'n_tokens_neox': 865, 'n_words': 222}