16bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes/*
26bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes * Copyright (C) 2010 The Android Open Source Project
3f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes *
46bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
56bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes * you may not use this file except in compliance with the License.
66bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes * You may obtain a copy of the License at
7f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes *
86bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
9f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes *
106bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes * Unless required by applicable law or agreed to in writing, software
116bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
126bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes * See the License for the specific language governing permissions and
146bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes * limitations under the License.
156bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes */
166bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes
174557728efb66c455a52b7669a8eefef7a9e54854Jesse Wilsonpackage libcore.java.util.zip;
186bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes
19406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughesimport java.io.BufferedOutputStream;
206bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughesimport java.io.File;
216bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughesimport java.io.FileInputStream;
226bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughesimport java.io.FileOutputStream;
23406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughesimport java.io.IOException;
246bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughesimport java.util.Arrays;
256bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughesimport java.util.List;
26355a98498e4bc434dde8809eacf6e150f9b25f89Jesse Wilsonimport java.util.jar.JarEntry;
274557728efb66c455a52b7669a8eefef7a9e54854Jesse Wilsonimport java.util.zip.ZipEntry;
2812f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamathimport java.util.zip.ZipException;
294557728efb66c455a52b7669a8eefef7a9e54854Jesse Wilsonimport java.util.zip.ZipFile;
304557728efb66c455a52b7669a8eefef7a9e54854Jesse Wilsonimport java.util.zip.ZipInputStream;
314557728efb66c455a52b7669a8eefef7a9e54854Jesse Wilsonimport java.util.zip.ZipOutputStream;
326bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes
336bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughespublic class ZipEntryTest extends junit.framework.TestCase {
34406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  private static File createTemporaryZipFile() throws IOException {
35406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    File result = File.createTempFile("ZipFileTest", "zip");
36406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    result.deleteOnExit();
37406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    return result;
38406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  }
39355a98498e4bc434dde8809eacf6e150f9b25f89Jesse Wilson
40406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  private static ZipOutputStream createZipOutputStream(File f) throws IOException {
41406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    return new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(f)));
42406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  }
43406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
44406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  private static String makeString(int count, String s) {
45406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    StringBuilder sb = new StringBuilder();
46406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    for (int i = 0; i < count; ++i) {
47406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes      sb.append(s);
48406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    }
49406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    return sb.toString();
50406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  }
51406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
52406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  // http://code.google.com/p/android/issues/detail?id=4690
53406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  public void test_utf8FileNames() throws Exception {
54406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    // Create a zip file containing non-ASCII filenames.
55406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    File f = File.createTempFile("your", "mum");
56406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    List<String> filenames = Arrays.asList("us-ascii",
57406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes                                           "\u043c\u0430\u0440\u0442\u0430", // russian
58406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes                                           "\u1f00\u03c0\u1f78", // greek
59406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes                                           "\u30b3\u30f3\u30cb\u30c1\u30cf"); // japanese
60406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(f));
61406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    for (String filename : filenames) {
62406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes      out.putNextEntry(new ZipEntry(filename));
63406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes      out.closeEntry(); // Empty files are fine.
64406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    }
65406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    out.close();
66406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    // Read it back, and check we find all those names.
67406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    // This failed when we were mangling the encoding.
68406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipFile zipFile = new ZipFile(f);
69406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    for (String filename : filenames) {
70406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes      assertNotNull(filename, zipFile.getEntry(filename));
71406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    }
72406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    // Check that ZipInputStream works too.
73406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipInputStream in = new ZipInputStream(new FileInputStream(f));
74406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipEntry entry;
75406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    int entryCount = 0;
76406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    while ((entry = in.getNextEntry()) != null) {
77406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes      assertTrue(entry.getName(), filenames.contains(entry.getName()));
78406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes      ++entryCount;
79406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    }
80406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    assertEquals(filenames.size(), entryCount);
81406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    in.close();
82406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  }
83406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
84406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  // http://b/2099615
85406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  public void testClone() {
86406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    byte[] extra = { 5, 7, 9 };
87406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    JarEntry jarEntry = new JarEntry("foo");
88406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    jarEntry.setExtra(extra);
89406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    assertSame("Expected no defensive copy of extra", extra, jarEntry.getExtra());
90406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
91406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipEntry clone = (ZipEntry) jarEntry.clone();
92406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    assertEquals(JarEntry.class, clone.getClass());
93406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    assertNotSame(extra, clone.getExtra());
94406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  }
95406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
96406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  public void testTooLongName() throws Exception {
97406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    String tooLongName = makeString(65536, "z");
98406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    try {
99406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes      new ZipEntry(tooLongName);
100406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes      fail();
101406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    } catch (IllegalArgumentException expected) {
102406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    }
103406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  }
104406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
105406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  public void testMaxLengthName() throws Exception {
106406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    String maxLengthName = makeString(65535, "z");
107406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
108406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    File f = createTemporaryZipFile();
109406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipOutputStream out = createZipOutputStream(f);
110406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    out.putNextEntry(new ZipEntry(maxLengthName));
111406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    out.closeEntry();
112406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    out.close();
113406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
114406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    // Read it back, and check that we see the entry.
115406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipFile zipFile = new ZipFile(f);
116406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    assertNotNull(zipFile.getEntry(maxLengthName));
117406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    zipFile.close();
118406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  }
119406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
120406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  public void testTooLongExtra() throws Exception {
121406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    byte[] tooLongExtra = new byte[65536];
122406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipEntry ze = new ZipEntry("x");
123406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    try {
124406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes      ze.setExtra(tooLongExtra);
125406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes      fail();
126406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    } catch (IllegalArgumentException expected) {
1276bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes    }
128406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  }
129406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
130406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  public void testMaxLengthExtra() throws Exception {
131406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    byte[] maxLengthExtra = new byte[65535];
132355a98498e4bc434dde8809eacf6e150f9b25f89Jesse Wilson
133406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    File f = createTemporaryZipFile();
134406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipOutputStream out = createZipOutputStream(f);
135406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipEntry ze = new ZipEntry("x");
13612f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath    ze.setSize(0);
137406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ze.setExtra(maxLengthExtra);
138406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    out.putNextEntry(ze);
139406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    out.closeEntry();
140406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    out.close();
141406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
142406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    // Read it back, and check that we see the entry.
143406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipFile zipFile = new ZipFile(f);
144406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    assertEquals(maxLengthExtra.length, zipFile.getEntry("x").getExtra().length);
145406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    zipFile.close();
146406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  }
147406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
14812f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath
1498456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  // TODO: This test does not compile because we need to add a ZipOutputStream constructor
1508456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  // that forces zip64. This also needs followup changes in ZipInputStream et al. to assume zip64
1518456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  // if the header says so, and to not depend purely on the entry length.
1528456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //
1538456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  // public void testMaxLengthExtra_zip64() throws Exception {
1548456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //   // Not quite the max length (65535), but large enough that there's no space
1558456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //   // for the zip64 extended info header.
1568456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //   byte[] maxLengthExtra = new byte[65530];
1578456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //
1588456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //   File f = createTemporaryZipFile();
1598456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //   ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(f)),
1608456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //           true /* forceZip64 */);
1618456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //   ZipEntry ze = new ZipEntry("x");
1628456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //
1638456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //   ze.setExtra(maxLengthExtra);
1648456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //   try {
1658456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //     out.putNextEntry(ze);
1668456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //     fail();
1678456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //   } catch (ZipException expected) {
1688456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  //   }
1698456b1f15317e7fd59267ab8cafe0a78f1d5b1a0Shubham Ajmera  // }
17012f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath
17112f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath
172a812a87e69850d1492c45bd88d7ff3dbf21d5075Narayan Kamath  public void testTooLongComment() throws Exception {
173406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    String tooLongComment = makeString(65536, "z");
174406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipEntry ze = new ZipEntry("x");
175406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    try {
176406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes      ze.setComment(tooLongComment);
177406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes      fail();
178406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    } catch (IllegalArgumentException expected) {
179355a98498e4bc434dde8809eacf6e150f9b25f89Jesse Wilson    }
180406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  }
181406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
182406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  public void testMaxLengthComment() throws Exception {
183406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    String maxLengthComment = makeString(65535, "z");
184406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
185406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    File f = createTemporaryZipFile();
186406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipOutputStream out = createZipOutputStream(f);
187406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipEntry ze = new ZipEntry("x");
188406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ze.setComment(maxLengthComment);
189406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    out.putNextEntry(ze);
190406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    out.closeEntry();
191406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    out.close();
192406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes
193406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    // Read it back, and check that we see the entry.
194406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    ZipFile zipFile = new ZipFile(f);
195406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    assertEquals(maxLengthComment, zipFile.getEntry("x").getComment());
196406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes    zipFile.close();
197406b85296a7ba29d2f480280d2f2a96133f940ecElliott Hughes  }
198c242577b1569f97f806ef176e4549141df147b78Kenny Root
199c242577b1569f97f806ef176e4549141df147b78Kenny Root  public void testCommentAndExtraInSameOrder() throws Exception {
200c242577b1569f97f806ef176e4549141df147b78Kenny Root    String comment = makeString(17, "z");
201c242577b1569f97f806ef176e4549141df147b78Kenny Root    byte[] extra = makeString(11, "a").getBytes();
202c242577b1569f97f806ef176e4549141df147b78Kenny Root
203c242577b1569f97f806ef176e4549141df147b78Kenny Root    File f = createTemporaryZipFile();
204c242577b1569f97f806ef176e4549141df147b78Kenny Root    ZipOutputStream out = createZipOutputStream(f);
20512f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath
20612f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath    // Regular (non zip64) format.
207c242577b1569f97f806ef176e4549141df147b78Kenny Root    ZipEntry ze = new ZipEntry("x");
20812f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath    ze.setSize(0);
20912f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath    ze.setExtra(extra);
21012f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath    ze.setComment(comment);
21112f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath    out.putNextEntry(ze);
21212f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath    out.closeEntry();
21312f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath
21412f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath    // An entry without a length is assumed to be zip64.
21512f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath    ze = new ZipEntry("y");
216c242577b1569f97f806ef176e4549141df147b78Kenny Root    ze.setExtra(extra);
217c242577b1569f97f806ef176e4549141df147b78Kenny Root    ze.setComment(comment);
218c242577b1569f97f806ef176e4549141df147b78Kenny Root    out.putNextEntry(ze);
219c242577b1569f97f806ef176e4549141df147b78Kenny Root    out.closeEntry();
220c242577b1569f97f806ef176e4549141df147b78Kenny Root    out.close();
221c242577b1569f97f806ef176e4549141df147b78Kenny Root
222c242577b1569f97f806ef176e4549141df147b78Kenny Root    // Read it back and make sure comments and extra are in the right order
223c242577b1569f97f806ef176e4549141df147b78Kenny Root    ZipFile zipFile = new ZipFile(f);
224c242577b1569f97f806ef176e4549141df147b78Kenny Root    try {
225c242577b1569f97f806ef176e4549141df147b78Kenny Root      assertEquals(comment, zipFile.getEntry("x").getComment());
226c242577b1569f97f806ef176e4549141df147b78Kenny Root      assertTrue(Arrays.equals(extra, zipFile.getEntry("x").getExtra()));
22712f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath
22812f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath      assertEquals(comment, zipFile.getEntry("y").getComment());
22912f5c69e074d6ef012706068416f0a61b70b4e52Narayan Kamath      assertTrue(Arrays.equals(extra, zipFile.getEntry("y").getExtra()));
230c242577b1569f97f806ef176e4549141df147b78Kenny Root    } finally {
231c242577b1569f97f806ef176e4549141df147b78Kenny Root      zipFile.close();
232c242577b1569f97f806ef176e4549141df147b78Kenny Root    }
233c242577b1569f97f806ef176e4549141df147b78Kenny Root  }
2346bd77683de703a6df640e863b38a73041e8c0c1bElliott Hughes}
235