AdeFileUtils { public static InputStream openLogFileAsInputStream(File file) throws AdeUsageException { final String fileName = file.getPath(); try { if (file.getName().endsWith(ZIP)) { return new BufferedInputStream( new GZIPInputStream(new FileInputStream(fileName))); } else { return new BufferedInputStream(new FileInputStream(fileName)); } } catch (IOException e) { throw new AdeUsageException("Failed opening file " + fileName + ": " , e); } } 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 testOpenLogFileAsInputStream() throws AdeUsageException { final InputStream inputStream = AdeFileUtils.openLogFileAsInputStream(testFile); assertNotNull("Verify that inputStream is not null.", inputStream); }
@Test public void testOpenLogFileAsInputStreamGZipFile() 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(); final InputStream inputStream = AdeFileUtils.openLogFileAsInputStream(targetFile); assertNotNull("Verify that inputStream is not null.", inputStream); }
@Test(expected = AdeUsageException.class) public void testOpenLogFileAsInputStreamBadGZipFile() throws AdeUsageException, IOException { final File targetFile = temporaryFolder.newFile("file.gz"); AdeFileUtils.openLogFileAsInputStream(targetFile); }