org.apache.commons.compress.archivers.zip

## Enum ZipArchiveEntry.ExtraFieldParsingMode

- java.lang.Object
- - java.lang.Enum<ZipArchiveEntry.ExtraFieldParsingMode>
  - - org.apache.commons.compress.archivers.zip.ZipArchiveEntry.ExtraFieldParsingMode

- All Implemented Interfaces:
    Serializable, Comparable<ZipArchiveEntry.ExtraFieldParsingMode>, ExtraFieldParsingBehavior, UnparseableExtraFieldBehavior
  Enclosing class:
    ZipArchiveEntry

      public static enum ZipArchiveEntry.ExtraFieldParsingMode
      extends Enum<ZipArchiveEntry.ExtraFieldParsingMode>
      implements ExtraFieldParsingBehavior

  How to try to parse the extra fields.

  Configures the behavior for:

  - What shall happen if the extra field content doesn't follow the recommended pattern of two-byte id followed by a two-byte length?
  - What shall happen if an extra field is generally supported by Commons Compress but its content cannot be parsed correctly? This may for example happen if the archive is corrupt, it triggers a bug in Commons Compress or the extra field uses a version not (yet) supported by Commons Compress.
  Since:
    1.19

- - ### Enum Constant Summary

    Enum Constants
    Enum Constant and Description
    `BEST_EFFORT` Try to parse as many extra fields as possible and wrap unknown extra fields as well as supported extra fields that cannot be parsed in `UnrecognizedExtraField`.
    `DRACONIC` Throw an exception if any of the recognized extra fields cannot be parsed or any extra field violates the recommended pattern.
    `ONLY_PARSEABLE_LENIENT` Try to parse as many extra fields as possible and wrap unknown extra fields as well as supported extra fields that cannot be parsed in `UnrecognizedExtraField`.
    `ONLY_PARSEABLE_STRICT` Try to parse as many extra fields as possible and wrap unknown extra fields in `UnrecognizedExtraField`.
    `STRICT_FOR_KNOW_EXTRA_FIELDS` Try to parse as many extra fields as possible and wrap unknown extra fields in `UnrecognizedExtraField`.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `ZipExtraField` | `createExtraField(ZipShort headerId)` Creates an instance of ZipExtraField for the given id.
    `ZipExtraField` | `fill(ZipExtraField field, byte[] data, int off, int len, boolean local)` Fills in the extra field data for a single extra field.
    `ZipExtraField` | `onUnparseableExtraField(byte[] data, int off, int len, boolean local, int claimedLength)` Decides what to do with extra field data that doesn't follow the recommended pattern.
    `static ZipArchiveEntry.ExtraFieldParsingMode` | `valueOf(String name)` Returns the enum constant of this type with the specified name.
    `static ZipArchiveEntry.ExtraFieldParsingMode[]` | `values()` Returns an array containing the constants of this enum type, in the order they are declared.

    - ### Methods inherited from class java.lang.Enum

      `clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf`

    - ### Methods inherited from class java.lang.Object

      `getClass, notify, notifyAll, wait, wait, wait`

- - ### Enum Constant Detail

    - #### BEST_EFFORT

          public static final ZipArchiveEntry.ExtraFieldParsingMode BEST_EFFORT

      Try to parse as many extra fields as possible and wrap unknown extra fields as well as supported extra fields that cannot be parsed in `UnrecognizedExtraField`.

      Wrap extra data that doesn't follow the recommended pattern in an `UnparseableExtraFieldData` instance.

      This is the default behavior starting with Commons Compress 1.19.

    - #### STRICT_FOR_KNOW_EXTRA_FIELDS

          public static final ZipArchiveEntry.ExtraFieldParsingMode STRICT_FOR_KNOW_EXTRA_FIELDS

      Try to parse as many extra fields as possible and wrap unknown extra fields in `UnrecognizedExtraField`.

      Wrap extra data that doesn't follow the recommended pattern in an `UnparseableExtraFieldData` instance.

      Throw an exception if an extra field that is generally supported cannot be parsed.

      This used to be the default behavior prior to Commons Compress 1.19.

    - #### ONLY_PARSEABLE_LENIENT

          public static final ZipArchiveEntry.ExtraFieldParsingMode ONLY_PARSEABLE_LENIENT

      Try to parse as many extra fields as possible and wrap unknown extra fields as well as supported extra fields that cannot be parsed in `UnrecognizedExtraField`.

      Ignore extra data that doesn't follow the recommended pattern.

    - #### ONLY_PARSEABLE_STRICT

          public static final ZipArchiveEntry.ExtraFieldParsingMode ONLY_PARSEABLE_STRICT

      Try to parse as many extra fields as possible and wrap unknown extra fields in `UnrecognizedExtraField`.

      Ignore extra data that doesn't follow the recommended pattern.

      Throw an exception if an extra field that is generally supported cannot be parsed.

    - #### DRACONIC

          public static final ZipArchiveEntry.ExtraFieldParsingMode DRACONIC

      Throw an exception if any of the recognized extra fields cannot be parsed or any extra field violates the recommended pattern.

  - ### Method Detail

    - #### values

          public static ZipArchiveEntry.ExtraFieldParsingMode[] values()

      Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:

          for (ZipArchiveEntry.ExtraFieldParsingMode c : ZipArchiveEntry.ExtraFieldParsingMode.values())
              System.out.println(c);

      Returns:
        an array containing the constants of this enum type, in the order they are declared

    - #### valueOf

          public static ZipArchiveEntry.ExtraFieldParsingMode valueOf(String name)

      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
        `name` - the name of the enum constant to be returned.
      Returns:
        the enum constant with the specified name
      Throws:
        `IllegalArgumentException` - if this enum type has no constant with the specified name
        `NullPointerException` - if the argument is null

    - #### onUnparseableExtraField

          public ZipExtraField onUnparseableExtraField(byte[] data,
                                                       int off,
                                                       int len,
                                                       boolean local,
                                                       int claimedLength)
                                                throws ZipException

      Description copied from interface: `UnparseableExtraFieldBehavior`
      Decides what to do with extra field data that doesn't follow the recommended pattern.
      Specified by:
        `onUnparseableExtraField` in interface `UnparseableExtraFieldBehavior`
      Parameters:
        `data` - the array of extra field data
        `off` - offset into data where the unparseable data starts
        `len` - the length of unparseable data
        `local` - whether the extra field data stems from the local file header. If this is false then the data is part if the central directory header extra data.
        `claimedLength` - length of the extra field claimed by the third and forth byte if it did follow the recommended pattern
      Returns:
        null if the data should be ignored or an extra field implementation that represents the data
      Throws:
        `ZipException` - if an error occurs or unparseable extra fields must not be accepted

    - #### createExtraField

          public ZipExtraField createExtraField(ZipShort headerId)
                                         throws ZipException,
                                                InstantiationException,
                                                IllegalAccessException

      Description copied from interface: `ExtraFieldParsingBehavior`
      Creates an instance of ZipExtraField for the given id.

      A good default implementation would be `ExtraFieldUtils.createExtraField(org.apache.commons.compress.archivers.zip.ZipShort)`.

      Specified by:
        `createExtraField` in interface `ExtraFieldParsingBehavior`
      Parameters:
        `headerId` - the id for the extra field
      Returns:
        an instance of ZipExtraField, must not be `null`
      Throws:
        `ZipException` - if an error occurs
        `InstantiationException` - if unable to instantiate the class
        `IllegalAccessException` - if not allowed to instantiate the class

    - #### fill

          public ZipExtraField fill(ZipExtraField field,
                                    byte[] data,
                                    int off,
                                    int len,
                                    boolean local)
                             throws ZipException

      Description copied from interface: `ExtraFieldParsingBehavior`
      Fills in the extra field data for a single extra field.

      A good default implementation would be `ExtraFieldUtils.fillExtraField(org.apache.commons.compress.archivers.zip.ZipExtraField, byte[], int, int, boolean)`.

      Specified by:
        `fill` in interface `ExtraFieldParsingBehavior`
      Parameters:
        `field` - the extra field instance to fill
        `data` - the array of extra field data
        `off` - offset into data where this field's data starts
        `len` - the length of this field's data
        `local` - whether the extra field data stems from the local file header. If this is false then the data is part if the central directory header extra data.
      Returns:
        the filled field. Usually this is the same as `field` but it could be a replacement extra field as well. Must not be `null`.
      Throws:
        `ZipException` - if an error occurs

Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.