-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomWriter.java
More file actions
49 lines (40 loc) · 1.32 KB
/
Copy pathRandomWriter.java
File metadata and controls
49 lines (40 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.Scanner;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Hashtable;
import java.util.Set;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Dictionary;
public class RandomWriter {
public static String getText(String source) throws FileNotFoundException { //get source text into one String
File input = new File(source);
Scanner sc = new Scanner(input);
String text = "";
while (sc.hasNextLine()) {
text = text + sc.nextLine() + "\n";
}
sc.close();
return text;
}
public static String write(String source, int seedLength, int length) throws FileNotFoundException {
//int length = Integer.parseInt(args[1]);
//String result = args[3];
String text = getText(source);
String returnString = "";
CharGenerator generator = new CharGenerator(text, seedLength);
ArrayList<Character> nextsArray = generator.getProbableNexts();
returnString += (generator.charSeed + "@");
for(int i = 0; i < length; i++) {
char nextChar = generator.getNextChar(nextsArray);
returnString += (nextChar);
generator.charSeed.add(nextChar);
generator.charSeed.remove(0);
//System.out.println(generator.charSeed);
nextsArray = generator.getProbableNexts();
}
return returnString;
}
}