File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
typesummary/app/src/main/java/typesummary Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 1919import com .google .common .reflect .ClassPath ;
2020
2121public class App {
22+ // -o absolutepathpath.txt to output to text file instead of console
2223 public static void main (String [] args ) throws Exception {
2324 final String [] mNames = { //those are default java language methods that every object will have
2425 "equals" ,
@@ -30,13 +31,19 @@ public static void main(String[] args) throws Exception {
3031 "wait"
3132 };
3233 methodsNameToSkip = Arrays .asList (mNames );
33- final ILogWriter writer = new ConsoleLogWriter ();
34+ final Boolean isFileMode = args .length > 0 && args [0 ].equals ("-o" );
35+
36+ final ILogWriter writer = isFileMode ? new TextFileLogWriter (args [1 ]) : new ConsoleLogWriter ();
3437
3538
3639 final List <String > classNames = getOrderedClassNames ();
3740 serializeEnums (writer , classNames );
3841 serializeClasses (writer , classNames );
3942 serializeInterfaces (writer , classNames );
43+
44+ if (isFileMode ) {
45+ ((TextFileLogWriter )writer ).flush ();
46+ }
4047 }
4148 private static void serializeEnums (final ILogWriter writer , final List <String > classNames ) throws Exception {
4249 for (String c : classNames ) {
Original file line number Diff line number Diff line change 1+ package typesummary ;
2+
3+ import java .lang .StringBuilder ;
4+ import com .google .common .base .Charsets ;
5+
6+ import com .google .common .io .Files ;
7+ import java .io .File ;
8+ import java .io .IOException ;
9+
10+ public class TextFileLogWriter implements ILogWriter {
11+ private String filePath ;
12+ private StringBuilder builder = new StringBuilder ();
13+ public TextFileLogWriter (final String filePath ) {
14+ this .filePath = filePath ;
15+ }
16+ public void write (final String content ) {
17+ write (content , 0 );
18+ }
19+ public void write (final String content , final int indent ) {
20+ String indentTxt = "" ;
21+ for (int i = 0 ; i <= indent ; i ++) {
22+ indentTxt += " " ;
23+ }
24+ this .builder .append (indentTxt + content + "\r \n " );
25+ }
26+ public void flush () throws IOException {
27+ File file = new File (this .filePath );
28+ Files .write (builder , file , Charsets .UTF_8 );
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments