From 093890c43c2bf5fc6375dab2253ea824fb830b8d Mon Sep 17 00:00:00 2001 From: Boris Petrov Date: Wed, 16 Dec 2020 17:39:20 +0200 Subject: [PATCH 1/2] Refactor to always calling `FileContent.getOutputStream` ... instead of `AbstractFileObject.getOutputStream`. This allows us to not call `endOutput` explicitly from anywhere other than `DefaultFileContent` --- .../commons/vfs2/provider/AbstractFileObject.java | 5 +++-- .../commons/vfs2/provider/ram/RamFileOutputStream.java | 10 +--------- 2 files changed, 4 insertions(+), 11 deletions(-) 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 6f66543589..b00c7350f4 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 @@ -319,8 +319,9 @@ public void createFile() throws FileSystemException { } if (!exists()) { - getOutputStream().close(); - endOutput(); + try (FileContent content = getContent()) { + content.getOutputStream().close(); + } } } catch (final RuntimeException re) { throw re; diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileOutputStream.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileOutputStream.java index ea23e7ebec..3860e663da 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileOutputStream.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileOutputStream.java @@ -19,8 +19,6 @@ import java.io.IOException; import java.io.OutputStream; -import org.apache.commons.vfs2.FileSystemException; - /** * OutputStream to a RamFile. */ @@ -57,13 +55,7 @@ public void close() throws IOException { if (exception != null) { throw exception; } - try { - this.closed = true; - // Close the - this.file.endOutput(); - } catch (final Exception e) { - throw new FileSystemException(e); - } + this.closed = true; } @Override From ac6d2762f33924efbcd573c170b73dd30a2e616e Mon Sep 17 00:00:00 2001 From: Boris Petrov Date: Wed, 16 Dec 2020 17:40:56 +0200 Subject: [PATCH 2/2] Add a couple of TODOs --- .../org/apache/commons/vfs2/provider/AbstractFileObject.java | 3 +++ 1 file changed, 3 insertions(+) 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 b00c7350f4..6bd8617f5f 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 @@ -1228,6 +1228,7 @@ public FileName getName() { return fileName; } + // TODO: remove this method for the next major version as it is unused /** * Prepares this file for writing. Makes sure it is either a file, or its parent folder exists. Returns an output * stream to use to write the content of the file to. @@ -1239,6 +1240,8 @@ public OutputStream getOutputStream() throws FileSystemException { return getOutputStream(false); } + // TODO: mark this method as `final` and package-private for the next major version because + // it shouldn't be used from anywhere other than `DefaultFileContent` /** * Prepares this file for writing. Makes sure it is either a file, or its parent folder exists. Returns an output * stream to use to write the content of the file to.