-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImgToFormattedString.java
More file actions
57 lines (48 loc) · 1.78 KB
/
ImgToFormattedString.java
File metadata and controls
57 lines (48 loc) · 1.78 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
50
51
52
53
54
55
56
57
import java.io.*;
public class ImgToFormattedString extends ImgToString{
private String formattedCode = new String();
private Format formatting = new Format();
private String outputType = new String();
// Constructor
public ImgToFormattedString(){};
public ImgToFormattedString(String filePathway){
this.filePathway = filePathway;
}
// Getter
public String getOutputType(){ return outputType; }
// Setter
public void setOutputType(String s){
if (s.equals(".java") || s.equals(".cpp"))
outputType = s;
else
System.out.println("Not .java or .cpp file. Use ImgToString class.");
return;
}
public void exportAs(){
// outfile is the name of the file to be downloaded from user
PrintWriter outfile = null;
// unformattedCode = textdetectionAPI.detectText(filePathway);
// formattedCode = formatting.formatText(unformattedCode);
try{
unformattedCode = textdetectionAPI.detectText(filePathway);
formattedCode = formatting.formatText(unformattedCode);
if (outputType.equals(".java")){
outfile = new PrintWriter("outfile.java");
} else if (outputType.equals(".cpp")){
outfile = new PrintWriter("outfile.cpp");
}
System.out.println(formattedCode);
for(char ch: unformattedCode.toCharArray()){
outfile.append(ch);
}
} catch (FileNotFoundException e){
System.out.println(e.toString());
} catch (Exception e){
System.out.println(" java is still being a bitch ");
} finally {
if (outfile != null){
outfile.close();
}
}
}
}