applied LGPLv3 and source code formatting.
[vamsas.git] / src / org / apache / tools / zip / JarMarker.java
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  */
18
19 package org.apache.tools.zip;
20
21 import java.util.zip.ZipException;
22
23 /**
24  * If this extra field is added as the very first extra field of the archive,
25  * Solaris will consider it an executable jar file.
26  * 
27  * @since Ant 1.6.3
28  */
29 public final class JarMarker implements ZipExtraField {
30
31   private static final ZipShort ID = new ZipShort(0xCAFE);
32
33   private static final ZipShort NULL = new ZipShort(0);
34
35   private static final byte[] NO_BYTES = new byte[0];
36
37   private static final JarMarker DEFAULT = new JarMarker();
38
39   /** No-arg constructor */
40   public JarMarker() {
41     // empty
42   }
43
44   /**
45    * Since JarMarker is stateless we can always use the same instance.
46    * 
47    * @return the DEFAULT jarmaker.
48    */
49   public static JarMarker getInstance() {
50     return DEFAULT;
51   }
52
53   /**
54    * The Header-ID.
55    * 
56    * @return the header id
57    */
58   public ZipShort getHeaderId() {
59     return ID;
60   }
61
62   /**
63    * Length of the extra field in the local file data - without Header-ID or
64    * length specifier.
65    * 
66    * @return 0
67    */
68   public ZipShort getLocalFileDataLength() {
69     return NULL;
70   }
71
72   /**
73    * Length of the extra field in the central directory - without Header-ID or
74    * length specifier.
75    * 
76    * @return 0
77    */
78   public ZipShort getCentralDirectoryLength() {
79     return NULL;
80   }
81
82   /**
83    * The actual data to put into local file data - without Header-ID or length
84    * specifier.
85    * 
86    * @return the data
87    * @since 1.1
88    */
89   public byte[] getLocalFileDataData() {
90     return NO_BYTES;
91   }
92
93   /**
94    * The actual data to put central directory - without Header-ID or length
95    * specifier.
96    * 
97    * @return the data
98    */
99   public byte[] getCentralDirectoryData() {
100     return NO_BYTES;
101   }
102
103   /**
104    * Populate data from this array as if it was in local file data.
105    * 
106    * @param data
107    *          an array of bytes
108    * @param offset
109    *          the start offset
110    * @param length
111    *          the number of bytes in the array from offset
112    * 
113    * @throws ZipException
114    *           on error
115    */
116   public void parseFromLocalFileData(byte[] data, int offset, int length)
117       throws ZipException {
118     if (length != 0) {
119       throw new ZipException("JarMarker doesn't expect any data");
120     }
121   }
122 }