View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   https://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.commons.compress.archivers.arj;
20  
21  import java.util.Arrays;
22  import java.util.Objects;
23  
24  final class LocalFileHeader {
25  
26      static final class FileTypes {
27          static final int BINARY = 0;
28          static final int SEVEN_BIT_TEXT = 1;
29          static final int COMMENT_HEADER = 2;
30          static final int DIRECTORY = 3;
31          static final int VOLUME_LABEL = 4;
32          static final int CHAPTER_LABEL = 5;
33      }
34  
35      static final class Flags {
36          static final int GARBLED = 0x01;
37          static final int VOLUME = 0x04;
38          static final int EXTFILE = 0x08;
39          static final int PATHSYM = 0x10;
40          static final int BACKUP = 0x20;
41      }
42  
43      static final class Methods {
44          static final int STORED = 0;
45          static final int COMPRESSED_MOST = 1;
46          static final int COMPRESSED = 2;
47          static final int COMPRESSED_FASTER = 3;
48          static final int COMPRESSED_FASTEST = 4;
49          static final int NO_DATA_NO_CRC = 8;
50          static final int NO_DATA = 9;
51      }
52  
53      int archiverVersionNumber;
54      int minVersionToExtract;
55      int hostOS;
56      int arjFlags;
57      int method;
58      int fileType;
59      int reserved;
60      int dateTimeModified;
61      long compressedSize;
62      long originalSize;
63      long originalCrc32;
64      int fileSpecPosition;
65  
66      int fileAccessMode;
67      int firstChapter;
68      int lastChapter;
69      int extendedFilePosition;
70  
71      int dateTimeAccessed;
72      int dateTimeCreated;
73  
74      int originalSizeEvenForVolumes;
75  
76      String name;
77  
78      String comment;
79  
80      byte[][] extendedHeaders;
81  
82      @Override
83      public boolean equals(final Object obj) {
84          if (this == obj) {
85              return true;
86          }
87          if (obj == null || getClass() != obj.getClass()) {
88              return false;
89          }
90          final LocalFileHeader other = (LocalFileHeader) obj;
91          return archiverVersionNumber == other.archiverVersionNumber && minVersionToExtract == other.minVersionToExtract && hostOS == other.hostOS
92                  && arjFlags == other.arjFlags && method == other.method && fileType == other.fileType && reserved == other.reserved
93                  && dateTimeModified == other.dateTimeModified && compressedSize == other.compressedSize && originalSize == other.originalSize
94                  && originalCrc32 == other.originalCrc32 && fileSpecPosition == other.fileSpecPosition && fileAccessMode == other.fileAccessMode
95                  && firstChapter == other.firstChapter && lastChapter == other.lastChapter && extendedFilePosition == other.extendedFilePosition
96                  && dateTimeAccessed == other.dateTimeAccessed && dateTimeCreated == other.dateTimeCreated
97                  && originalSizeEvenForVolumes == other.originalSizeEvenForVolumes && Objects.equals(name, other.name) && Objects.equals(comment, other.comment)
98                  && Arrays.deepEquals(extendedHeaders, other.extendedHeaders);
99      }
100 
101     @Override
102     public int hashCode() {
103         return name == null ? 0 : name.hashCode();
104     }
105 
106     @Override
107     public String toString() {
108         final StringBuilder builder = new StringBuilder();
109         builder.append("LocalFileHeader [archiverVersionNumber=");
110         builder.append(archiverVersionNumber);
111         builder.append(", minVersionToExtract=");
112         builder.append(minVersionToExtract);
113         builder.append(", hostOS=");
114         builder.append(hostOS);
115         builder.append(", arjFlags=");
116         builder.append(arjFlags);
117         builder.append(", method=");
118         builder.append(method);
119         builder.append(", fileType=");
120         builder.append(fileType);
121         builder.append(", reserved=");
122         builder.append(reserved);
123         builder.append(", dateTimeModified=");
124         builder.append(dateTimeModified);
125         builder.append(", compressedSize=");
126         builder.append(compressedSize);
127         builder.append(", originalSize=");
128         builder.append(originalSize);
129         builder.append(", originalCrc32=");
130         builder.append(originalCrc32);
131         builder.append(", fileSpecPosition=");
132         builder.append(fileSpecPosition);
133         builder.append(", fileAccessMode=");
134         builder.append(fileAccessMode);
135         builder.append(", firstChapter=");
136         builder.append(firstChapter);
137         builder.append(", lastChapter=");
138         builder.append(lastChapter);
139         builder.append(", extendedFilePosition=");
140         builder.append(extendedFilePosition);
141         builder.append(", dateTimeAccessed=");
142         builder.append(dateTimeAccessed);
143         builder.append(", dateTimeCreated=");
144         builder.append(dateTimeCreated);
145         builder.append(", originalSizeEvenForVolumes=");
146         builder.append(originalSizeEvenForVolumes);
147         builder.append(", name=");
148         builder.append(name);
149         builder.append(", comment=");
150         builder.append(comment);
151         builder.append(", extendedHeaders=");
152         builder.append(Arrays.toString(extendedHeaders));
153         builder.append("]");
154         return builder.toString();
155     }
156 
157 }