You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

TarArchiveSparseEntry.java 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.tools.tar;
  20. import java.io.IOException;
  21. /**
  22. * This class represents a sparse entry in a Tar archive.
  23. *
  24. * <p>
  25. * The C structure for a sparse entry is:
  26. * <pre>
  27. * struct posix_header {
  28. * struct sparse sp[21]; // TarConstants.SPARSELEN_GNU_SPARSE - offset 0
  29. * char isextended; // TarConstants.ISEXTENDEDLEN_GNU_SPARSE - offset 504
  30. * };
  31. * </pre>
  32. * Whereas, "struct sparse" is:
  33. * <pre>
  34. * struct sparse {
  35. * char offset[12]; // offset 0
  36. * char numbytes[12]; // offset 12
  37. * };
  38. * </pre>
  39. */
  40. public class TarArchiveSparseEntry implements TarConstants {
  41. /** If an extension sparse header follows. */
  42. private boolean isExtended;
  43. /**
  44. * Construct an entry from an archive's header bytes. File is set
  45. * to null.
  46. *
  47. * @param headerBuf The header bytes from a tar archive entry.
  48. * @throws IOException on unknown format
  49. */
  50. public TarArchiveSparseEntry(byte[] headerBuf) throws IOException {
  51. int offset = 0;
  52. offset += SPARSELEN_GNU_SPARSE;
  53. isExtended = TarUtils.parseBoolean(headerBuf, offset);
  54. }
  55. public boolean isExtended() {
  56. return isExtended;
  57. }
  58. }