view src/alice/test/codesegment/local/wordcount/SetTask.java @ 241:02783f3699b1

add word count
author sugi
date Tue, 16 Apr 2013 15:09:47 +0900
parents
children 3bcaf12cf877
line wrap: on
line source

package alice.test.codesegment.local.wordcount;

import alice.codesegment.CodeSegment;
import java.io.*;

public class SetTask extends CodeSegment {
	
	private WordConfig conf;

	public SetTask(WordConfig conf) {
		this.conf = conf;
	}

	@Override
	public void run() {
		BufferedReader br = null;
		int i = 0;
		try {
			br= new BufferedReader(
                    new InputStreamReader(
                       new FileInputStream(
                          new File(conf.filename)
                          )));
			int size = conf.division * 1024 * 1024; // 16Kbyte
			char[] buf;
			for (;;i++){
				buf = new char[size];
				int check = br.read(buf);
				ods.put("array", buf);
				if (check==-1) break;
				new WordCount();
			}
			new CorrectResult(i);
		} catch (FileNotFoundException e) {
			System.out.println("file not found");
			System.exit(0);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		try {
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}