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.tar; 20 21 import java.util.Objects; 22 23 /** 24 * A {@code struct sparse} in a <a href="https://www.gnu.org/software/tar/manual/html_node/Standard.html">Tar archive</a>. 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 /** 42 * Constructs a new instance. 43 * 44 * @param offset An offset greater or equal to zero. 45 * @param numBytes An count greater or equal to zero. 46 */ 47 public TarArchiveStructSparse(final long offset, final long numBytes) { 48 if (offset < 0) { 49 throw new IllegalArgumentException("offset must not be negative"); 50 } 51 if (numBytes < 0) { 52 throw new IllegalArgumentException("numbytes must not be negative"); 53 } 54 this.offset = offset; 55 this.numbytes = numBytes; 56 } 57 58 @Override 59 public boolean equals(final Object o) { 60 if (this == o) { 61 return true; 62 } 63 if (o == null || getClass() != o.getClass()) { 64 return false; 65 } 66 final TarArchiveStructSparse that = (TarArchiveStructSparse) o; 67 return offset == that.offset && numbytes == that.numbytes; 68 } 69 70 /** 71 * Gets the byte count. 72 * 73 * @return the byte count. 74 */ 75 public long getNumbytes() { 76 return numbytes; 77 } 78 79 /** 80 * Gets the offset. 81 * 82 * @return the offset. 83 */ 84 public long getOffset() { 85 return offset; 86 } 87 88 @Override 89 public int hashCode() { 90 return Objects.hash(offset, numbytes); 91 } 92 93 @Override 94 public String toString() { 95 return "TarArchiveStructSparse{offset=" + offset + ", numbytes=" + numbytes + '}'; 96 } 97 }