You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alex Herbert (Jira)" <ji...@apache.org> on 2020/10/29 08:08:00 UTC

[jira] [Resolved] (IO-691) IOUtils copyLarge gives incorrect result with buffered stream and zip file

     [ https://issues.apache.org/jira/browse/IO-691?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alex Herbert resolved IO-691.
-----------------------------
    Resolution: Not A Bug

Copy to the output stream requires explicit close after the copy has ended.

> IOUtils copyLarge gives incorrect result with buffered stream and zip file
> --------------------------------------------------------------------------
>
>                 Key: IO-691
>                 URL: https://issues.apache.org/jira/browse/IO-691
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.8.0
>         Environment: Mac OS Catalina v 10.15.7 
> Java 11 
> MacBook Pro (16-inch, 2019)
>            Reporter: Aymon de Broglie
>            Priority: Minor
>         Attachments: test.zip
>
>
> I run the following code 
>  
> {code:java}
> import org.apache.commons.io.IOUtils;
> import java.io.*;
> class Scratch {
>     public static void main(String[] args) throws IOException {
>         String oldFilePath = "your_path/test.zip";
>         String newFilePath = "your_path/new_zip.zip";
>         InputStream inputStream = new FileInputStream(oldFilePath);
>         File file = new File(newFilePath);
>         file.createNewFile();
>         IOUtils.copyLarge(inputStream, new BufferedOutputStream(new FileOutputStream(file)));
>     }
> }
> {code}
> I then try to open the new_zip.zip and it is impossible to open, the file is not well copied
> However if I remove the BufferedOutputStream as below, the copy works correctly 
>  {code:java}
> import org.apache.commons.io.IOUtils;
> import java.io.*;
> class Scratch {
>     public static void main(String[] args) throws IOException {
>         String oldFilePath = "your_path/test.zip";
>         String newFilePath = "your_path/new_zip.zip";
>         InputStream inputStream = new FileInputStream(oldFilePath);
>         File file = new File(newFilePath);
>         file.createNewFile();
>         IOUtils.copyLarge(inputStream, new FileOutputStream(file));
>     }
> }
> {code}



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