@Test public void testLocalFilesystem() throws Exception { final File tempdir = new File(temporaryFolder.getRoot(), UUID.randomUUID().toString()); final File testfile1 = new File(tempdir, UUID.randomUUID().toString()); final File testfile2 = new File(tempdir, UUID.randomUUID().toString()); final Path pathtotestfile1 = new Path(testfile1.toURI().getPath()); final Path pathtotestfile2 = new Path(testfile2.toURI().getPath()); final LocalFileSystem lfs = new LocalFileSystem(); final Path pathtotmpdir = new Path(tempdir.toURI().getPath()); assertFalse(lfs.exists(pathtotmpdir)); assertTrue(tempdir.mkdirs()); assertTrue(lfs.exists(pathtotmpdir)); final FileStatus localstatus1 = lfs.getFileStatus(pathtotmpdir); assertTrue(localstatus1.isDir()); final FileStatus[] statusforfiles = lfs.listStatus(pathtotmpdir); assertTrue(statusforfiles.length == 0); lfs.delete(pathtotmpdir, true); assertFalse(lfs.exists(pathtotmpdir)); assertFalse(tempdir.exists()); lfs.mkdirs(pathtotmpdir); assertTrue(tempdir.exists()); final FSDataOutputStream lfsoutput1 = lfs.create(pathtotestfile1, WriteMode.NO_OVERWRITE); assertTrue(testfile2.createNewFile()); assertTrue(testfile1.exists()); assertTrue(lfs.exists(pathtotestfile2)); final byte[] testbytes = { 1, 2, 3, 4, 5 }; lfsoutput1.write(testbytes); lfsoutput1.close(); assertEquals(testfile1.length(), 5L); byte[] testbytestest = new byte[5]; try (FileInputStream fisfile1 = new FileInputStream(testfile1)) { assertEquals(testbytestest.length, fisfile1.read(testbytestest)); } assertArrayEquals(testbytes, testbytestest); assertEquals(lfs.getFileStatus(pathtotestfile1).getLen(), testfile1.length()); assertEquals(lfs.listStatus(pathtotestfile1)[0].getLen(), testfile1.length()); final FileOutputStream fosfile2 = new FileOutputStream(testfile2); fosfile2.write(testbytes); fosfile2.close(); testbytestest = new byte[5]; final FSDataInputStream lfsinput2 = lfs.open(pathtotestfile2); assertEquals(lfsinput2.read(testbytestest), 5); lfsinput2.close(); assertTrue(Arrays.equals(testbytes, testbytestest)); assertEquals(lfs.listStatus(pathtotmpdir).length, 2); assertEquals(lfs.getFileBlockLocations(lfs.getFileStatus(pathtotestfile1), 0, 0).length, 1); assertTrue(lfs.delete(pathtotestfile1, false)); assertTrue(lfs.delete(pathtotmpdir, true)); assertTrue(!tempdir.exists()); }
public LocalFileSystem() { this.workingDir = new File(System.getProperty("user.dir")).toURI(); this.homeDir = new File(System.getProperty("user.home")).toURI(); String tmp = "unknownHost"; try { tmp = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { LOG.error("Could not resolve local host", e); } this.hostName = tmp; }
LocalFileSystem extends FileSystem { public LocalFileSystem() { this.workingDir = new File(System.getProperty("user.dir")).toURI(); this.homeDir = new File(System.getProperty("user.home")).toURI(); String tmp = "unknownHost"; try { tmp = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { LOG.error("Could not resolve local host", e); } this.hostName = tmp; } }
LocalFileSystem extends FileSystem { public LocalFileSystem() { this.workingDir = new File(System.getProperty("user.dir")).toURI(); this.homeDir = new File(System.getProperty("user.home")).toURI(); String tmp = "unknownHost"; try { tmp = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { LOG.error("Could not resolve local host", e); } this.hostName = tmp; } LocalFileSystem(); }
LocalFileSystem extends FileSystem { public LocalFileSystem() { this.workingDir = new File(System.getProperty("user.dir")).toURI(); this.homeDir = new File(System.getProperty("user.home")).toURI(); String tmp = "unknownHost"; try { tmp = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { LOG.error("Could not resolve local host", e); } this.hostName = tmp; } LocalFileSystem(); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override FileStatus getFileStatus(Path f); @Override URI getUri(); @Override Path getWorkingDirectory(); @Override Path getHomeDirectory(); @Override FSDataInputStream open(final Path f, final int bufferSize); @Override FSDataInputStream open(final Path f); @Override LocalRecoverableWriter createRecoverableWriter(); @Override boolean exists(Path f); @Override FileStatus[] listStatus(final Path f); @Override boolean delete(final Path f, final boolean recursive); @Override boolean mkdirs(final Path f); @Override FSDataOutputStream create(final Path filePath, final WriteMode overwrite); @Override boolean rename(final Path src, final Path dst); @Override boolean isDistributedFS(); @Override FileSystemKind getKind(); File pathToFile(Path path); static URI getLocalFsURI(); static LocalFileSystem getSharedInstance(); }
LocalFileSystem extends FileSystem { public LocalFileSystem() { this.workingDir = new File(System.getProperty("user.dir")).toURI(); this.homeDir = new File(System.getProperty("user.home")).toURI(); String tmp = "unknownHost"; try { tmp = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { LOG.error("Could not resolve local host", e); } this.hostName = tmp; } LocalFileSystem(); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override FileStatus getFileStatus(Path f); @Override URI getUri(); @Override Path getWorkingDirectory(); @Override Path getHomeDirectory(); @Override FSDataInputStream open(final Path f, final int bufferSize); @Override FSDataInputStream open(final Path f); @Override LocalRecoverableWriter createRecoverableWriter(); @Override boolean exists(Path f); @Override FileStatus[] listStatus(final Path f); @Override boolean delete(final Path f, final boolean recursive); @Override boolean mkdirs(final Path f); @Override FSDataOutputStream create(final Path filePath, final WriteMode overwrite); @Override boolean rename(final Path src, final Path dst); @Override boolean isDistributedFS(); @Override FileSystemKind getKind(); File pathToFile(Path path); static URI getLocalFsURI(); static LocalFileSystem getSharedInstance();  }