Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6285124

Small compressed zip entries should be read in one read() operation

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 6
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Introduced In Version:
    • Resolved In Build:
      b47
    • CPU:
      x86
    • OS:
      windows_2000

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.5.0_03"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
        Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows 2000 [Version 5.00.2195]


        A DESCRIPTION OF THE PROBLEM :
        When I compress text string "Data disponible" using ZipOutputStream class and uncompress it using ZipFile class the uncompressed result lost the last byte and replace it with a null char.

        If I used other text with more bytes, I have no problem.

        I think we have this problem only with a data that the compressed result is greather than the uncompressed data. In our case, uncompress data is 15 bytes and compress data is 17 bytes.




        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile and execute the source code and check the result.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Uncompress result should be exactly the same as before compression.
        ACTUAL -
        Content:Data disponibl

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------

        import java.io.*;
        import java.util.zip.*;

        public class TestZip
        {
           public TestZip()
           {
              try
              {
                 // Create a working dir
                 File dir = new File("c:\\temp\\testzip");
                 dir.delete();
                 dir.mkdir();

                 // Create a file to compress
                 File file = new File(dir, "abc.txt");
                 FileWriter writer = new FileWriter(file);
                 writer.write("Data disponible");
                 writer.close();

                 // Compress file
                 zip(new File("c:\\temp\\testzip\\abc.zip"), file);

                 // Uncompress file and check the content.
                 ZipFile zipFile = new ZipFile(new File("c:\\temp\\testzip\\abc.zip"));
                 InputStream inputStream = zipFile.getInputStream(zipFile.getEntry("abc.txt"));

                 byte[] content = new byte[inputStream.available()];
                 inputStream.read(content);
                 System.out.println("Content:" + new String(content));

                 zipFile.close();
              }
              catch (Exception ex)
              {
                 ex.printStackTrace();
              }
           }

           private void zip(final File aZipFileName, final File aFile) throws IOException
           {
              final int BUFFER = 2048;

              BufferedInputStream origin = new BufferedInputStream(new FileInputStream(aFile));

              ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(aZipFileName)));
              zip.putNextEntry(new ZipEntry(aFile.getName()));

              int count;
              byte data[] = new byte[BUFFER];
              while((count = origin.read(data, 0, BUFFER)) != -1)
              {
                 zip.write(data, 0, count);
              }

              origin.close();
              zip.closeEntry();
              zip.close();
           }

           public static void main(String[] args)
           {
              TestZip testzip = new TestZip();
           }
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        I don't known.
        ###@###.### 2005-06-14 09:05:09 GMT

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                martin Martin Buchholz
                Reporter:
                jssunw Jitender S (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: