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   * http://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.tar;
20  
21  import java.util.Objects;
22  
23  /**
24   * This class represents struct sparse in a Tar archive.
25   * <p>
26   * Whereas, "struct sparse" is:
27   * </p>
28   * <pre>
29   * struct sparse {
30   * char offset[12];   // offset 0
31   * char numbytes[12]; // offset 12
32   * };
33   * </pre>
34   *
35   * @since 1.20
36   */
37  public final class TarArchiveStructSparse {
38      private final long offset;
39      private final long numbytes;
40  
41      public TarArchiveStructSparse(final long offset, final long numbytes) {
42          if (offset < 0) {
43              throw new IllegalArgumentException("offset must not be negative");
44          }
45          if (numbytes < 0) {
46              throw new IllegalArgumentException("numbytes must not be negative");
47          }
48          this.offset = offset;
49          this.numbytes = numbytes;
50      }
51  
52      @Override
53      public boolean equals(final Object o) {
54          if (this == o) {
55              return true;
56          }
57          if (o == null || getClass() != o.getClass()) {
58              return false;
59          }
60          final TarArchiveStructSparse that = (TarArchiveStructSparse) o;
61          return offset == that.offset && numbytes == that.numbytes;
62      }
63  
64      public long getNumbytes() {
65          return numbytes;
66      }
67  
68      public long getOffset() {
69          return offset;
70      }
71  
72      @Override
73      public int hashCode() {
74          return Objects.hash(offset, numbytes);
75      }
76  
77      @Override
78      public String toString() {
79          return "TarArchiveStructSparse{" + "offset=" + offset + ", numbytes=" + numbytes + '}';
80      }
81  }