1. /*
  2. * Copyright 2001-2002,2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.zip;
  18. /**
  19. * Simple placeholder for all those extra fields we don't want to deal
  20. * with.
  21. *
  22. * <p>Assumes local file data and central directory entries are
  23. * identical - unless told the opposite.</p>
  24. *
  25. * @version $Revision: 1.4.2.4 $
  26. */
  27. public class UnrecognizedExtraField implements ZipExtraField {
  28. /**
  29. * The Header-ID.
  30. *
  31. * @since 1.1
  32. */
  33. private ZipShort headerId;
  34. public void setHeaderId(ZipShort headerId) {
  35. this.headerId = headerId;
  36. }
  37. public ZipShort getHeaderId() {
  38. return headerId;
  39. }
  40. /**
  41. * Extra field data in local file data - without
  42. * Header-ID or length specifier.
  43. *
  44. * @since 1.1
  45. */
  46. private byte[] localData;
  47. public void setLocalFileDataData(byte[] data) {
  48. localData = data;
  49. }
  50. public ZipShort getLocalFileDataLength() {
  51. return new ZipShort(localData.length);
  52. }
  53. public byte[] getLocalFileDataData() {
  54. return localData;
  55. }
  56. /**
  57. * Extra field data in central directory - without
  58. * Header-ID or length specifier.
  59. *
  60. * @since 1.1
  61. */
  62. private byte[] centralData;
  63. public void setCentralDirectoryData(byte[] data) {
  64. centralData = data;
  65. }
  66. public ZipShort getCentralDirectoryLength() {
  67. if (centralData != null) {
  68. return new ZipShort(centralData.length);
  69. }
  70. return getLocalFileDataLength();
  71. }
  72. public byte[] getCentralDirectoryData() {
  73. if (centralData != null) {
  74. return centralData;
  75. }
  76. return getLocalFileDataData();
  77. }
  78. public void parseFromLocalFileData(byte[] data, int offset, int length) {
  79. byte[] tmp = new byte[length];
  80. System.arraycopy(data, offset, tmp, 0, length);
  81. setLocalFileDataData(tmp);
  82. }
  83. }