Enum ZipArchiveEntry.ExtraFieldParsingMode

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<ZipArchiveEntry.ExtraFieldParsingMode>, ExtraFieldParsingBehavior, UnparseableExtraFieldBehavior
    Enclosing class:
    ZipArchiveEntry

    public static enum ZipArchiveEntry.ExtraFieldParsingMode
    extends java.lang.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 Detail

      • 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​(java.lang.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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • onUnparseableExtraField

        public ZipExtraField onUnparseableExtraField​(byte[] data,
                                                     int off,
                                                     int len,
                                                     boolean local,
                                                     int claimedLength)
                                              throws java.util.zip.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:
        java.util.zip.ZipException - if an error occurs or unparseable extra fields must not be accepted
      • fill

        public ZipExtraField fill​(ZipExtraField field,
                                  byte[] data,
                                  int off,
                                  int len,
                                  boolean local)
                           throws java.util.zip.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:
        java.util.zip.ZipException - if an error occurs