/** * Parses the "End of central dir record" and positions * the stream at the first central directory record. * * Expects stream to be positioned at the beginning of the * "End of central dir record". */ private void positionAtCentralDirectory32() throws IOException { skipBytes(CFD_LOCATOR_OFFSET); wordBbuf.rewind(); IOUtils.readFully(archive, wordBbuf); archive.position(ZipLong.getValue(wordBuf)); }
/** * Parses the "Zip64 end of central directory locator", * finds the "Zip64 end of central directory record" using the * parsed information, parses that and positions the stream at the * first central directory record. * * Expects stream to be positioned right behind the "Zip64 * end of central directory locator"'s signature. */ private void positionAtCentralDirectory64() throws IOException { skipBytes(ZIP64_EOCDL_LOCATOR_OFFSET - WORD /* signature has already been read */); dwordBbuf.rewind(); IOUtils.readFully(archive, dwordBbuf); archive.position(ZipEightByteInteger.getLongValue(dwordBuf)); wordBbuf.rewind(); IOUtils.readFully(archive, wordBbuf); if (!Arrays.equals(wordBuf, ZipArchiveOutputStream.ZIP64_EOCD_SIG)) { throw new ZipException("archive's ZIP64 end of central " + "directory locator is corrupt."); } skipBytes(ZIP64_EOCD_CFD_LOCATOR_OFFSET - WORD /* signature has already been read */); dwordBbuf.rewind(); IOUtils.readFully(archive, dwordBbuf); archive.position(ZipEightByteInteger.getLongValue(dwordBuf)); }
wordBbuf.get(shortBuf); final int extraFieldLen = ZipShort.getValue(shortBuf); skipBytes(fileNameLen); final byte[] localExtraData = new byte[extraFieldLen]; IOUtils.readFully(archive, ByteBuffer.wrap(localExtraData));
/** * Searches for either the "Zip64 end of central directory * locator" or the "End of central dir record", parses * it and positions the stream at the first central directory * record. */ private void positionAtCentralDirectory() throws IOException { positionAtEndOfCentralDirectoryRecord(); boolean found = false; final boolean searchedForZip64EOCD = archive.position() > ZIP64_EOCDL_LENGTH; if (searchedForZip64EOCD) { archive.position(archive.position() - ZIP64_EOCDL_LENGTH); wordBbuf.rewind(); IOUtils.readFully(archive, wordBbuf); found = Arrays.equals(ZipArchiveOutputStream.ZIP64_EOCD_LOC_SIG, wordBuf); } if (!found) { // not a ZIP64 archive if (searchedForZip64EOCD) { skipBytes(ZIP64_EOCDL_LENGTH - WORD); } positionAtCentralDirectory32(); } else { positionAtCentralDirectory64(); } }
/** * Parses the "End of central dir record" and positions * the stream at the first central directory record. * * Expects stream to be positioned at the beginning of the * "End of central dir record". */ private void positionAtCentralDirectory32() throws IOException { skipBytes(CFD_LOCATOR_OFFSET); wordBbuf.rewind(); IOUtils.readFully(archive, wordBbuf); archive.position(ZipLong.getValue(wordBuf)); }
/** * Parses the "Zip64 end of central directory locator", * finds the "Zip64 end of central directory record" using the * parsed information, parses that and positions the stream at the * first central directory record. * * Expects stream to be positioned right behind the "Zip64 * end of central directory locator"'s signature. */ private void positionAtCentralDirectory64() throws IOException { skipBytes(ZIP64_EOCDL_LOCATOR_OFFSET - WORD /* signature has already been read */); dwordBbuf.rewind(); IOUtils.readFully(archive, dwordBbuf); archive.position(ZipEightByteInteger.getLongValue(dwordBuf)); wordBbuf.rewind(); IOUtils.readFully(archive, wordBbuf); if (!Arrays.equals(wordBuf, ZipArchiveOutputStream.ZIP64_EOCD_SIG)) { throw new ZipException("archive's ZIP64 end of central " + "directory locator is corrupt."); } skipBytes(ZIP64_EOCD_CFD_LOCATOR_OFFSET - WORD /* signature has already been read */); dwordBbuf.rewind(); IOUtils.readFully(archive, dwordBbuf); archive.position(ZipEightByteInteger.getLongValue(dwordBuf)); }
wordBbuf.get(shortBuf); final int extraFieldLen = ZipShort.getValue(shortBuf); skipBytes(fileNameLen); final byte[] localExtraData = new byte[extraFieldLen]; IOUtils.readFully(archive, ByteBuffer.wrap(localExtraData));
/** * Searches for either the "Zip64 end of central directory * locator" or the "End of central dir record", parses * it and positions the stream at the first central directory * record. */ private void positionAtCentralDirectory() throws IOException { positionAtEndOfCentralDirectoryRecord(); boolean found = false; final boolean searchedForZip64EOCD = archive.position() > ZIP64_EOCDL_LENGTH; if (searchedForZip64EOCD) { archive.position(archive.position() - ZIP64_EOCDL_LENGTH); wordBbuf.rewind(); IOUtils.readFully(archive, wordBbuf); found = Arrays.equals(ZipArchiveOutputStream.ZIP64_EOCD_LOC_SIG, wordBuf); } if (!found) { // not a ZIP64 archive if (searchedForZip64EOCD) { skipBytes(ZIP64_EOCDL_LENGTH - WORD); } positionAtCentralDirectory32(); } else { positionAtCentralDirectory64(); } }