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/04 18:26:05 UTC

[commons-vfs] branch master updated: [VFS-750] Fix backwards incompatibility in AbstractFileObject.getInputStream().

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 6e1b4ff  [VFS-750] Fix backwards incompatibility in AbstractFileObject.getInputStream().
6e1b4ff is described below

commit 6e1b4ffe37e682e6a3ee8cdfd9d6b37fa2f20449
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jan 4 13:26:01 2020 -0500

    [VFS-750] Fix backwards incompatibility in
    AbstractFileObject.getInputStream().
---
 .../commons/vfs2/provider/AbstractFileObject.java      | 18 +++++++++++++++++-
 src/changes/changes.xml                                |  3 +++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java
index d75d732..6f294ac 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java
@@ -67,6 +67,8 @@ import org.apache.commons.vfs2.util.RandomAccessMode;
  */
 public abstract class AbstractFileObject<AFS extends AbstractFileSystem> implements FileObject {
 
+    private static final String DO_GET_INPUT_STREAM_INT = "doGetInputStream(int)";
+
     /**
      * Same as {@link BufferedInputStream}.
      */
@@ -638,7 +640,7 @@ public abstract class AbstractFileObject<AFS extends AbstractFileSystem> impleme
      * @throws Exception if an error occurs.
      */
     protected InputStream doGetInputStream(final int bufferSize) throws Exception {
-        throw new UnsupportedOperationException();
+        throw new UnsupportedOperationException(DO_GET_INPUT_STREAM_INT);
     }
 
     /**
@@ -1206,6 +1208,20 @@ public abstract class AbstractFileObject<AFS extends AbstractFileSystem> impleme
             throw new org.apache.commons.vfs2.FileNotFoundException(fileName, exc);
         } catch (final FileSystemException exc) {
             throw exc;
+        } catch (final UnsupportedOperationException exc) {
+            // Backward compatibility for subclasses before 2.5.0
+            if (DO_GET_INPUT_STREAM_INT.equals(exc.getMessage())) {
+                try {
+                    // Invoke old API.
+                    return doGetInputStream();
+                } catch (Exception e) {
+                    if (e instanceof FileSystemException) {
+                        throw (FileSystemException) e;
+                    }
+                    throw new FileSystemException("vfs.provider/read.error", fileName, exc);
+                }
+            }
+            throw exc;
         } catch (final Exception exc) {
             throw new FileSystemException("vfs.provider/read.error", fileName, exc);
         }
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1c4aeb5..5e5bfc8 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -49,6 +49,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" due-to="Eitan Adler" type="fix">
         Clean up tests and simplify assertions #76.
       </action>
+      <action issue="VFS-750" dev="ggregory" due-to="Boris Petrov, Gary Gregory" type="fix">
+        Fix backwards incompatibility in AbstractFileObject.getInputStream().
+      </action>
     </release>
     <release version="2.5.0" date="2019-12-24" description="New features and bug fix release.">
 <!--       <action issue="VFS-443" dev="ggregory" type="update" due-to="nickallen"> -->