FileUtils { public static InputStream open(final Path file, FileSystem fileSystem) throws IOException { fileSystem = FileUtils.ensureFileSystem(file, fileSystem); InputStream inputStream = fileSystem.open(file); InflaterInputStreamFactory<?> factory = findInflaterInputStreamFactory(file); if (factory != null) { inputStream = factory.create(inputStream); } return inputStream; } private  FileUtils(); static List<Path> gatherFiles(final int depth,
                                         final String... inputPaths); static Path[] createPaths(final String... pathStrings); static List<Path> gatherFiles(final int depth,
                                         final Path... inputPaths); static Path ensureEmptyDirectory(final Path parentPath,
                                            final String name, final FileSystem fs); static void ensureEmptyDirectory(final Path path, FileSystem fs); static FileSystem ensureFileSystem(final Path path,
                                              final FileSystem fs); static boolean remove(final Path file, final boolean recursive); static InputStream open(final Path file, FileSystem fileSystem); static InflaterInputStreamFactory<?> findInflaterInputStreamFactory(Path file); static Path findCommonParentPath(Path path1, Path path2); static String findCommonParent(Collection<String> filePaths); static String extractExtension(final Path file); static Encoding detectEncoding(final Path file, FileSystem fileSystem, Encoding fallback,
                                          Reference<InputStream> gnawedInputStreamReference);  }
@Test public void testOpenGzippedFile() throws URISyntaxException, IOException { Path path = new Path(getClass().getResource("/test.csv.gz").toURI().toString()); try (InputStream in = FileUtils.open(path, null)) { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String firstLine = reader.readLine(); Assert.assertEquals("a;1;100;1;\"John Doe\"", firstLine); } ; }
@Test public void testOpenRegularFile() throws URISyntaxException, IOException { Path path = new Path(getClass().getResource("/test.csv").toURI().toString()); try (InputStream in = FileUtils.open(path, null)) { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String firstLine = reader.readLine(); Assert.assertEquals("a;1;100;1;\"John Doe\"", firstLine); } ; }