mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
no runtime exceptions in zip subsystem; IOException only
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1310 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
30ee4b49c7
commit
dabac4421a
9 changed files with 53 additions and 36 deletions
|
@ -99,6 +99,7 @@ public final class ZipFile {
|
|||
* Finds descriptor of the last header and installs sizes of files
|
||||
*/
|
||||
private void findAndReadDescriptor(MyBufferedInputStream baseStream, LocalFileHeader header) throws IOException {
|
||||
loop:
|
||||
while (true) {
|
||||
int signature = 0;
|
||||
do {
|
||||
|
@ -107,18 +108,29 @@ public final class ZipFile {
|
|||
throw new ZipException(
|
||||
"readFileHeaders. Unexpected end of file when looking for DataDescriptor");
|
||||
}
|
||||
signature = ((signature << 8) & (0x0FFFFFFFF)) + (byte) nextByte;
|
||||
} while (signature != LocalFileHeader.DATA_DESCRIPTOR_SIGNATURE);
|
||||
baseStream.skip(4);
|
||||
int compressedSize = baseStream.read4Bytes();
|
||||
int uncompressedSize = baseStream.read4Bytes();
|
||||
if ((baseStream.offset() - header.OffsetOfLocalData - 16) == compressedSize) {
|
||||
header.setSizes(compressedSize, uncompressedSize);
|
||||
break;
|
||||
} else {
|
||||
baseStream.backSkip(12);
|
||||
continue;
|
||||
}
|
||||
signature = ((signature >> 8) & 0x0FFFFFF) | (nextByte << 24);
|
||||
} while (
|
||||
signature != LocalFileHeader.FILE_HEADER_SIGNATURE &&
|
||||
signature != LocalFileHeader.FOLDER_HEADER_SIGNATURE &&
|
||||
signature != LocalFileHeader.DATA_DESCRIPTOR_SIGNATURE
|
||||
);
|
||||
switch (signature) {
|
||||
case LocalFileHeader.FILE_HEADER_SIGNATURE:
|
||||
break loop;
|
||||
case LocalFileHeader.FOLDER_HEADER_SIGNATURE:
|
||||
break loop;
|
||||
case LocalFileHeader.DATA_DESCRIPTOR_SIGNATURE:
|
||||
baseStream.skip(4);
|
||||
int compressedSize = baseStream.read4Bytes();
|
||||
int uncompressedSize = baseStream.read4Bytes();
|
||||
if ((baseStream.offset() - header.OffsetOfLocalData - 16) == compressedSize) {
|
||||
header.setSizes(compressedSize, uncompressedSize);
|
||||
break loop;
|
||||
} else {
|
||||
baseStream.backSkip(12);
|
||||
continue loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue