view src/main/java/alice/test/codesegment/local/wordcount/SeparateArray.java @ 345:8f71c3e6f11d

Change directory structure Maven standard
author sugi
date Wed, 16 Apr 2014 18:26:07 +0900
parents
children aefbe41fcf12
line wrap: on
line source

package alice.test.codesegment.local.wordcount;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import alice.codesegment.CodeSegment;

public class SeparateArray extends CodeSegment{
	private WordConfig conf;
	
	SeparateArray(WordConfig conf){
		this.conf = conf;
	}
	
	@Override
	public void run() {	
		// cpu分だけTaskをあらかじめ作成
	 	int cpu_num = Runtime.getRuntime().availableProcessors();
	 	for (int cnt =0;cnt < cpu_num;cnt++){
	 		new WordCount();
	 	}
		BufferedReader br = null;
		int i = 0;
		try {
			br= new BufferedReader(
					new InputStreamReader(
							new FileInputStream(
									new File(conf.filename)
									)));
			int size = conf.division * 1024; // Kbyte
			Range range = new Range(size);
			int check = br.read(range.array);
			for (;check!=-1;i++){			
				char[] array;
				array = new char[size];
				check = br.read(array);
				range.nextchar = array[0];
				ods.put("array", range);
				range = new Range(array);
			} 
			new CorrectResult(i);
		} catch (FileNotFoundException e) {
			System.exit(1);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}