Java Zip File Check isZip64EndOfCentralDirectoryLocatorPresent(RandomAccessFile zip, long zipEndOfCentralDirectoryPosition)

Here you can find the source of isZip64EndOfCentralDirectoryLocatorPresent(RandomAccessFile zip, long zipEndOfCentralDirectoryPosition)

Description

Returns true if the provided file contains a ZIP64 End of Central Directory Locator.

License

Apache License

Parameter

Parameter Description
zipEndOfCentralDirectoryPosition offset of the ZIP End of Central Directory record in the file.

Exception

Parameter Description
IOException if an I/O error occurs while reading the file.

Declaration

static final boolean isZip64EndOfCentralDirectoryLocatorPresent(RandomAccessFile zip,
        long zipEndOfCentralDirectoryPosition) throws IOException 

Method Source Code


//package com.java2s;
/*//from   ww  w  .j  a  v  a 2 s  .  c  om
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.IOException;
import java.io.RandomAccessFile;

public class Main {
    private static final int ZIP64_EOCD_LOCATOR_SIZE = 20;
    private static final int ZIP64_EOCD_LOCATOR_SIG_REVERSE_BYTE_ORDER = 0x504b0607;

    /**
     * Returns {@code true} if the provided file contains a ZIP64 End of Central Directory
     * Locator.
     *
     * @param zipEndOfCentralDirectoryPosition offset of the ZIP End of Central Directory record
     *        in the file.
     *
     * @throws IOException if an I/O error occurs while reading the file.
     */
    static final boolean isZip64EndOfCentralDirectoryLocatorPresent(RandomAccessFile zip,
            long zipEndOfCentralDirectoryPosition) throws IOException {
        // ZIP64 End of Central Directory Locator immediately precedes the ZIP End of Central
        // Directory Record.
        long locatorPosition = zipEndOfCentralDirectoryPosition - ZIP64_EOCD_LOCATOR_SIZE;
        if (locatorPosition < 0) {
            return false;
        }
        zip.seek(locatorPosition);
        // RandomAccessFile.readInt assumes big-endian byte order, but ZIP format uses
        // little-endian.
        return zip.readInt() == ZIP64_EOCD_LOCATOR_SIG_REVERSE_BYTE_ORDER;
    }
}

Related

  1. isZip(File file)
  2. isZip(File file)
  3. isZip(File file)
  4. isZip(File file)
  5. isZip(File zip)
  6. isZipContainsEntry(File zip, String relativePath)
  7. isZipEntryPackage(String str)
  8. isZipFile(File f)
  9. isZipFile(File f)