@Override public Committer closeForCommit() throws IOException { final long pos = getPos(); close(); return new LocalCommitter(new LocalRecoverable(targetFile, tempFile, pos)); }
@Override public FSDataInputStream open(final Path f) throws IOException { final File file = pathToFile(f); return new LocalDataInputStream(file); }
@Override public ResumeRecoverable persist() throws IOException { // we call both flush and sync in order to ensure persistence on mounted // file systems, like NFS, EBS, EFS, ... flush(); sync(); return new LocalRecoverable(targetFile, tempFile, getPos()); }
@Override public FileStatus getFileStatus(Path f) throws IOException { LocalFileStatus status = (LocalFileStatus) super.getFileStatus(f); return new LocalFileStatus(status.getFile(), this); }
@Override public FileStatus[] listStatus(Path f) throws IOException { FileStatus[] stati = super.listStatus(f); LocalFileStatus[] newStati = new LocalFileStatus[stati.length]; for (int i = 0; i < stati.length; i++) { newStati[i] = new LocalFileStatus(((LocalFileStatus) stati[i]).getFile(), this); } return newStati; }
/** * Gets the default file system URI that is used for paths and file systems * that do not specify and explicit scheme. * * <p>As an example, assume the default file system URI is set to {@code 'hdfs://someserver:9000/'}. * A file path of {@code '/user/USERNAME/in.txt'} is interpreted as * {@code 'hdfs://someserver:9000/user/USERNAME/in.txt'}. * * @return The default file system URI */ public static URI getDefaultFsUri() { return defaultScheme != null ? defaultScheme : LocalFileSystem.getLocalFsURI(); }
@Override public FileSystem create(URI fsUri) { return LocalFileSystem.getSharedInstance(); } }
@Override public FSDataInputStream open(final Path f, final int bufferSize) throws IOException { return open(f); }
@Override public RecoverableFsDataOutputStream open(Path filePath) throws IOException { final File targetFile = fs.pathToFile(filePath); final File tempFile = generateStagingTempFilePath(targetFile); // try to create the parent final File parent = tempFile.getParentFile(); if (parent != null && !parent.mkdirs() && !parent.exists()) { throw new IOException("Failed to create the parent directory: " + parent); } return new LocalRecoverableFsDataOutputStream(targetFile, tempFile); }
@Override public void seek(long desired) throws IOException { if (desired != getPos()) { this.fileChannel.position(desired); } }
@Override public boolean exists(Path f) throws IOException { final File path = pathToFile(f); return path.exists(); }
@Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { return new BlockLocation[] { new LocalBlockLocation(hostName, file.getLen()) }; }
@Override public LocalRecoverableWriter createRecoverableWriter() throws IOException { return new LocalRecoverableWriter(this); }
@Override public Committer recoverForCommit(CommitRecoverable recoverable) throws IOException { if (recoverable instanceof LocalRecoverable) { return new LocalRecoverableFsDataOutputStream.LocalCommitter((LocalRecoverable) recoverable); } else { throw new IllegalArgumentException( "LocalFileSystem cannot recover recoverable for other file system: " + recoverable); } }
@Override public RecoverableFsDataOutputStream recover(ResumeRecoverable recoverable) throws IOException { if (recoverable instanceof LocalRecoverable) { return new LocalRecoverableFsDataOutputStream((LocalRecoverable) recoverable); } else { throw new IllegalArgumentException( "LocalFileSystem cannot recover recoverable for other file system: " + recoverable); } }
@Override public LocalRecoverable deserialize(int version, byte[] serialized) throws IOException { switch (version) { case 1: return deserializeV1(serialized); default: throw new IOException("Unrecognized version or corrupt state: " + version); } }
@Override public FileSystem getFileSystem() throws Exception { return LocalFileSystem.getSharedInstance(); }
@Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { streamOpenCounter++; return super.open(f, bufferSize); }
/** * Returns a reference to the {@link FileSystem} instance for accessing the local file system. * * @return a reference to the {@link FileSystem} instance for accessing the local file system. */ public static FileSystem getLocalFileSystem() { return FileSystemSafetyNet.wrapWithSafetyNetWhenActivated(LocalFileSystem.getSharedInstance()); }
@Override public FSDataInputStream open(Path f) throws IOException { streamOpenCounter++; return super.open(f); }