-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTranscoder.java
69 lines (57 loc) · 1.79 KB
/
Transcoder.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.Scanner;
import Tokens.ClassToken;
import java.io.*;
/**
* @author Keenan Leverty
* @author Peter Matern
* @author Chris Allender
*
*/
public class Transcoder {
ClassToken startingToken;
/**
* Creates a new Transcoder starting with the class token
* @param input string containing input
*/
Transcoder(String input) {
startingToken = new ClassToken(input);
}
@Override
public String toString() {
return startingToken.toString();
}
/**
* Run the program. Prompt the user for the file path of the java file to be trascoded.
*
* @param args
*/
public static void main(String[] args) {
String inputPath = "";
String input = "";
Scanner in = new Scanner(System.in);
System.out.println("Enter the file path to be trascoded:\n");
inputPath = in.nextLine();
in.close();
try {
File file = new File(inputPath);
Scanner sc = new Scanner(file);
while (sc.hasNextLine()) {
input += sc.nextLine();
}
sc.close();
} catch (FileNotFoundException e) {
System.out.println("ERROR: " + e.getMessage()); // Could not find the file
}
// new Transcoder
Transcoder tr = new Transcoder(input);
try {
String outputPath = inputPath.replaceAll(".java", ".py");
BufferedWriter writer = new BufferedWriter(new FileWriter(outputPath));
writer.write(tr.toString());
writer.close();
System.out.println("\nThe file was successfully transcoded");
} catch (IOException e) {
System.out.println("ERROR: " + e.getMessage()); // Could not create output file
}
}
}