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;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.FileReader;
/**
* @author Nicolás A. Ortega
* @copyright Nicolás A. Ortega
@ -10,50 +15,65 @@ package coffeebreak;
*
*/
public class CoffeeBreak {
public static final String usage = "Usage: coffeebreak [compiler]";
public String[] compilers = {"gcc", "g++", "clang++", "javac", "ant"};
private static final String version = "v0.1";
private static final String usage = "Usage: coffeebreak [-h | --help | -v | -c | -w | -f <file>]";
public CoffeeBreak(String compiler) {
int compid = -1;
compilerLoop:
for(int i = 0; i < compilers.length; i++) {
if(compiler.equals(compilers[i])) {
compid = i;
break compilerLoop;
// Constructor:
public CoffeeBreak(String filepath) {
String line;
while(true) {
try {
BufferedReader br = new BufferedReader(new FileReader(filepath));
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) {
if(args.length != 1) {
System.out.println("Invalid number of arguments.\n" + usage);
if(args.length == 2) {
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;
}
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
}
}