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..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 @@ -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; @@ -1227,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. @@ -1238,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. 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