View Javadoc
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  package org.apache.commons.compress.archivers.arj;
18  
19  import java.util.Arrays;
20  import java.util.Objects;
21  
22  final class LocalFileHeader {
23  
24      static final class FileTypes {
25          static final int BINARY = 0;
26          static final int SEVEN_BIT_TEXT = 1;
27          static final int COMMENT_HEADER = 2;
28          static final int DIRECTORY = 3;
29          static final int VOLUME_LABEL = 4;
30          static final int CHAPTER_LABEL = 5;
31      }
32  
33      static final class Flags {
34          static final int GARBLED = 0x01;
35          static final int VOLUME = 0x04;
36          static final int EXTFILE = 0x08;
37          static final int PATHSYM = 0x10;
38          static final int BACKUP = 0x20;
39      }
40  
41      static final class Methods {
42          static final int STORED = 0;
43          static final int COMPRESSED_MOST = 1;
44          static final int COMPRESSED = 2;
45          static final int COMPRESSED_FASTER = 3;
46          static final int COMPRESSED_FASTEST = 4;
47          static final int NO_DATA_NO_CRC = 8;
48          static final int NO_DATA = 9;
49      }
50  
51      int archiverVersionNumber;
52      int minVersionToExtract;
53      int hostOS;
54      int arjFlags;
55      int method;
56      int fileType;
57      int reserved;
58      int dateTimeModified;
59      long compressedSize;
60      long originalSize;
61      long originalCrc32;
62      int fileSpecPosition;
63  
64      int fileAccessMode;
65      int firstChapter;
66      int lastChapter;
67      int extendedFilePosition;
68  
69      int dateTimeAccessed;
70      int dateTimeCreated;
71  
72      int originalSizeEvenForVolumes;
73  
74      String name;
75  
76      String comment;
77  
78      byte[][] extendedHeaders;
79  
80      @Override
81      public boolean equals(final Object obj) {
82          if (this == obj) {
83              return true;
84          }
85          if (obj == null || getClass() != obj.getClass()) {
86              return false;
87          }
88          final LocalFileHeader other = (LocalFileHeader) obj;
89          return archiverVersionNumber == other.archiverVersionNumber && minVersionToExtract == other.minVersionToExtract && hostOS == other.hostOS
90                  && arjFlags == other.arjFlags && method == other.method && fileType == other.fileType && reserved == other.reserved
91                  && dateTimeModified == other.dateTimeModified && compressedSize == other.compressedSize && originalSize == other.originalSize
92                  && originalCrc32 == other.originalCrc32 && fileSpecPosition == other.fileSpecPosition && fileAccessMode == other.fileAccessMode
93                  && firstChapter == other.firstChapter && lastChapter == other.lastChapter && extendedFilePosition == other.extendedFilePosition
94                  && dateTimeAccessed == other.dateTimeAccessed && dateTimeCreated == other.dateTimeCreated
95                  && originalSizeEvenForVolumes == other.originalSizeEvenForVolumes && Objects.equals(name, other.name) && Objects.equals(comment, other.comment)
96                  && Arrays.deepEquals(extendedHeaders, other.extendedHeaders);
97      }
98  
99      @Override
100     public int hashCode() {
101         return name == null ? 0 : name.hashCode();
102     }
103 
104     @Override
105     public String toString() {
106         final StringBuilder builder = new StringBuilder();
107         builder.append("LocalFileHeader [archiverVersionNumber=");
108         builder.append(archiverVersionNumber);
109         builder.append(", minVersionToExtract=");
110         builder.append(minVersionToExtract);
111         builder.append(", hostOS=");
112         builder.append(hostOS);
113         builder.append(", arjFlags=");
114         builder.append(arjFlags);
115         builder.append(", method=");
116         builder.append(method);
117         builder.append(", fileType=");
118         builder.append(fileType);
119         builder.append(", reserved=");
120         builder.append(reserved);
121         builder.append(", dateTimeModified=");
122         builder.append(dateTimeModified);
123         builder.append(", compressedSize=");
124         builder.append(compressedSize);
125         builder.append(", originalSize=");
126         builder.append(originalSize);
127         builder.append(", originalCrc32=");
128         builder.append(originalCrc32);
129         builder.append(", fileSpecPosition=");
130         builder.append(fileSpecPosition);
131         builder.append(", fileAccessMode=");
132         builder.append(fileAccessMode);
133         builder.append(", firstChapter=");
134         builder.append(firstChapter);
135         builder.append(", lastChapter=");
136         builder.append(lastChapter);
137         builder.append(", extendedFilePosition=");
138         builder.append(extendedFilePosition);
139         builder.append(", dateTimeAccessed=");
140         builder.append(dateTimeAccessed);
141         builder.append(", dateTimeCreated=");
142         builder.append(dateTimeCreated);
143         builder.append(", originalSizeEvenForVolumes=");
144         builder.append(originalSizeEvenForVolumes);
145         builder.append(", name=");
146         builder.append(name);
147         builder.append(", comment=");
148         builder.append(comment);
149         builder.append(", extendedHeaders=");
150         builder.append(Arrays.toString(extendedHeaders));
151         builder.append("]");
152         return builder.toString();
153     }
154 
155 }