CoffeeBreak will read a file and print its contents every 2 seconds.

This commit is contained in:
Deathsbreed 2014-11-15 15:21:38 -06:00
parent 0abdaefe39
commit 67f880fe44

View File

@ -1,5 +1,10 @@
package coffeebreak; package coffeebreak;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.FileReader;
/** /**
* @author Nicolás A. Ortega * @author Nicolás A. Ortega
* @copyright Nicolás A. Ortega * @copyright Nicolás A. Ortega
@ -10,50 +15,65 @@ package coffeebreak;
* *
*/ */
public class CoffeeBreak { public class CoffeeBreak {
public static final String usage = "Usage: coffeebreak [compiler]"; private static final String version = "v0.1";
public String[] compilers = {"gcc", "g++", "clang++", "javac", "ant"}; private static final String usage = "Usage: coffeebreak [-h | --help | -v | -c | -w | -f <file>]";
public CoffeeBreak(String compiler) { // Constructor:
int compid = -1; public CoffeeBreak(String filepath) {
compilerLoop: String line;
for(int i = 0; i < compilers.length; i++) { while(true) {
if(compiler.equals(compilers[i])) { try {
compid = i; BufferedReader br = new BufferedReader(new FileReader(filepath));
break compilerLoop; try {
while((line = br.readLine()) != null) {
System.out.println(line);
try {
Thread.sleep(2000);
} catch(InterruptedException e) { System.out.println("Error waiting."); }
}
br.close();
} catch(IOException e) {
System.out.println("Error with reading from file.");
System.exit(1);
}
} catch(FileNotFoundException e) {
System.out.println("Cannot find file.");
System.exit(1);
} }
} }
if(compid == -1) {
System.out.println("This compiler is not supported. Add it!!!");
return;
}
System.out.println("You chose compiler " + compiler);
}
public void compileGCC() {
}
public void compileGXX() {
}
public void compileCLANGXX() {
}
public void compileJAVAC() {
}
public void compileANT() {
} }
// Main:
public static void main(String[] args) { public static void main(String[] args) {
if(args.length != 1) { if(args.length == 2) {
System.out.println("Invalid number of arguments.\n" + usage); if(args[0].equals("-f")) new CoffeeBreak(args[1]);
else System.out.println("Invalid argument '" + args[0] + "'.\n" + usage);
} else if(args.length == 1) {
if(args[0].equals("-h") || args[0].equals("--help")) printHelpInfo();
else if(args[0].equals("-v")) System.out.println("CoffeeBreak " + version);
else if(args[0].equals("-c")) printCopyrightInfo();
else if(args[0].equals("-w")) printWarrantyInfo();
else System.out.println("Invalid argument '" + args[0] + "'.\n" + usage);
} else {
System.out.println("Invalid number of arguments.");
return; return;
} }
new CoffeeBreak(args[0]); }
private static void printHelpInfo() {
System.out.println(usage +
"\n -h or --help -- Print this help information." +
"\n -v -- Print version." +
"\n -c -- Print copyright information." +
"\n -w -- Print warranty information." +
"\n -f <file> -- File to read from.");
}
private static void printCopyrightInfo() {
// TODO
}
private static void printWarrantyInfo() {
// TODO
} }
} }