[ https://issues.apache.org/jira/browse/VFS-807?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17390771#comment-17390771 ]
Gary D. Gregory commented on VFS-807: ------------------------------------- Hi [~klv_m72] Please try git master. I did not try your Java app as it is not runnable as a unit test. If you want to provide something we can use, feel free to provide a PR on GitHub for a unit test ;) > 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 > Attachments: TestJdkWriteFile.java > > > 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)