001package edu.pdx.cs410J.apptbook; 002 003import edu.pdx.cs410J.AppointmentBookParser; 004import edu.pdx.cs410J.ParserException; 005 006import java.io.BufferedReader; 007import java.io.FileReader; 008import java.io.IOException; 009import java.io.Reader; 010 011/** 012 * A skeletal implementation of the <code>TextParser</code> class for Project 2. 013 */ 014public class TextParser implements AppointmentBookParser<AppointmentBook> { 015 private final Reader reader; 016 017 public TextParser(Reader reader) { 018 this.reader = reader; 019 } 020 021 @Override 022 public AppointmentBook parse() throws ParserException { 023 try ( 024 BufferedReader br = new BufferedReader(this.reader) 025 ) { 026 027 String owner = br.readLine(); 028 029 if (owner == null) { 030 throw new ParserException("Missing owner"); 031 } 032 033 return new AppointmentBook(owner); 034 035 } catch (IOException e) { 036 throw new ParserException("While parsing appointment book text", e); 037 } 038 } 039}