001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.zip;
020:
021: import java.util.zip.ZipException;
022:
023: /**
024: * If this extra field is added as the very first extra field of the
025: * archive, Solaris will consider it an executable jar file.
026: *
027: * @since Ant 1.6.3
028: */
029: public final class JarMarker implements ZipExtraField {
030:
031: private static final ZipShort ID = new ZipShort(0xCAFE);
032: private static final ZipShort NULL = new ZipShort(0);
033: private static final byte[] NO_BYTES = new byte[0];
034: private static final JarMarker DEFAULT = new JarMarker();
035:
036: /** No-arg constructor */
037: public JarMarker() {
038: // empty
039: }
040:
041: /**
042: * Since JarMarker is stateless we can always use the same instance.
043: * @return the DEFAULT jarmaker.
044: */
045: public static JarMarker getInstance() {
046: return DEFAULT;
047: }
048:
049: /**
050: * The Header-ID.
051: * @return the header id
052: */
053: public ZipShort getHeaderId() {
054: return ID;
055: }
056:
057: /**
058: * Length of the extra field in the local file data - without
059: * Header-ID or length specifier.
060: * @return 0
061: */
062: public ZipShort getLocalFileDataLength() {
063: return NULL;
064: }
065:
066: /**
067: * Length of the extra field in the central directory - without
068: * Header-ID or length specifier.
069: * @return 0
070: */
071: public ZipShort getCentralDirectoryLength() {
072: return NULL;
073: }
074:
075: /**
076: * The actual data to put into local file data - without Header-ID
077: * or length specifier.
078: * @return the data
079: * @since 1.1
080: */
081: public byte[] getLocalFileDataData() {
082: return NO_BYTES;
083: }
084:
085: /**
086: * The actual data to put central directory - without Header-ID or
087: * length specifier.
088: * @return the data
089: */
090: public byte[] getCentralDirectoryData() {
091: return NO_BYTES;
092: }
093:
094: /**
095: * Populate data from this array as if it was in local file data.
096: * @param data an array of bytes
097: * @param offset the start offset
098: * @param length the number of bytes in the array from offset
099: *
100: * @throws ZipException on error
101: */
102: public void parseFromLocalFileData(byte[] data, int offset,
103: int length) throws ZipException {
104: if (length != 0) {
105: throw new ZipException("JarMarker doesn't expect any data");
106: }
107: }
108: }
|