AdeFileUtils { public static BufferedReader openLogFile(File file) throws AdeUsageException { BufferedReader logReader; final String fileName = file.getPath(); try { if (file.getName().endsWith(ZIP)) { logReader = new BufferedReader(new InputStreamReader( new GZIPInputStream(new FileInputStream(fileName)), StandardCharsets.UTF_8)); } else { logReader = new BufferedReader(new InputStreamReader( new FileInputStream(fileName), StandardCharsets.UTF_8)); } } catch (IOException e) { throw new AdeUsageException("Failed opening file " + fileName + ": " , e); } return logReader; } private  AdeFileUtils(); static void copyFile(File source, File target); static BufferedReader openLogFile(File file); static InputStream openLogFileAsInputStream(File file); static void deleteFile(File file); static void deleteFileOrLog(File file); static void createDir(File target); static void createDirs(File target); static boolean deleteRecursiveOrLog(File path);  }
@Test public void testOpenLogFile() throws AdeUsageException { final BufferedReader reader = AdeFileUtils.openLogFile(testFile); assertNotNull("Verify that the reader is not null.", reader); }
@Test public void testOpenLogFileGZipFile() throws AdeUsageException, IOException { final File targetFile = temporaryFolder.newFile("file.gz"); final FileOutputStream out = new FileOutputStream(targetFile); final GZIPOutputStream gos = new GZIPOutputStream(out); gos.write(text.getBytes(StandardCharsets.UTF_8)); gos.close(); BufferedReader reader = AdeFileUtils.openLogFile(targetFile); assertNotNull("Verify that the reader is not null.", reader); String unzippedText = reader.readLine(); assertEquals("The unzipped text should be exactly the same as the source.", text, unzippedText); }
@Test(expected = AdeUsageException.class) public void testOpenLogFileBadGZipFile() throws AdeUsageException, IOException { final File targetFile = temporaryFolder.newFile("file.gz"); AdeFileUtils.openLogFile(targetFile); }