[ 
https://issues.apache.org/jira/browse/VFS-807?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17393448#comment-17393448
 ] 

Gary D. Gregory commented on VFS-807:
-------------------------------------

Hi [~klv_m72]

Please don't delete comments ("// TODO Reuse Apache Commons IO") in your patch 
because that's where the implementation will be coming from as soon as Apache 
Commons IO is released, you can see git master for Commons IO which I just 
updated. My plan is to release Commons IO and then to reuse its 
PathUtils.newOutputStream() method from here.

 

> LocalFile migration to NIO is not done correctly
> ------------------------------------------------
>
>                 Key: VFS-807
>                 URL: https://issues.apache.org/jira/browse/VFS-807
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 2.9.0
>            Reporter: L
>            Priority: Blocker
>             Fix For: 2.9.1
>
>         Attachments: TestJdkWriteFile.java, vfs-807.diff
>
>
> According to release notes 
> ([https://archive.apache.org/dist/commons/vfs/RELEASE-NOTES.txt),] version 
> 2.9.0 includes the following change:
> Replace construction of FileInputStream and FileOutputStream objects with 
> Files NIO APIs. #164. Thanks to Arturo Bernal.
> Strangely, it was not completed: LocalFlie.java has the following now, even 
> in master: 
> {code:java}
> /**
>  * Creates an input stream to read the content from.
>  */
>  @Override
>  protected InputStream doGetInputStream(final int bufferSize) throws 
> Exception {
>     return new FileInputStream(file);
>  } 
> {code}
>  
> But what is worse, doGetOutputStream is *completely* broken: 
> {code:java}
>     /**
>      * 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);
>     } {code}
>  
> This can be demonstrated with a small java program, see attachment. The 
> program just tries to write to a local file (into the same directory), using 
> different ways to do it:
>  # Java IO, how it was done before VFS 2.9.0
>  # Java NIO the way VFS 2.9.0 does it
>  # Java NIO the way it must be done
> What is important, the program also verifies the result.
> VFS 2.9.0 fails in 2 cases: 
>  # When the file does not exist and append must be performed:  
> java.nio.file.NoSuchFileException is thrown in this case.
>  # When the file exists and no append must be performed: the file is not 
> truncated, so whatever is written overwrites the beginning of the file, 
> keeping the rest.
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to