import java.io.*;


/**
 * Archives one or more lines to a file
 * named "archive.txt"
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 3.0
 */
public class LineArchiver implements LineObserver
{
    PrintWriter         out;


    /**
     * Default Constructor
     */
    public LineArchiver() throws IOException
    {
       out = new PrintWriter(new FileOutputStream("archive.txt"));
    }


    /**
     * Close the archiver
     */
    public void close() throws IOException
    {
       out.flush();
       out.close();
    }


    /**
     * Handle a line of text
     */
    public void handleLine(LineSubject source)
    {
       String     line;

       try 
       {
          line = source.getLine();
          save(line);
       } 
       catch (IOException ioe) 
       {
          // Ignore
       }
    }


    /**
     * Save a line in the archive
     *
     * @param line   The line to save
     */
    private void save(String line) throws IOException
    {
       out.println(line);
    }
}
