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/01/06 15:11:07 UTC

[commons-vfs] branch master updated: [VFS-751] Deprecate org.apache.commons.vfs2.FileUtil for org.apache.commons.vfs2.util.FileObjectUtils.

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


The following commit(s) were added to refs/heads/master by this push:
     new fa7133e  [VFS-751] Deprecate org.apache.commons.vfs2.FileUtil for org.apache.commons.vfs2.util.FileObjectUtils.
fa7133e is described below

commit fa7133e4b3767d3886e8d406cb5c33b6bce5e031
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jan 6 10:11:03 2020 -0500

    [VFS-751] Deprecate org.apache.commons.vfs2.FileUtil for
    org.apache.commons.vfs2.util.FileObjectUtils.
---
 .../org/apache/commons/vfs2/example/Shell.java     |  4 +-
 .../java/org/apache/commons/vfs2/FileUtil.java     | 27 ++++++---
 .../org/apache/commons/vfs2/impl/Resource.java     |  4 +-
 .../apache/commons/vfs2/util/FileObjectUtils.java  | 65 ++++++++++++++++++----
 src/changes/changes.xml                            |  3 +
 5 files changed, 82 insertions(+), 21 deletions(-)

diff --git a/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java b/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
index 015be71..eda3ea4 100644
--- a/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
+++ b/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
@@ -36,11 +36,11 @@ import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.FileSystemException;
 import org.apache.commons.vfs2.FileSystemManager;
 import org.apache.commons.vfs2.FileType;
-import org.apache.commons.vfs2.FileUtil;
 import org.apache.commons.vfs2.Selectors;
 import org.apache.commons.vfs2.VFS;
 import org.apache.commons.vfs2.impl.StandardFileSystemManager;
 import org.apache.commons.vfs2.operations.FileOperationProvider;
+import org.apache.commons.vfs2.util.FileObjectUtils;
 
 /**
  * A simple command-line shell for performing file operations.
@@ -234,7 +234,7 @@ public final class Shell {
         final FileObject file = mgr.resolveFile(cwd, cmd[1]);
 
         // Dump the contents to System.out
-        FileUtil.writeContent(file, System.out);
+        FileObjectUtils.writeContent(file, System.out);
         System.out.println();
     }
 
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileUtil.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileUtil.java
index 512a32b..2b98116 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileUtil.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileUtil.java
@@ -19,22 +19,29 @@ package org.apache.commons.vfs2;
 import java.io.IOException;
 import java.io.OutputStream;
 
+import org.apache.commons.vfs2.util.FileObjectUtils;
+
 /**
  * Utility methods for dealing with FileObjects.
+ * 
+ * @deprecated Use {@link org.apache.commons.vfs2.util.FileObjectUtils}.
  */
+@Deprecated
 public final class FileUtil {
 
     /**
      * Copies the content from a source file to a destination file.
      *
-     * @param srcFile  The source FileObject.
+     * @param srcFile The source FileObject.
      * @param destFile The target FileObject
      * @throws IOException If an error occurs copying the file.
      * @see FileContent#write(FileContent)
      * @see FileContent#write(FileObject)
+     * @deprecated Use {@link org.apache.commons.vfs2.util.FileObjectUtils#writeContent(FileObject, FileObject)}.
      */
+    @Deprecated
     public static void copyContent(final FileObject srcFile, final FileObject destFile) throws IOException {
-        srcFile.getContent().write(destFile);
+        FileObjectUtils.writeContent(srcFile, destFile);
     }
 
     /**
@@ -43,26 +50,32 @@ public final class FileUtil {
      * @param file The file to get the content of.
      * @return The content as a byte array.
      * @throws IOException if the file content cannot be accessed.
+     * @deprecated Use {@link org.apache.commons.vfs2.util.FileObjectUtils#getContentAsByteArray(FileObject)}.
      */
+    @Deprecated
     public static byte[] getContent(final FileObject file) throws IOException {
-        try (final FileContent content = file.getContent()) {
-            return content.getByteArray();
-        }
+        return FileObjectUtils.getContentAsByteArray(file);
     }
 
     /**
      * Writes the content of a file to an OutputStream.
      *
-     * @param file   The FileObject to write.
+     * @param file The FileObject to write.
      * @param output The OutputStream to write to.
      * @throws IOException if an error occurs writing the file.
      * @see FileContent#write(OutputStream)
+     * @deprecated Use {@link org.apache.commons.vfs2.util.FileObjectUtils#writeContent(FileObject, OutputStream)}.
      */
+    @Deprecated
     public static void writeContent(final FileObject file, final OutputStream output) throws IOException {
-        file.getContent().write(output);
+        FileObjectUtils.writeContent(file, output);
     }
 
+    /**
+     * No instances.
+     */
     private FileUtil() {
+        // empty
     }
 
 }
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/Resource.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/Resource.java
index a41542b..ec8ee66 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/Resource.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/Resource.java
@@ -22,7 +22,7 @@ import java.util.jar.Attributes;
 
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.FileSystemException;
-import org.apache.commons.vfs2.FileUtil;
+import org.apache.commons.vfs2.util.FileObjectUtils;
 
 /**
  * Helper class for VFSClassLoader. This represents a resource loaded with the classloader.
@@ -100,6 +100,6 @@ class Resource {
      * Returns the data for this resource as a byte array.
      */
     public byte[] getBytes() throws IOException {
-        return FileUtil.getContent(resource);
+        return FileObjectUtils.getContentAsByteArray(resource);
     }
 }
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/FileObjectUtils.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/FileObjectUtils.java
index 86074e9..fb2328f 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/FileObjectUtils.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/FileObjectUtils.java
@@ -18,9 +18,9 @@ package org.apache.commons.vfs2.util;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.nio.charset.Charset;
 import java.util.Properties;
-
 import org.apache.commons.vfs2.FileContent;
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.FileSystemException;
@@ -64,16 +64,31 @@ public final class FileObjectUtils {
         }
 
         throw new FileSystemException("vfs.util/find-abstract-file-object.error",
-                fileObject == null ? "null" : fileObject.getClass().getName());
+            fileObject == null ? "null" : fileObject.getClass().getName());
     }
 
     /**
-     * Returns the content of a file as a String.
+     * Gets the content of a file object, as a byte array.
      *
-     * @param file The file to get the content of.
-     * @param charset The file character set, may be null.
+     * @param file Gets the contents of this file object.
      * @return The content as a byte array.
      * @throws IOException if the file content cannot be accessed.
+     *
+     * @since 2.6.0
+     */
+    public static byte[] getContentAsByteArray(final FileObject file) throws IOException {
+        try (final FileContent content = file.getContent()) {
+            return content.getByteArray();
+        }
+    }
+
+    /**
+     * Gets the content of a file as a String.
+     *
+     * @param file Gets the contents of this file object.
+     * @param charset The file character set, may be null.
+     * @return The content as a string.
+     * @throws IOException if the file content cannot be accessed.
      * @since 2.4
      */
     public static String getContentAsString(final FileObject file, final Charset charset) throws IOException {
@@ -85,9 +100,9 @@ public final class FileObjectUtils {
     /**
      * Returns the content of a file as a String.
      *
-     * @param file The file to get the content of.
+     * @param file Gets the contents of this file object.
      * @param charset The file character set, may be null.
-     * @return The content as a byte array.
+     * @return The content as a string.
      * @throws IOException if the file content cannot be accessed.
      * @since 2.4
      */
@@ -100,13 +115,13 @@ public final class FileObjectUtils {
     /**
      * Checks if the given FileObject is instance of given class argument.
      *
-     * @param fileObject  The FileObject.
+     * @param fileObject The FileObject.
      * @param wantedClass The Class to check.
      * @return true if fileObject is an instance of the specified Class.
      * @throws FileSystemException if an error occurs.
      */
     public static boolean isInstanceOf(final FileObject fileObject, final Class<?> wantedClass)
-            throws FileSystemException {
+        throws FileSystemException {
         Object searchObject = fileObject;
         while (searchObject instanceof DecoratedFileObject) {
             if (wantedClass.isInstance(searchObject)) {
@@ -148,7 +163,7 @@ public final class FileObjectUtils {
      * @since 2.4
      */
     public static Properties readProperties(final FileObject fileObject, final Properties properties)
-            throws FileSystemException, IOException {
+        throws FileSystemException, IOException {
         if (fileObject == null) {
             return properties;
         }
@@ -158,6 +173,36 @@ public final class FileObjectUtils {
         return properties;
     }
 
+    /**
+     * Writes the content of a file to an OutputStream.
+     *
+     * @param file The FileObject to write.
+     * @param output The OutputStream to write to.
+     * @throws IOException if an error occurs writing the file.
+     * @see FileContent#write(OutputStream)
+     * @since 2.6.0
+     */
+    public static void writeContent(final FileObject file, final OutputStream output) throws IOException {
+        try (final FileContent content = file.getContent()) {
+            content.write(output);
+        }
+    }
+
+    /**
+     * Writes the content from a source file to a destination file.
+     *
+     * @param srcFile The source FileObject.
+     * @param destFile The target FileObject
+     * @throws IOException If an error occurs copying the file.
+     * @see FileContent#write(FileObject)
+     * @since 2.6.0
+     */
+    public static void writeContent(final FileObject srcFile, final FileObject destFile) throws IOException {
+        try (final FileContent content = srcFile.getContent()) {
+            content.write(destFile);
+        }
+    }
+
     private FileObjectUtils() {
         // noop
     }
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 9cd338c..8b94e81 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -59,6 +59,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" due-to="Gary Gregory" type="update">
         Update JUnit from 4.12 to 4.13.
       </action>
+      <action issue="VFS-751" dev="ggregory" due-to="Gary Gregory" type="fix">
+        Deprecate org.apache.commons.vfs2.FileUtil for org.apache.commons.vfs2.util.FileObjectUtils.
+      </action>
     </release>
     <release version="2.5.0" date="2019-12-24" description="New features and bug fix release.">
       <action issue="VFS-741" dev="ecki" type="fix">