Code example for ZipEntry

Methods: getCrc, setCrc, setMethod, setSize

0
        out.putNextEntry(new ZipEntry("okay")); // ZipOutputStream.close throws if you add nothing!
        out.close();
    } 
 
    public void testCrc() throws IOException { 
        ZipEntry ze = new ZipEntry("test");
        ze.setMethod(ZipEntry.STORED);
        ze.setSize(4);
 
        // setCrc takes a long, not an int, so -1 isn't a valid CRC32 (because it's 64 bits). 
        try { 
            ze.setCrc(-1);
        } catch (IllegalArgumentException expected) {
        } 
 
        // You can set the CRC32 to 0xffffffff if you're slightly more careful though... 
        ze.setCrc(0xffffffffL);
        assertEquals(0xffffffffL, ze.getCrc());
 
        // And it actually works, even though we use -1L to mean "no CRC set"... 
        ZipOutputStream out = createZipOutputStream(createTemporaryZipFile());
        out.putNextEntry(ze);
        out.write(-1);