Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
Corrected bug where stdout was not restored when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeo Kheng Meng committed Nov 27, 2013
1 parent 0b64ad5 commit 6eb3f5c
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions docs-to-pdf-converter/src/MainClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public enum DOC_TYPE {
PPT,
PPTX
}

private static PrintStream originalStdout = null;


public static void main(String[] args){
Expand All @@ -25,17 +27,26 @@ public static void main(String[] args){
try{
converter = processArguments(args);
} catch ( IllegalArgumentException e){
if(originalStdout != null) {
System.setOut(originalStdout);
}
System.out.println("\n\nInput file not specified.");
return;
}


if(converter == null){
if(originalStdout != null) {
System.setOut(originalStdout);
}
System.out.println("Unable to determine type of input file.");
} else {
try {
converter.convert();
} catch (Exception e) {
if(originalStdout != null) {
System.setOut(originalStdout);
}
e.printStackTrace();
}
}
Expand Down Expand Up @@ -73,13 +84,6 @@ public static Converter processArguments(String[] args) throws IllegalArgumentEx
outPath = changeExtensionToPDF(inPath);
}

if(!shouldShowMessages){
System.setOut(new PrintStream(new OutputStream() {
public void write(int b) {
//DO NOTHING
}
}));
}

if(values.type == null){
if(inPath.endsWith("doc")){
Expand Down Expand Up @@ -113,6 +117,16 @@ public void write(int b) {


}

if(!shouldShowMessages){
originalStdout = System.out;

System.setOut(new PrintStream(new OutputStream() {
public void write(int b) {
//DO NOTHING
}
}));
}

} catch (CmdLineException e) {
// handling of wrong arguments
Expand Down

0 comments on commit 6eb3f5c

Please sign in to comment.