001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019 package org.apache.commons.compress.archivers.tar;
020
021 import java.io.IOException;
022
023 /**
024 * This class represents a sparse entry in a Tar archive.
025 *
026 * <p>
027 * The C structure for a sparse entry is:
028 * <pre>
029 * struct posix_header {
030 * struct sparse sp[21]; // TarConstants.SPARSELEN_GNU_SPARSE - offset 0
031 * char isextended; // TarConstants.ISEXTENDEDLEN_GNU_SPARSE - offset 504
032 * };
033 * </pre>
034 * Whereas, "struct sparse" is:
035 * <pre>
036 * struct sparse {
037 * char offset[12]; // offset 0
038 * char numbytes[12]; // offset 12
039 * };
040 * </pre>
041 */
042
043 public class TarArchiveSparseEntry implements TarConstants {
044 /** If an extension sparse header follows. */
045 private boolean isExtended;
046
047 /**
048 * Construct an entry from an archive's header bytes. File is set
049 * to null.
050 *
051 * @param headerBuf The header bytes from a tar archive entry.
052 * @throws IOException on unknown format
053 */
054 public TarArchiveSparseEntry(byte[] headerBuf) throws IOException {
055 int offset = 0;
056 offset += SPARSELEN_GNU_SPARSE;
057 isExtended = TarUtils.parseBoolean(headerBuf, offset);
058 }
059
060 public boolean isExtended() {
061 return isExtended;
062 }
063 }