Java Code Examples for java.util.zip.ZipEntry#setMethod()

The following examples show how to use java.util.zip.ZipEntry#setMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskCommandDefinitionsGenerator.java    From FoxBPM with Apache License 2.0 6 votes vote down vote up
public void generate(ZipOutputStream out) {
	try {
		log.debug("开始处理taskCommandDefinition.data文件。。。");
		ProcessEngineConfigurationImpl processEngineConfigurationImpl = FoxBpmUtil.getProcessEngine().getProcessEngineConfiguration();
		List<TaskCommandDefinition> list = processEngineConfigurationImpl.getTaskCommandDefinitions();
		ObjectMapper objectMapper = new ObjectMapper();
		JsonGenerator jsonGenerator = objectMapper.getJsonFactory().createJsonGenerator(out, JsonEncoding.UTF8);
		String tmpEntryName = "cache/taskCommandDefinition.data";
		ZipEntry zipEntry = new ZipEntry(tmpEntryName);
		zipEntry.setMethod(ZipEntry.DEFLATED);// 设置条目的压缩方式
		out.putNextEntry(zipEntry);
		jsonGenerator.writeObject(list);
		out.closeEntry();
		log.debug("处理taskCommandDefinition.data文件完毕");
	} catch (Exception ex) {
		log.error("解析taskCommandDefinition.data文件失败!生成zip文件失败!");
		throw new FoxBPMException("解析taskCommandDefinition.data文件失败", ex);
	}
}
 
Example 2
Source File: BundleFileSystemProvider.java    From incubator-taverna-language with Apache License 2.0 6 votes vote down vote up
protected static void addMimeTypeToZip(ZipOutputStream out, String mimetype)
		throws IOException {
	if (mimetype == null) {
		mimetype = APPLICATION_VND_WF4EVER_ROBUNDLE_ZIP;
	}
	// FIXME: Make the mediatype a parameter
	byte[] bytes = mimetype.getBytes(UTF8);

	// We'll have to do the mimetype file quite low-level
	// in order to ensure it is STORED and not COMPRESSED

	ZipEntry entry = new ZipEntry(MIMETYPE_FILE);
	entry.setMethod(ZipEntry.STORED);
	entry.setSize(bytes.length);
	CRC32 crc = new CRC32();
	crc.update(bytes);
	entry.setCrc(crc.getValue());

	out.putNextEntry(entry);
	out.write(bytes);
	out.closeEntry();
}
 
Example 3
Source File: B7050028.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection();
    int len = conn.getContentLength();
    byte[] data = new byte[len];
    InputStream is = conn.getInputStream();
    is.read(data);
    is.close();
    conn.setDefaultUseCaches(false);
    File jar = File.createTempFile("B7050028", ".jar");
    jar.deleteOnExit();
    OutputStream os = new FileOutputStream(jar);
    ZipOutputStream zos = new ZipOutputStream(os);
    ZipEntry ze = new ZipEntry("B7050028.class");
    ze.setMethod(ZipEntry.STORED);
    ze.setSize(len);
    CRC32 crc = new CRC32();
    crc.update(data);
    ze.setCrc(crc.getValue());
    zos.putNextEntry(ze);
    zos.write(data, 0, len);
    zos.closeEntry();
    zos.finish();
    zos.close();
    os.close();
    System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName()));
}
 
Example 4
Source File: B7050028.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection();
    int len = conn.getContentLength();
    byte[] data = new byte[len];
    InputStream is = conn.getInputStream();
    is.read(data);
    is.close();
    conn.setDefaultUseCaches(false);
    File jar = File.createTempFile("B7050028", ".jar");
    jar.deleteOnExit();
    OutputStream os = new FileOutputStream(jar);
    ZipOutputStream zos = new ZipOutputStream(os);
    ZipEntry ze = new ZipEntry("B7050028.class");
    ze.setMethod(ZipEntry.STORED);
    ze.setSize(len);
    CRC32 crc = new CRC32();
    crc.update(data);
    ze.setCrc(crc.getValue());
    zos.putNextEntry(ze);
    zos.write(data, 0, len);
    zos.closeEntry();
    zos.finish();
    zos.close();
    os.close();
    System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName()));
}
 
Example 5
Source File: ConnectorGenerator.java    From FoxBPM with Apache License 2.0 5 votes vote down vote up
private void generZip(InputStream stream,String entryName,ZipOutputStream out) throws Exception{
	
	ZipEntry zipEntry = new ZipEntry(entryName);
	zipEntry.setMethod(ZipEntry.DEFLATED);// 设置条目的压缩方式
	out.putNextEntry(zipEntry);
	int n = 0;
	byte b[] = new byte[SIZE];
	while((n=stream.read(b)) != -1){
		out.write(b , 0 , n);
	}
	out.closeEntry();
	stream.close();
}
 
Example 6
Source File: MergeTool.java    From atlas with Apache License 2.0 5 votes vote down vote up
private static int writePatch(Enumeration entries, ZipOutputStream out, BufferedOutputStream bo,ZipFile zipFile, int i) throws IOException {
    byte[] buffer = new byte[BUFFEREDSIZE];
    while (entries.hasMoreElements()) {
        ZipEntry zipEnt = (ZipEntry) entries.nextElement();
        String name = zipEnt.getName();
        if (name.endsWith(MergeConstants.DEX_SUFFIX)) {
            ZipEntry zipEntry = new ZipEntry(String.format("%s%s%s", MergeConstants.CLASS, i == 1 ? "" : i, MergeConstants.DEX_SUFFIX));
            out.putNextEntry(zipEntry);
            write(zipFile.getInputStream(zipEnt), out, buffer);
            bo.flush();
            i++;
            continue;
        }
        ZipEntry newEntry = new ZipEntry(name);
        if (name.contains("raw/") || name.contains("assets/") || name.equals("resources.arsc")) {
            newEntry.setMethod(ZipEntry.STORED);
            newEntry.setCrc(zipEnt.getCrc());
            newEntry.setSize(zipEnt.getSize());
        }
        out.putNextEntry(newEntry);
        InputStream in = zipFile.getInputStream(zipEnt);
        write(in, out, buffer);
        bo.flush();
    }

    return i;

}
 
Example 7
Source File: ApkBreakdownGeneratorTest.java    From bundletool with Apache License 2.0 5 votes vote down vote up
private static long compress(byte[] data) throws IOException {
  ZipEntry zipEntry = new ZipEntry("entry");
  try (ZipOutputStream zos = new ZipOutputStream(ByteStreams.nullOutputStream())) {
    zipEntry.setMethod(ZipEntry.DEFLATED);
    zos.putNextEntry(zipEntry);
    zos.write(data);
    zos.closeEntry();
  }
  return zipEntry.getCompressedSize();
}
 
Example 8
Source File: EncryptedManifestEntry.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ZipEntry asZipEntry() {
    final ZipEntry zipEntry = new ZipEntry(this.fullPath);
    zipEntry.setSize(this.encryptParameters.getCompressedSize());
    zipEntry.setCompressedSize(this.encryptParameters.getCompressedSize());
    zipEntry.setCrc(this.encryptParameters.getCrc32());
    zipEntry.setMethod(ZipEntry.STORED);
    return zipEntry;
}
 
Example 9
Source File: ZipUtils.java    From ratel with Apache License 2.0 5 votes vote down vote up
private static void processFolder(final File folder, final ZipOutputStream zipOutputStream, final int prefixLength)
        throws BrutException, IOException {
    for (final File file : folder.listFiles()) {
        if (file.isFile()) {
            final String cleanedPath = BrutIO.sanitizeUnknownFile(folder, file.getPath().substring(prefixLength));
            final ZipEntry zipEntry = new ZipEntry(BrutIO.normalizePath(cleanedPath));

            // aapt binary by default takes in parameters via -0 arsc to list extensions that shouldn't be
            // compressed. We will replicate that behavior
            final String extension = FilenameUtils.getExtension(file.getAbsolutePath());
            if (mDoNotCompress != null && (mDoNotCompress.contains(extension) || mDoNotCompress.contains(zipEntry.getName()))) {
                zipEntry.setMethod(ZipEntry.STORED);
                zipEntry.setSize(file.length());
                BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(file));
                CRC32 crc = BrutIO.calculateCrc(unknownFile);
                zipEntry.setCrc(crc.getValue());
                unknownFile.close();
            } else {
                zipEntry.setMethod(ZipEntry.DEFLATED);
            }

            zipOutputStream.putNextEntry(zipEntry);
            try (FileInputStream inputStream = new FileInputStream(file)) {
                IOUtils.copy(inputStream, zipOutputStream);
            }
            zipOutputStream.closeEntry();
        } else if (file.isDirectory()) {
            processFolder(file, zipOutputStream, prefixLength);
        }
    }
}
 
Example 10
Source File: Comment.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void writeZipFile(String name, String comment)
    throws IOException
{
    try (FileOutputStream fos = new FileOutputStream(name);
         ZipOutputStream zos = new ZipOutputStream(fos))
    {
        zos.setComment(comment);
        ZipEntry ze = new ZipEntry(entryName);
        ze.setMethod(ZipEntry.DEFLATED);
        zos.putNextEntry(ze);
        new DataOutputStream(zos).writeUTF(entryContents);
        zos.closeEntry();
    }
}
 
Example 11
Source File: Comment.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void writeZipFile(String name, String comment)
    throws IOException
{
    try (FileOutputStream fos = new FileOutputStream(name);
         ZipOutputStream zos = new ZipOutputStream(fos))
    {
        zos.setComment(comment);
        ZipEntry ze = new ZipEntry(entryName);
        ze.setMethod(ZipEntry.DEFLATED);
        zos.putNextEntry(ze);
        new DataOutputStream(zos).writeUTF(entryContents);
        zos.closeEntry();
    }
}
 
Example 12
Source File: MSOffice2Xliff.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Save entry.
 * @param entry
 *            the entry
 * @param name
 *            the name
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
private void saveEntry(ZipEntry entry, String name) throws IOException {
	ZipEntry content = new ZipEntry(entry.getName());
	content.setMethod(ZipEntry.DEFLATED);
	zipOut.putNextEntry(content);
	FileInputStream input = new FileInputStream(name);
	byte[] array = new byte[1024];
	int len;
	while ((len = input.read(array)) > 0) {
		zipOut.write(array, 0, len);
	}
	zipOut.closeEntry();
	input.close();
}
 
Example 13
Source File: AtlasFixStackFramesTransform.java    From atlas with Apache License 2.0 5 votes vote down vote up
@NonNull
private ExceptionRunnable createFile(
        @NonNull File input, @NonNull File output, @NonNull TransformInvocation invocation) {
    return () -> {
        try (ZipFile inputZip = new ZipFile(input);
             ZipOutputStream outputZip =
                     new ZipOutputStream(
                             new BufferedOutputStream(
                                     Files.newOutputStream(output.toPath())))) {
            Enumeration<? extends ZipEntry> inEntries = inputZip.entries();
            while (inEntries.hasMoreElements()) {
                ZipEntry entry = inEntries.nextElement();
                if (!entry.getName().endsWith(SdkConstants.DOT_CLASS)) {
                    continue;
                }
                InputStream originalFile =
                        new BufferedInputStream(inputZip.getInputStream(entry));
                ZipEntry outEntry = new ZipEntry(entry.getName());

                byte[] newEntryContent =
                        getFixedClass(originalFile, getClassLoader(invocation));
                CRC32 crc32 = new CRC32();
                crc32.update(newEntryContent);
                outEntry.setCrc(crc32.getValue());
                outEntry.setMethod(ZipEntry.STORED);
                outEntry.setSize(newEntryContent.length);
                outEntry.setCompressedSize(newEntryContent.length);
                outEntry.setLastAccessTime(ZERO);
                outEntry.setLastModifiedTime(ZERO);
                outEntry.setCreationTime(ZERO);

                outputZip.putNextEntry(outEntry);
                outputZip.write(newEntryContent);
                outputZip.closeEntry();
            }
        }
    };
}
 
Example 14
Source File: Comment.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void writeZipFile(String name, String comment)
    throws IOException
{
    try (FileOutputStream fos = new FileOutputStream(name);
         ZipOutputStream zos = new ZipOutputStream(fos))
    {
        zos.setComment(comment);
        ZipEntry ze = new ZipEntry(entryName);
        ze.setMethod(ZipEntry.DEFLATED);
        zos.putNextEntry(ze);
        new DataOutputStream(zos).writeUTF(entryContents);
        zos.closeEntry();
    }
}
 
Example 15
Source File: DexPrinter.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private void copyAllButClassesDexAndSigFiles(ZipFile source, ZipOutputStream destination) throws IOException {
	Enumeration<? extends ZipEntry> sourceEntries = source.entries();
	while (sourceEntries.hasMoreElements()) {
		ZipEntry sourceEntry = sourceEntries.nextElement();
		String sourceEntryName = sourceEntry.getName();
		if (sourceEntryName.equals(CLASSES_DEX) || isSignatureFile(sourceEntryName)) {
			continue;
		}
		// separate ZipEntry avoids compression problems due to encodings
		ZipEntry destinationEntry = new ZipEntry(sourceEntryName);
		// use the same compression method as the original (certain files are stored, not compressed)
		destinationEntry.setMethod(sourceEntry.getMethod());
		// copy other necessary fields for STORE method
		destinationEntry.setSize(sourceEntry.getSize());
		destinationEntry.setCrc(sourceEntry.getCrc());
		// finally craft new entry
		destination.putNextEntry(destinationEntry);
		InputStream zipEntryInput = source.getInputStream(sourceEntry);
		byte[] buffer = new byte[2048];
		int bytesRead = zipEntryInput.read(buffer);
		while (bytesRead > 0) {
			destination.write(buffer, 0, bytesRead);
			bytesRead = zipEntryInput.read(buffer);
		}
		zipEntryInput.close();
	}
}
 
Example 16
Source File: NativeUnpack.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void writeEntry(JarOutputStream j, String name,
                        long mtime, long lsize, boolean deflateHint,
                        ByteBuffer data0, ByteBuffer data1) throws IOException {
    int size = (int)lsize;
    if (size != lsize)
        throw new IOException("file too large: "+lsize);

    CRC32 crc32 = _crc32;

    if (_verbose > 1)
        Utils.log.fine("Writing entry: "+name+" size="+size
                         +(deflateHint?" deflated":""));

    if (_buf.length < size) {
        int newSize = size;
        while (newSize < _buf.length) {
            newSize <<= 1;
            if (newSize <= 0) {
                newSize = size;
                break;
            }
        }
        _buf = new byte[newSize];
    }
    assert(_buf.length >= size);

    int fillp = 0;
    if (data0 != null) {
        int size0 = data0.capacity();
        data0.get(_buf, fillp, size0);
        fillp += size0;
    }
    if (data1 != null) {
        int size1 = data1.capacity();
        data1.get(_buf, fillp, size1);
        fillp += size1;
    }
    while (fillp < size) {
        // Fill in rest of data from the stream itself.
        int nr = in.read(_buf, fillp, size - fillp);
        if (nr <= 0)  throw new IOException("EOF at end of archive");
        fillp += nr;
    }

    ZipEntry z = new ZipEntry(name);
    z.setTime(mtime * 1000);

    if (size == 0) {
        z.setMethod(ZipOutputStream.STORED);
        z.setSize(0);
        z.setCrc(0);
        z.setCompressedSize(0);
    } else if (!deflateHint) {
        z.setMethod(ZipOutputStream.STORED);
        z.setSize(size);
        z.setCompressedSize(size);
        crc32.reset();
        crc32.update(_buf, 0, size);
        z.setCrc(crc32.getValue());
    } else {
        z.setMethod(Deflater.DEFLATED);
        z.setSize(size);
    }

    j.putNextEntry(z);

    if (size > 0)
        j.write(_buf, 0, size);

    j.closeEntry();
    if (_verbose > 0) Utils.log.info("Writing " + Utils.zeString(z));
}
 
Example 17
Source File: NativeUnpack.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private void writeEntry(JarOutputStream j, String name,
                        long mtime, long lsize, boolean deflateHint,
                        ByteBuffer data0, ByteBuffer data1) throws IOException {
    int size = (int)lsize;
    if (size != lsize)
        throw new IOException("file too large: "+lsize);

    CRC32 crc32 = _crc32;

    if (_verbose > 1)
        Utils.log.fine("Writing entry: "+name+" size="+size
                         +(deflateHint?" deflated":""));

    if (_buf.length < size) {
        int newSize = size;
        while (newSize < _buf.length) {
            newSize <<= 1;
            if (newSize <= 0) {
                newSize = size;
                break;
            }
        }
        _buf = new byte[newSize];
    }
    assert(_buf.length >= size);

    int fillp = 0;
    if (data0 != null) {
        int size0 = data0.capacity();
        data0.get(_buf, fillp, size0);
        fillp += size0;
    }
    if (data1 != null) {
        int size1 = data1.capacity();
        data1.get(_buf, fillp, size1);
        fillp += size1;
    }
    while (fillp < size) {
        // Fill in rest of data from the stream itself.
        int nr = in.read(_buf, fillp, size - fillp);
        if (nr <= 0)  throw new IOException("EOF at end of archive");
        fillp += nr;
    }

    ZipEntry z = new ZipEntry(name);
    z.setTime(mtime * 1000);

    if (size == 0) {
        z.setMethod(ZipOutputStream.STORED);
        z.setSize(0);
        z.setCrc(0);
        z.setCompressedSize(0);
    } else if (!deflateHint) {
        z.setMethod(ZipOutputStream.STORED);
        z.setSize(size);
        z.setCompressedSize(size);
        crc32.reset();
        crc32.update(_buf, 0, size);
        z.setCrc(crc32.getValue());
    } else {
        z.setMethod(Deflater.DEFLATED);
        z.setSize(size);
    }

    j.putNextEntry(z);

    if (size > 0)
        j.write(_buf, 0, size);

    j.closeEntry();
    if (_verbose > 0) Utils.log.info("Writing " + Utils.zeString(z));
}
 
Example 18
Source File: NativeUnpack.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void writeEntry(JarOutputStream j, String name,
                        long mtime, long lsize, boolean deflateHint,
                        ByteBuffer data0, ByteBuffer data1) throws IOException {
    int size = (int)lsize;
    if (size != lsize)
        throw new IOException("file too large: "+lsize);

    CRC32 crc32 = _crc32;

    if (_verbose > 1)
        Utils.log.fine("Writing entry: "+name+" size="+size
                         +(deflateHint?" deflated":""));

    if (_buf.length < size) {
        int newSize = size;
        while (newSize < _buf.length) {
            newSize <<= 1;
            if (newSize <= 0) {
                newSize = size;
                break;
            }
        }
        _buf = new byte[newSize];
    }
    assert(_buf.length >= size);

    int fillp = 0;
    if (data0 != null) {
        int size0 = data0.capacity();
        data0.get(_buf, fillp, size0);
        fillp += size0;
    }
    if (data1 != null) {
        int size1 = data1.capacity();
        data1.get(_buf, fillp, size1);
        fillp += size1;
    }
    while (fillp < size) {
        // Fill in rest of data from the stream itself.
        int nr = in.read(_buf, fillp, size - fillp);
        if (nr <= 0)  throw new IOException("EOF at end of archive");
        fillp += nr;
    }

    ZipEntry z = new ZipEntry(name);
    z.setTime(mtime * 1000);

    if (size == 0) {
        z.setMethod(ZipOutputStream.STORED);
        z.setSize(0);
        z.setCrc(0);
        z.setCompressedSize(0);
    } else if (!deflateHint) {
        z.setMethod(ZipOutputStream.STORED);
        z.setSize(size);
        z.setCompressedSize(size);
        crc32.reset();
        crc32.update(_buf, 0, size);
        z.setCrc(crc32.getValue());
    } else {
        z.setMethod(Deflater.DEFLATED);
        z.setSize(size);
    }

    j.putNextEntry(z);

    if (size > 0)
        j.write(_buf, 0, size);

    j.closeEntry();
    if (_verbose > 0) Utils.log.info("Writing " + Utils.zeString(z));
}
 
Example 19
Source File: NativeUnpack.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private void writeEntry(JarOutputStream j, String name,
                        long mtime, long lsize, boolean deflateHint,
                        ByteBuffer data0, ByteBuffer data1) throws IOException {
    int size = (int)lsize;
    if (size != lsize)
        throw new IOException("file too large: "+lsize);

    CRC32 crc32 = _crc32;

    if (_verbose > 1)
        Utils.log.fine("Writing entry: "+name+" size="+size
                         +(deflateHint?" deflated":""));

    if (_buf.length < size) {
        int newSize = size;
        while (newSize < _buf.length) {
            newSize <<= 1;
            if (newSize <= 0) {
                newSize = size;
                break;
            }
        }
        _buf = new byte[newSize];
    }
    assert(_buf.length >= size);

    int fillp = 0;
    if (data0 != null) {
        int size0 = data0.capacity();
        data0.get(_buf, fillp, size0);
        fillp += size0;
    }
    if (data1 != null) {
        int size1 = data1.capacity();
        data1.get(_buf, fillp, size1);
        fillp += size1;
    }
    while (fillp < size) {
        // Fill in rest of data from the stream itself.
        int nr = in.read(_buf, fillp, size - fillp);
        if (nr <= 0)  throw new IOException("EOF at end of archive");
        fillp += nr;
    }

    ZipEntry z = new ZipEntry(name);
    z.setTime(mtime * 1000);

    if (size == 0) {
        z.setMethod(ZipOutputStream.STORED);
        z.setSize(0);
        z.setCrc(0);
        z.setCompressedSize(0);
    } else if (!deflateHint) {
        z.setMethod(ZipOutputStream.STORED);
        z.setSize(size);
        z.setCompressedSize(size);
        crc32.reset();
        crc32.update(_buf, 0, size);
        z.setCrc(crc32.getValue());
    } else {
        z.setMethod(Deflater.DEFLATED);
        z.setSize(size);
    }

    j.putNextEntry(z);

    if (size > 0)
        j.write(_buf, 0, size);

    j.closeEntry();
    if (_verbose > 0) Utils.log.info("Writing " + Utils.zeString(z));
}
 
Example 20
Source File: ZipReaderTest.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Test public void testZipEntryFields() throws IOException {
  CRC32 crc = new CRC32();
  Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
  long date = 791784306000L; // 2/3/1995 04:05:06
  byte[] extra = new ExtraData((short) 0xaa, new byte[] { (byte) 0xbb, (byte) 0xcd }).getBytes();
  byte[] tmp = new byte[128];
  try (ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(test))) {

    ZipEntry foo = new ZipEntry("foo");
    foo.setComment("foo comment.");
    foo.setMethod(ZipEntry.DEFLATED);
    foo.setTime(date);
    foo.setExtra(extra);
    zout.putNextEntry(foo);
    zout.write("foo".getBytes(UTF_8));
    zout.closeEntry();

    ZipEntry bar = new ZipEntry("bar");
    bar.setComment("bar comment.");
    bar.setMethod(ZipEntry.STORED);
    bar.setSize("bar".length());
    bar.setCompressedSize("bar".length());
    crc.reset();
    crc.update("bar".getBytes(UTF_8));
    bar.setCrc(crc.getValue());
    zout.putNextEntry(bar);
    zout.write("bar".getBytes(UTF_8));
    zout.closeEntry();
  }

  try (ZipReader reader = new ZipReader(test, UTF_8)) {
    ZipFileEntry fooEntry = reader.getEntry("foo");
    assertThat(fooEntry.getName()).isEqualTo("foo");
    assertThat(fooEntry.getComment()).isEqualTo("foo comment.");
    assertThat(fooEntry.getMethod()).isEqualTo(Compression.DEFLATED);
    assertThat(fooEntry.getVersion()).isEqualTo(Compression.DEFLATED.getMinVersion());
    assertThat(fooEntry.getTime()).isEqualTo(date);
    assertThat(fooEntry.getSize()).isEqualTo("foo".length());
    deflater.reset();
    deflater.setInput("foo".getBytes(UTF_8));
    deflater.finish();
    assertThat(fooEntry.getCompressedSize()).isEqualTo(deflater.deflate(tmp));
    crc.reset();
    crc.update("foo".getBytes(UTF_8));
    assertThat(fooEntry.getCrc()).isEqualTo(crc.getValue());
    assertThat(fooEntry.getExtra().getBytes()).isEqualTo(extra);

    ZipFileEntry barEntry = reader.getEntry("bar");
    assertThat(barEntry.getName()).isEqualTo("bar");
    assertThat(barEntry.getComment()).isEqualTo("bar comment.");
    assertThat(barEntry.getMethod()).isEqualTo(Compression.STORED);
    assertThat(barEntry.getVersion()).isEqualTo(Compression.STORED.getMinVersion());
    assertDateAboutNow(new Date(barEntry.getTime()));
    assertThat(barEntry.getSize()).isEqualTo("bar".length());
    assertThat(barEntry.getCompressedSize()).isEqualTo("bar".length());
    crc.reset();
    crc.update("bar".getBytes(UTF_8));
    assertThat(barEntry.getCrc()).isEqualTo(crc.getValue());
    assertThat(barEntry.getExtra().getBytes()).isEqualTo(new byte[] {});
  }
}