### Question:
FileSystemUtil { public static boolean fileExists(@Nonnull final URI uri, @Nonnull final Configuration conf) throws IOException { final URI hadoopUri; if ("hadoop".equals(uri.getScheme())) { try { hadoopUri = new URI(uri.getSchemeSpecificPart()); } catch (final URISyntaxException e) { throw new IOException("Not a valid hadoop URI: " + uri); } } else { hadoopUri = uri; } switch (hadoopUri.getScheme()) { case "file": log.debug("Checking local path exists: {}", hadoopUri); return new File(hadoopUri).exists(); case "hdfs": log.debug("Checking HDFS path exists: {}", hadoopUri); try { return FileSystem.get(hadoopUri, conf).exists(new Path(hadoopUri)); } catch (final IOException e) { log.debug("Unable to read HDFS path: {}", hadoopUri, e); return true; } default: throw new IOException("Not a supported scheme: " + hadoopUri.getScheme()); } } private  FileSystemUtil(); static boolean fileExists(@Nonnull final URI uri, @Nonnull final Configuration conf); @Nonnull static URL parseUrl(@Nonnull final String s, @Nullable final Configuration conf); static void registerFileSystems(@Nonnull final Iterable<FileSystem> fileSystems, @Nonnull final Configuration conf);  }### Answer:
@Test public void fileExistsHdfs() throws IOException { final Configuration conf = new Configuration(false); conf.setClass("fs.hdfs.impl", MockFileSystem.class, FileSystem.class); final File file = File.createTempFile("kylo-", ".tmp"); try { Assert.assertTrue("Expected HDFS file to exist", FileSystemUtil.fileExists(URI.create("hdfs:" + file.getAbsolutePath()), conf)); Assert.assertTrue("Expected HDFS file to exist", FileSystemUtil.fileExists(URI.create("hadoop:hdfs:" + file.getAbsolutePath()), conf)); } finally { Files.delete(file.toPath()); } }
@Test public void fileExistsLocal() throws IOException { final File file = File.createTempFile("kylo-", ".tmp"); try { Assert.assertTrue("Expected local file to exist", FileSystemUtil.fileExists(file.toURI(), new Configuration(false))); } finally { Files.delete(file.toPath()); } }
@Test(expected = IOException.class) public void fileExistsOther() throws IOException { final Configuration conf = new Configuration(false); conf.setClass("fs.mock.impl", MockFileSystem.class, FileSystem.class); FileSystemUtil.fileExists(URI.create("mock:/tmp/" + UUID.randomUUID().toString()), conf); }