<commit_before>package org.nutz.mvc.upload;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.nutz.filepool.FilePool;
import org.nutz.http.Http;
import org.nutz.lang.Strings;
import org.nutz.lang.stream.StreamBuffer;

class Uploading {

	private static final char[] endName = {0x0D, 0x0A, 0x0D, 0x0A};

	private Map<String, Object> params;

	private UploadInfo info;

	public void parse(HttpServletRequest request, String charset, FilePool tmpFiles)
			throws UploadFailException {
		// Store upload info to sessioin
		info = new UploadInfo();
		request.getSession().setAttribute(UploadInfo.class.getName(), info);
		info.setSum(request.getContentLength());

		try {
			params = new HashMap<String, Object>();
			// Analyze the request data
			InputStream ins = request.getInputStream();
			// Buffer the stream
//			if (!(ins instanceof BufferedInputStream))
			ins = new BufferedInputStream(ins);
			// Check content type
			String contentType = request.getContentType();
			String s = "\r\n--" + Http.multipart.getBoundary(contentType);
			char[] endValue = s.toCharArray(); // expect boundary
			int[] right = new int[endValue.length]; // runtime cache
			int cursor;
			int c = 0;
			// skip first endField
			for (int i = 0; i < s.length(); i++)
				c = info.read(ins);
			while (c != -1) {
				cursor = 0;
				right[cursor++] = info.read(ins);
				right[cursor++] = right[0] == -1 ? -1 : info.read(ins);
				if (right[1] == -1 || (right[0] == '-' && right[1] == '-'))
					break;
				// read field title
				StreamBuffer sb = new StreamBuffer();
				while (cursor < endName.length && (c = info.read(ins)) != -1) {
					if (c == endName[cursor]) {
						right[cursor++] = c;
					} else {
						if (cursor > 0) {
							for (int i = 0; i < cursor; i++)
								sb.write(right[i]);
						}
						sb.write(c);
						cursor = 0;
					}
				}<commit_msg>request.getInputStream() 理论上还有有可能是 BufferedStream 的<commit_after>package org.nutz.mvc.upload;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.nutz.filepool.FilePool;
import org.nutz.http.Http;
import org.nutz.lang.Strings;
import org.nutz.lang.stream.StreamBuffer;

class Uploading {

	private static final char[] endName = {0x0D, 0x0A, 0x0D, 0x0A};

	private Map<String, Object> params;

	private UploadInfo info;

	public void parse(HttpServletRequest request, String charset, FilePool tmpFiles)
			throws UploadFailException {
		// Store upload info to sessioin
		info = new UploadInfo();
		request.getSession().setAttribute(UploadInfo.class.getName(), info);
		info.setSum(request.getContentLength());

		try {
			params = new HashMap<String, Object>();
			// Analyze the request data
			InputStream ins = request.getInputStream();
			// Buffer the stream
			if (!(ins instanceof BufferedInputStream))
				ins = new BufferedInputStream(ins);
			// Check content type
			String contentType = request.getContentType();
			String s = "\r\n--" + Http.multipart.getBoundary(contentType);
			char[] endValue = s.toCharArray(); // expect boundary
			int[] right = new int[endValue.length]; // runtime cache
			int cursor;
			int c = 0;
			// skip first endField
			for (int i = 0; i < s.length(); i++)
				c = info.read(ins);
			while (c != -1) {
				cursor = 0;
				right[cursor++] = info.read(ins);
				right[cursor++] = right[0] == -1 ? -1 : info.read(ins);
				if (right[1] == -1 || (right[0] == '-' && right[1] == '-'))
					break;
				// read field title
				StreamBuffer sb = new StreamBuffer();
				while (cursor < endName.length && (c = info.read(ins)) != -1) {
					if (c == endName[cursor]) {
						right[cursor++] = c;
					} else {
						if (cursor > 0) {
							for (int i = 0; i < cursor; i++)
								sb.write(right[i]);
						}
						sb.write(c);
						cursor = 0;
					}
				}
{'fraction_non_alphanumeric': 0.14618792259267896, 'fraction_numerical': 0.010725110748426206, 'mean_word_length': 3.281437125748503, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '3938714', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1391, 'n_words': 363}