You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/09/14 16:58:06 UTC

[commons-vfs] 01/05: [VFS-570] Add HDFS write support #114.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git

commit 6abfda72c10ea678d7a1c6fcbda4cb5185789104
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Sep 14 12:55:38 2020 -0400

    [VFS-570] Add HDFS write support #114.
---
 .../commons/vfs2/provider/hdfs/HdfsFileObject.java | 24 ++++++++--------------
 src/changes/changes.xml                            |  3 +++
 2 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileObject.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileObject.java
index 4d41858..4cec2f4 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileObject.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileObject.java
@@ -32,7 +32,6 @@ import org.apache.commons.vfs2.RandomAccessContent;
 import org.apache.commons.vfs2.provider.AbstractFileName;
 import org.apache.commons.vfs2.provider.AbstractFileObject;
 import org.apache.commons.vfs2.util.RandomAccessMode;
-import org.apache.hadoop.fs.FSDataOutputStream;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -73,22 +72,13 @@ public class HdfsFileObject extends AbstractFileObject<HdfsFileSystem> {
         if (!super.canRenameTo(newfile)) {
             return false;
         }
-
-        FileStatus newfileStat = null;
         try {
-            newfileStat = this.hdfs.getFileStatus(new Path(newfile.getName().getPath()));
+            return this.hdfs.getFileStatus(new Path(newfile.getName().getPath())) == null;
         } catch (final FileNotFoundException e) {
-            // do nothing       
+            return false;
         } catch (IOException e) {
             throw new IllegalStateException(e);
         }
-        if (newfileStat == null) {
-            return true;
-        } else if (newfileStat.isDirectory() || newfileStat.isFile()) {
-            return false;
-        }
-
-        return false;
     }
 
     /**
@@ -140,20 +130,20 @@ public class HdfsFileObject extends AbstractFileObject<HdfsFileSystem> {
     }
 
     /**
-     * @see org.apache.commons.vfs2.provider.AbstractFileObject#doGetOutputStream()
+     * @see org.apache.commons.vfs2.provider.AbstractFileObject#doGetOutputStream(boolean)
+     * @since 2.7.0
      */
     @Override
     protected OutputStream doGetOutputStream(final boolean append) throws Exception {
         if (append) {
             throw new FileSystemException("vfs.provider/write-append-not-supported.error", this.path.getName());
-        } else {
-            FSDataOutputStream out = hdfs.create(this.path);
-            return out;
         }
+        return hdfs.create(this.path);
     }
 
     /**
      * @see org.apache.commons.vfs2.provider.AbstractFileObject#doDelete()
+     * @since 2.7.0
      */
     @Override
     protected void doDelete() throws Exception {
@@ -162,6 +152,7 @@ public class HdfsFileObject extends AbstractFileObject<HdfsFileSystem> {
 
     /**
      * @see org.apache.commons.vfs2.provider.AbstractFileObject#doCreateFolder()
+     * @since 2.7.0
      */
     @Override
     protected void doCreateFolder() throws Exception {
@@ -170,6 +161,7 @@ public class HdfsFileObject extends AbstractFileObject<HdfsFileSystem> {
 
     /**
      * @see org.apache.commons.vfs2.provider.AbstractFileObject#doRename(FileObject)
+     * @since 2.7.0
      */
     @Override
     protected void doRename(FileObject newfile) throws Exception {
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 624e4fc..66de430 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -101,6 +101,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action issue="VFS-777" dev="ggregory" due-to="Bing-ok, Gary Gregory" type="fix">
         NoSuchMethodError due to multiple versions of commons-codec:commons-codec:jar.
       </action>
+      <action issue="VFS-570" dev="ggregory" due-to="garpinc, Gary Gregory" type="add">
+        Add HDFS write support #114.
+      </action>
       <!-- UPDATES -->
       <action issue="VFS-755" dev="ggregory" due-to="Gary Gregory" type="update">
         Update org.apache.httpcomponents:httpclient from 4.5.10 to 4.5.11.