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 34efda6  LocalFile.doGetOutputStream(boolean) for an existing file no 
longer truncates the file.
34efda6 is described below

commit 34efda6b7c932d671012e5ff11c58e1ddd17a95d
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Fri Jul 30 15:05:07 2021 -0400

    LocalFile.doGetOutputStream(boolean) for an existing file no longer
    truncates the file.
---
 .../java/org/apache/commons/vfs2/provider/local/LocalFile.java   | 9 +++++++--
 src/changes/changes.xml                                          | 3 +++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git 
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFile.java
 
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFile.java
index 836a7b8..e0c67d9 100644
--- 
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFile.java
+++ 
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFile.java
@@ -22,6 +22,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.file.Files;
+import java.nio.file.OpenOption;
+import java.nio.file.Path;
 import java.nio.file.StandardOpenOption;
 
 import org.apache.commons.vfs2.FileObject;
@@ -123,8 +125,11 @@ public class LocalFile extends 
AbstractFileObject<LocalFileSystem> {
      * Creates an output stream to write the file content to.
      */
     @Override
-    protected OutputStream doGetOutputStream(final boolean bAppend) throws 
Exception {
-        return Files.newOutputStream(file.toPath(), bAppend ? 
StandardOpenOption.APPEND : StandardOpenOption.CREATE);
+    protected OutputStream doGetOutputStream(final boolean append) throws 
Exception {
+        // TODO Reuse Apache Commons IO
+        return Files.newOutputStream(file.toPath(), append ?
+            new OpenOption[] {StandardOpenOption.APPEND} : 
+            new OpenOption[] {StandardOpenOption.CREATE, 
StandardOpenOption.TRUNCATE_EXISTING});
     }
 
     @Override
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 506c7c1..3e8d1bc 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -50,6 +50,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Seth Falco">
         Replace package.html with package-info.java #206. 
       </action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">
+        LocalFile.doGetOutputStream(boolean) for an existing file no longer 
truncates the file.
+      </action>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Seth Falco">
         Add vscode files to gitignore #205.

Reply via email to