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

Commit

Permalink
Removed legacy variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeo Kheng Meng committed Dec 1, 2013
1 parent 52c2f0c commit 37235d9
Showing 1 changed file with 29 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,56 @@

public abstract class Converter {

private final String LOADING_FORMAT = "\nLoading file \"%1$s\"\n\n";

private final String LOADING_FORMAT = "\nLoading stream\n\n";
private final String PROCESSING_FORMAT = "Load completed in %1$dms, now converting...\n\n";
private final String SAVING_FORMAT = "Conversion to \"%1$s\" took %2$dms.\n\nTotal: %3$dms\n";
private final String SAVING_FORMAT = "Conversion took %1$dms.\n\nTotal: %2$dms\n";

private long startTime;
private long startOfProcessTime;

protected String inputFilePath;
protected String outputFilePath;


protected InputStream inStream;
protected OutputStream outStream;

protected boolean showOutputMessages = false;
protected boolean closeStreamsWhenComplete = true;

public Converter(InputStream inStream, OutputStream outStream, boolean showMessages, boolean closeStreamsWhenComplete){
this.inStream = inStream;
this.outStream = outStream;
this.showOutputMessages = showMessages;
this.closeStreamsWhenComplete = closeStreamsWhenComplete;
}

// public Converter(String inputFilePath, String outputFilePath, boolean showMessages, boolean closeStreamsWhenComplete) throws IOException {
// inStream = getInFileStream(inputFilePath);
// outStream = getOutFileStream(outputFilePath);
// this.showOutputMessages = showMessages;
//
// inputFilePath = inStream.toString();
// outputFilePath = outStream.toString();
// this.closeStreamsWhenComplete = closeStreamsWhenComplete;
// }



public abstract void convert() throws Exception;

private void startTime(){
startTime = System.currentTimeMillis();
startOfProcessTime = startTime;
}

protected void loading(){
printMessages(String.format(LOADING_FORMAT, inputFilePath));
printMessages(String.format(LOADING_FORMAT));
startTime();
}

protected void processing(){
long currentTime = System.currentTimeMillis();
long prevProcessTook = currentTime - startOfProcessTime;

printMessages(String.format(PROCESSING_FORMAT, prevProcessTook));

startOfProcessTime = System.currentTimeMillis();

}

protected void finished(){
long currentTime = System.currentTimeMillis();
long timeTaken = currentTime - startTime;
long prevProcessTook = currentTime - startOfProcessTime;

startOfProcessTime = System.currentTimeMillis();

if(closeStreamsWhenComplete){
try {
inStream.close();
Expand All @@ -79,22 +65,22 @@ protected void finished(){
//Nothing done
}
}
printMessages(String.format(SAVING_FORMAT, outputFilePath, prevProcessTook, timeTaken));

printMessages(String.format(SAVING_FORMAT, prevProcessTook, timeTaken));
}


protected void printMessages(String toBePrinted){
if(showOutputMessages){
System.out.println(toBePrinted);
}
}








}

0 comments on commit 37235d9

Please sign in to comment.