@Test public void testParseEocd() throws IOException { int eocdOffset = MinimalZipParser.locateStartOfEocd(unitTestZipArchive); ByteArrayInputStream in = new ByteArrayInputStream(unitTestZipArchive); Assert.assertEquals(eocdOffset, in.skip(eocdOffset)); MinimalCentralDirectoryMetadata centralDirectoryMetadata = MinimalZipParser.parseEocd(in); Assert.assertNotNull(centralDirectoryMetadata); checkExpectedBytes( new byte[] {0x50, 0x4b, 0x01, 0x02}, (int) centralDirectoryMetadata.getOffsetOfCentralDirectory()); long calculatedEndOfCentralDirectory = centralDirectoryMetadata.getOffsetOfCentralDirectory() + centralDirectoryMetadata.getLengthOfCentralDirectory(); checkExpectedBytes(new byte[] {0x50, 0x4b, 0x05, 0x06}, (int) calculatedEndOfCentralDirectory); Assert.assertEquals( UnitTestZipArchive.allEntriesInFileOrder.size(), centralDirectoryMetadata.getNumEntriesInCentralDirectory()); }
public static MinimalCentralDirectoryMetadata parseEocd(InputStream in) throws IOException, ZipException { if (((int) read32BitUnsigned(in)) != EOCD_SIGNATURE) { throw new ZipException("Bad eocd header"); } skipOrDie(in, 2 + 2 + 2); int numEntriesInCentralDirectory = read16BitUnsigned(in); if (numEntriesInCentralDirectory == 0xffff) { throw new ZipException("No support for zip64"); } long lengthOfCentralDirectory = read32BitUnsigned(in); long offsetOfCentralDirectory = read32BitUnsigned(in); return new MinimalCentralDirectoryMetadata( numEntriesInCentralDirectory, offsetOfCentralDirectory, lengthOfCentralDirectory); }
MinimalZipParser { public static MinimalCentralDirectoryMetadata parseEocd(InputStream in) throws IOException, ZipException { if (((int) read32BitUnsigned(in)) != EOCD_SIGNATURE) { throw new ZipException("Bad eocd header"); } skipOrDie(in, 2 + 2 + 2); int numEntriesInCentralDirectory = read16BitUnsigned(in); if (numEntriesInCentralDirectory == 0xffff) { throw new ZipException("No support for zip64"); } long lengthOfCentralDirectory = read32BitUnsigned(in); long offsetOfCentralDirectory = read32BitUnsigned(in); return new MinimalCentralDirectoryMetadata( numEntriesInCentralDirectory, offsetOfCentralDirectory, lengthOfCentralDirectory); } }
MinimalZipParser { public static MinimalCentralDirectoryMetadata parseEocd(InputStream in) throws IOException, ZipException { if (((int) read32BitUnsigned(in)) != EOCD_SIGNATURE) { throw new ZipException("Bad eocd header"); } skipOrDie(in, 2 + 2 + 2); int numEntriesInCentralDirectory = read16BitUnsigned(in); if (numEntriesInCentralDirectory == 0xffff) { throw new ZipException("No support for zip64"); } long lengthOfCentralDirectory = read32BitUnsigned(in); long offsetOfCentralDirectory = read32BitUnsigned(in); return new MinimalCentralDirectoryMetadata( numEntriesInCentralDirectory, offsetOfCentralDirectory, lengthOfCentralDirectory); }  }
MinimalZipParser { public static MinimalCentralDirectoryMetadata parseEocd(InputStream in) throws IOException, ZipException { if (((int) read32BitUnsigned(in)) != EOCD_SIGNATURE) { throw new ZipException("Bad eocd header"); } skipOrDie(in, 2 + 2 + 2); int numEntriesInCentralDirectory = read16BitUnsigned(in); if (numEntriesInCentralDirectory == 0xffff) { throw new ZipException("No support for zip64"); } long lengthOfCentralDirectory = read32BitUnsigned(in); long offsetOfCentralDirectory = read32BitUnsigned(in); return new MinimalCentralDirectoryMetadata( numEntriesInCentralDirectory, offsetOfCentralDirectory, lengthOfCentralDirectory); }  static MinimalZipEntry parseCentralDirectoryEntry(InputStream in); static long parseLocalEntryAndGetCompressedDataOffset(InputStream in); static long locateStartOfEocd(RandomAccessFileInputStream in, int searchBufferLength); static int locateStartOfEocd(byte[] buffer); static MinimalCentralDirectoryMetadata parseEocd(InputStream in); }
MinimalZipParser { public static MinimalCentralDirectoryMetadata parseEocd(InputStream in) throws IOException, ZipException { if (((int) read32BitUnsigned(in)) != EOCD_SIGNATURE) { throw new ZipException("Bad eocd header"); } skipOrDie(in, 2 + 2 + 2); int numEntriesInCentralDirectory = read16BitUnsigned(in); if (numEntriesInCentralDirectory == 0xffff) { throw new ZipException("No support for zip64"); } long lengthOfCentralDirectory = read32BitUnsigned(in); long offsetOfCentralDirectory = read32BitUnsigned(in); return new MinimalCentralDirectoryMetadata( numEntriesInCentralDirectory, offsetOfCentralDirectory, lengthOfCentralDirectory); }  static MinimalZipEntry parseCentralDirectoryEntry(InputStream in); static long parseLocalEntryAndGetCompressedDataOffset(InputStream in); static long locateStartOfEocd(RandomAccessFileInputStream in, int searchBufferLength); static int locateStartOfEocd(byte[] buffer); static MinimalCentralDirectoryMetadata parseEocd(InputStream in); static final int EOCD_SIGNATURE; static final int CENTRAL_DIRECTORY_ENTRY_SIGNATURE; static final int LOCAL_ENTRY_SIGNATURE; }