View Javadoc

1   /*
2    * Copyright (c) 2004 International Decision Systems, Inc.  All Rights Reserved.
3    *
4    * By using this Software, You acknowledge that the Software is a valuable asset
5    * and trade secret of either International Decision Systems, Inc. ("IDSI") or a
6    * third party supplier of IDSI and constitutes confidential and proprietary
7    * information.
8    *
9    * NEITHER IDSI NOR ANY AGENT OR PERSON ACTING FOR OR WITH IDSI HAS MADE OR DOES
10   * MAKE ANY STATEMENTS, AFFIRMATIONS, REPRESENTATIONS OR WARRANTIES WHATSOEVER
11   * TO YOU, WHETHER EXPRESS OR IMPLIED, AS TO THE SOFTWARE, THE QUALITY OR
12   * CONDITION OF THE SOFTWARE, OR THE OPERATING CHARACTERISTICS OR RELIABILITY OF
13   * THE SOFTWARE, OR ITS SUITABILITY FOR ANY GENERAL OR PARTICULAR PURPOSE, OR AS
14   * TO ANY OTHER MATTER WHATSOEVER; ANY AND ALL OTHER WARRANTIES INCLUDING
15   * WITHOUT LIMITATION ANY WARRANTIES IMPLIED BY LAW, SUCH AS THE IMPLIED
16   * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND TITLE,
17   * USE AND NON-INFRINGEMENT; ARE HEREBY EXPRESSLY DISCLAIMED AND EXCLUDED.
18  */
19  package net.sourceforge.addam.ddlrun.utils;
20  
21  import java.io.*;
22  import java.util.MissingResourceException;
23  
24  /**
25   * Used to read resources from within the local FileSystem.
26   *
27   * @author TIM3
28   * @since Mar 5, 2005
29   */
30  public class FileSystemReader implements ResourceReader {
31  
32      /**
33       * Allows only the FileSystemReaderFactory to construct a FileSystemReader.
34       *
35       * @param resourceFile the file to read from
36       */
37      FileSystemReader(File resourceFile) {
38          this.resourceFile = resourceFile;
39      }
40  
41      public String readLine() throws IOException {
42          return this.getReader().readLine();
43      }
44  
45      private BufferedReader getReader() {
46          if (reader == null) {
47              try {
48                  reader = new BufferedReader(new FileReader(resourceFile));
49              } catch (FileNotFoundException e) {
50                  throw new MissingResourceException("FileSystemReader unable to locate resource " + resourceFile,
51                          FileSystemReader.class.getName(), resourceFile.toString());
52              }
53          }
54          return reader;
55      }
56  
57      private BufferedReader reader;
58      final File resourceFile; // not private in order to facilitate testing
59  }