Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-691

IOUtils copyLarge gives incorrect result with buffered stream and zip file

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Not A Bug
    • 2.8.0
    • None
    • Utilities
    • None
    • Mac OS Catalina v 10.15.7 

      Java 11 

      MacBook Pro (16-inch, 2019)

    Description

      I run the following code 

       

      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)));
          }
      }
      
      

      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

      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));
          }
      }
      
      

      Attachments

        1. test.zip
          0.2 kB
          Aymon de Broglie

        Activity

          People

            Unassigned Unassigned
            aymondebroglie Aymon de Broglie
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: