ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen * CDDL HEADER START
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen * The contents of this file are subject to the terms of the
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen * Common Development and Distribution License (the "License").
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen * You may not use this file except in compliance with the License.
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen * See LICENSE.txt included in this distribution for the specific
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen * language governing permissions and limitations under the License.
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen * When distributing Covered Code, include this CDDL HEADER in each
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen * file and include the License file at LICENSE.txt.
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen * If applicable, add the following below this CDDL HEADER, with the
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen * fields enclosed by brackets "[]" replaced with your own identifying
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen * information: Portions Copyright [yyyy] [name of copyright owner]
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen * CDDL HEADER END
eb11fe3584b7b243fb0641da4ab2e157610bb767Lubos Kosco * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlenpackage org.opensolaris.opengrok.analysis.archive;
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlenimport org.opensolaris.opengrok.analysis.FileAnalyzer;
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlenimport org.opensolaris.opengrok.analysis.FileAnalyzer.Genre;
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlenimport org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
23d7d0b65bed750a74caa1b2efc2c4121e84e965Knut Anders Hatlenimport org.opensolaris.opengrok.analysis.executables.JarAnalyzerFactory;
3af7cb62d32b222d39b8af3ebf691892502eba15Jorgen Austvikpublic final class ZipAnalyzerFactory extends FileAnalyzerFactory {
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen private static final String[] SUFFIXES = {
b30e5871823d614f9fc46cdaea08387ec62cabf8Jorgen Austvik private static final byte[] MAGIC = {'P', 'K', 3, 4};
23d7d0b65bed750a74caa1b2efc2c4121e84e965Knut Anders Hatlen // Derived from /usr/src/cmd/file/file.c in OpenSolaris
23d7d0b65bed750a74caa1b2efc2c4121e84e965Knut Anders Hatlen private static final Matcher MATCHER = new Matcher() {
23d7d0b65bed750a74caa1b2efc2c4121e84e965Knut Anders Hatlen private int CH(byte[] b, int n) {
23d7d0b65bed750a74caa1b2efc2c4121e84e965Knut Anders Hatlen return b[n] & 0xff;
23d7d0b65bed750a74caa1b2efc2c4121e84e965Knut Anders Hatlen private int SH(byte[] b, int n) {
23d7d0b65bed750a74caa1b2efc2c4121e84e965Knut Anders Hatlen private int LOCNAM(byte[] b) {
23d7d0b65bed750a74caa1b2efc2c4121e84e965Knut Anders Hatlen private int LOCEXT(byte[] b) {
23d7d0b65bed750a74caa1b2efc2c4121e84e965Knut Anders Hatlen public FileAnalyzerFactory isMagic(byte[] contents, InputStream in)
23d7d0b65bed750a74caa1b2efc2c4121e84e965Knut Anders Hatlen int xoff_end = Math.min(len, xoff + LOCEXT(buf));
23d7d0b65bed750a74caa1b2efc2c4121e84e965Knut Anders Hatlen while ((xoff < xoff_end) && (len - xoff >= XFHSIZ)) {
23d7d0b65bed750a74caa1b2efc2c4121e84e965Knut Anders Hatlen return JarAnalyzerFactory.DEFAULT_INSTANCE;
23d7d0b65bed750a74caa1b2efc2c4121e84e965Knut Anders Hatlen return ZipAnalyzerFactory.DEFAULT_INSTANCE;
23d7d0b65bed750a74caa1b2efc2c4121e84e965Knut Anders Hatlen public static final ZipAnalyzerFactory DEFAULT_INSTANCE =
eb11fe3584b7b243fb0641da4ab2e157610bb767Lubos Kosco super(null, null, SUFFIXES, null, MATCHER, null, Genre.XREFABLE, name);
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen return new ZipAnalyzer(this);