Configuration configuration = new Configuration(); FileSystem hdfs = FileSystem.get( new URI( "hdfs://localhost:54310" ), configuration ); Path file = new Path("hdfs://localhost:54310/s2013/batch/table.html"); if ( hdfs.exists( file )) { hdfs.delete( file, true ); } OutputStream os = hdfs.create( file, new Progressable() { public void progress() { out.println("...bytes written: [ "+bytesWritten+" ]"); } }); BufferedWriter br = new BufferedWriter( new OutputStreamWriter( os, "UTF-8" ) ); br.write("Hello World"); br.close(); hdfs.close();
public File(File parent, String child) { if (child == null) throw new NullPointerException(); if (parent != null) { this.path = fs.resolve(parent.path.equals("") ? fs.getDefaultParent() : parent.path, fs.normalize(child)); } else { this.path = fs.normalize(child); } this.prefixLength = fs.prefixLength(this.path); }
public File(URI uri) { if (!uri.isAbsolute()) throw new IllegalArgumentException("URI is not absolute"); if (uri.isOpaque()) throw new IllegalArgumentException("URI is not hierarchical"); String scheme = uri.getScheme(); if ((scheme == null) || !scheme.equalsIgnoreCase("file")) throw new IllegalArgumentException("URI scheme is not \"file\""); if (uri.getAuthority() != null) throw new IllegalArgumentException("URI has an authority component"); if (uri.getFragment() != null) throw new IllegalArgumentException("URI has a fragment component"); if (uri.getQuery() != null) throw new IllegalArgumentException("URI has a query component"); String p = uri.getPath(); if (p.equals("")) throw new IllegalArgumentException("URI path component is empty"); p = fs.fromURIPath(p); if (File.separatorChar != '/') p = p.replace('/', File.separatorChar); this.path = fs.normalize(p); this.prefixLength = fs.prefixLength(this.path); }
/** * The FileSystem object representing the platform's local file system. */ private static final FileSystem fs = DefaultFileSystem.getFileSystem(); // Snip. public File(File parent, String child) { if (child == null) { throw new NullPointerException(); } if (parent != null) { if (parent.path.equals("")) { this.path = fs.resolve(fs.getDefaultParent(), fs.normalize(child)); } else { this.path = fs.resolve(parent.path, fs.normalize(child)); } } else { this.path = fs.normalize(child); } this.prefixLength = fs.prefixLength(this.path); }
public File(String pathname) { if (pathname == null) throw new NullPointerException(); this.path = fs.normalize(pathname); this.prefixLength = fs.prefixLength(this.path); }
public String getCanonicalPath() throws IOException { if (isInvalid()) throw new IOException("Invalid file path"); return fs.canonicalize(fs.resolve(this)); }
public static File createTempFile(String prefix, String suffix, File directory) throws IOException { if (prefix.length() < 3) throw new IllegalArgumentException("Prefix string too short"); if (suffix == null) suffix = ".tmp"; File tmpdir = (directory != null) ? directory : TempDirectory.location(); File f; do { f = TempDirectory.generateFile(prefix, suffix, tmpdir); } while ((fs.getBooleanAttributes(f) & FileSystem.BA_EXISTS) != 0); if (!fs.createFileExclusively(f.getPath())) throw new IOException("Unable to create temporary file"); return f; }
public String getAbsolutePath() { return fs.resolve(this); }
Job job = new Job(getConf()); //... //your job setup, including the output config job.setOutputKeyClass(Text.class); job.setOutputValueClass(NullWritable.class); //... boolean success = job.waitForCompletion(true); if (success){ FileSystem hdfs = FileSystem.get(getConf()); FileStatus fs[] = hdfs.listStatus(new Path(outputPath)); if (fs != null){ for (FileStatus aFile : fs) { if (!aFile.isDir()) { hdfs.rename(aFile.getPath(), new Path(aFile.getPath().toString()+".csv")); } } } }
public File getAbsoluteFile() { String absPath = getAbsolutePath(); return new File(absPath, fs.prefixLength(absPath)); }
public boolean canWrite() { if (isInvalid()) return false; return fs.checkAccess(this, FileSystem.ACCESS_WRITE); }
public int compareTo(File pathname) { return fs.compare(this, pathname); }
public boolean mkdir() { if (isInvalid()) return false; return fs.createDirectory(this); }
public boolean createNewFile() throws IOException { if (isInvalid()) throw new IOException("Invalid file path"); return fs.createFileExclusively(path); }
fakeFtpServer = new FakeFtpServer(); fakeFtpServer.setServerControlPort(FTPPORT); FileSystem fileSystem = new UnixFakeFileSystem(); fileSystem.add(new DirectoryEntry(FTPDIRECTORY)); fakeFtpServer.setFileSystem(fileSystem); fakeFtpServer.addUserAccount(new UserAccount(USERNAME, PASSWORD, FTPDIRECTORY)); ... assertTrue("Expected file to be transferred", fakeFtpServer.getFileSystem().exists(FTPDIRECTORY + "/" + FILENAME));
public File(String parent, String child) { if (child == null) throw new NullPointerException(); if (parent != null) { this.path = fs.resolve(parent.equals("") ? fs.getDefaultParent() : fs.normalize(parent), fs.normalize(child)); } else { this.path = fs.normalize(child); } this.prefixLength = fs.prefixLength(this.path); }
private File(String child, File parent) { assert parent.path != null; assert (!parent.path.equals("")); this.path = fs.resolve(parent.path, child); this.prefixLength = parent.prefixLength; }
public boolean renameTo(File dest) { if (dest == null) throw new NullPointerException(); if (this.isInvalid() || dest.isInvalid()) return false; return fs.rename(this, dest); }
public File getCanonicalFile() throws IOException { String canonPath = getCanonicalPath(); return new File(canonPath, fs.prefixLength(canonPath)); }
public boolean canExecute() { if (isInvalid()) return false; return fs.checkAccess(this, FileSystem.ACCESS_EXECUTE); }