SharedFileResource extends BaleenResource { public static String[] readFileLines(File file) throws IOException { List<String> lines = new LinkedList<>(); try (Stream<String> stream = Files.lines(file.toPath())) { stream.forEach(l -> lines.add(StringUtils.strip(l.replaceAll("\r\n", "\n")))); } while (StringUtils.strip(lines.get(0)).isEmpty()) { lines.remove(0); } while (StringUtils.strip(lines.get(lines.size() - 1)).isEmpty()) { lines.remove(lines.size() - 1); } return lines.toArray(new String[lines.size()]); }  static String readFile(File file); static String[] readFileLines(File file);  }
@Test public void testReadFileLines() throws Exception { String[] lines = SharedFileResource.readFileLines(new File(getClass().getResource("test.txt").toURI())); assertEquals(3, lines.length); assertEquals("This is my test file.", lines[0]); assertEquals("", lines[1]); assertEquals("It has lots of whitespace in it!", lines[2]); try { SharedFileResource.readFileLines(new File("missing.txt")); fail("Expected an exception"); } catch (IOException ioe) { } }