
package quote;

import java.io.*;
import java.net.*;
import java.util.*;

public class QuoteImpl implements QuoteIF {

protected BufferedReader in = null;

    public String getQuote() {
        return getNextQuote();
    }

    public QuoteImpl() 
	//throws IOException
    {
        super();

        try {
	    // Change this to a directory where the one-liners.txt file exists!
	    in = new BufferedReader(new FileReader("C:\\PROFILES\\CSUser\\My Documents\\Carlos Varela\\one-liners.txt"));
        } catch (FileNotFoundException e) {
            System.err.println("Could not open quote file. Serving time instead."+e);
        }
    }

    protected String getNextQuote() {

	// figure out response
	if (in == null)
	    {
		System.err.println(new Date());
		return new Date().toString();
	    }

	else {
	
	    String returnValue = null;
	    try {
		if ((returnValue = in.readLine()) == null) {
		    in.close();
		    returnValue = "No more quotes. Goodbye.";
		}
	    } catch (IOException e) {
		returnValue = "IOException occurred in server.";
	    }
	    return returnValue;
	}
    }
}

