Skip to content

Package: FileReader

FileReader

nameinstructionbranchcomplexitylinemethod
read(String)
M: 7 C: 35
83%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 2 C: 8
80%
M: 0 C: 1
100%

Coverage

1: /**
2: *
3: */
4: package reader;
5:
6: import java.io.File;
7: import java.io.FileInputStream;
8: import java.io.IOException;
9:
10: /**
11: * @author Phil
12: *
13: */
14: public final class FileReader {
15:         /**
16:          * private constructor.
17:          */
18:         private FileReader() {
19:         }
20:
21:         /**
22:          * Reads the file in the given part and returns a string representation.
23:          *
24:          * @param pathToRead
25:          * The path to read.
26:          * @throws ReaderException
27:          * If the Reader causes an exception.
28:          * @return Returns a string representation of the file.
29:          */
30:         public static String read(final String pathToRead) throws ReaderException {
31:                 final StringBuffer input = new StringBuffer();
32:                 try {
33:                         final FileInputStream in = new FileInputStream(new File(pathToRead));
34:                         try {
35:•                                for (int n = in.read(); n != -1; n = in.read()) {
36:                                         final char c = (char) n;
37:                                         input.append(c);
38:                                 }
39:                         } finally {
40:                                 in.close();
41:                         }
42:                 } catch (final IOException ioEx) {
43:                         throw new ReaderException(basic.ReaderConstants.READEXCEPTION, ioEx);
44:
45:                 }
46:
47:                 return input.toString();
48:
49:         }
50: }