Package org.apache.commons.compress.archivers.zip

# Class ExtraFieldUtils

java.lang.Object
org.apache.commons.compress.archivers.zip.ExtraFieldUtils

public class ExtraFieldUtils extends Object
`ZipExtraField` related methods.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static final class`
  `ExtraFieldUtils.UnparseableExtraField`
  "enum" for the possible actions to take if the extra field cannot be parsed.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ExtraFieldUtils()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static ZipExtraField`
  `createExtraField(ZipShort headerId)`
  Creates an instance of the appropriate ExtraField, falls back to `UnrecognizedExtraField`.
  `static ZipExtraField`
  `createExtraFieldNoDefault(ZipShort headerId)`
  Creates an instance of the appropriate `ZipExtraField`.
  `static ZipExtraField`
  `fillExtraField(ZipExtraField ze, byte[] data, int off, int len, boolean local)`
  Fills in the extra field data into the given instance.
  `static byte[]`
  `mergeCentralDirectoryData(ZipExtraField[] data)`
  Merges the central directory fields of the given ZipExtraFields.
  `static byte[]`
  `mergeLocalFileDataData(ZipExtraField[] data)`
  Merges the local file data fields of the given ZipExtraFields.
  `static ZipExtraField[]`
  `parse(byte[] data)`
  Parses the array into ExtraFields and populate them with the given data as local file data, throwing an exception if the data cannot be parsed.
  `static ZipExtraField[]`
  `parse(byte[] data, boolean local)`
  Parses the array into ExtraFields and populate them with the given data, throwing an exception if the data cannot be parsed.
  `static ZipExtraField[]`
  `parse(byte[] data, boolean local, ExtraFieldParsingBehavior parsingBehavior)`
  Parses the array into ExtraFields and populate them with the given data.
  `static ZipExtraField[]`
  `parse(byte[] data, boolean local, ExtraFieldUtils.UnparseableExtraField onUnparseableData)`
  Parses the array into ExtraFields and populate them with the given data.
  `static void`
  `register(Class<?> clazz)`
  Deprecated.
  Use `ZipArchiveInputStream.setExtraFieldSupport(java.util.function.Function<org.apache.commons.compress.archivers.zip.ZipShort, org.apache.commons.compress.archivers.zip.ZipExtraField>)` instead to not leak instances between archives and applications.

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

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ExtraFieldUtils

    public ExtraFieldUtils()

- ## Method Details

  - ### createExtraField

    public static ZipExtraField createExtraField(ZipShort headerId)
    Creates an instance of the appropriate ExtraField, falls back to `UnrecognizedExtraField`.
    Parameters:
      `headerId` - the header identifier
    Returns:
      an instance of the appropriate ExtraField

  - ### createExtraFieldNoDefault

    public static ZipExtraField createExtraFieldNoDefault(ZipShort headerId)
    Creates an instance of the appropriate `ZipExtraField`.
    Parameters:
      `headerId` - the header identifier
    Returns:
      an instance of the appropriate `ZipExtraField` or null if the id is not supported
    Since:
      1.19

  - ### fillExtraField

    public static ZipExtraField fillExtraField(ZipExtraField ze, byte[] data, int off, int len, boolean local) throws ZipException
    Fills in the extra field data into the given instance.

    Calls `ZipExtraField.parseFromCentralDirectoryData(byte[], int, int)` or `ZipExtraField.parseFromLocalFileData(byte[], int, int)` internally and wraps any `ArrayIndexOutOfBoundsException` thrown into a `ZipException`.

    Parameters:
      `ze` - 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, will never be `null`
    Throws:
      `ZipException` - if an error occurs
    Since:
      1.19

  - ### mergeCentralDirectoryData

    public static byte[] mergeCentralDirectoryData(ZipExtraField[] data)
    Merges the central directory fields of the given ZipExtraFields.
    Parameters:
      `data` - an array of ExtraFields
    Returns:
      an array of bytes

  - ### mergeLocalFileDataData

    public static byte[] mergeLocalFileDataData(ZipExtraField[] data)
    Merges the local file data fields of the given ZipExtraFields.
    Parameters:
      `data` - an array of ExtraFiles
    Returns:
      an array of bytes

  - ### parse

    public static ZipExtraField[] parse(byte[] data) throws ZipException
    Parses the array into ExtraFields and populate them with the given data as local file data, throwing an exception if the data cannot be parsed.
    Parameters:
      `data` - an array of bytes as it appears in local file data
    Returns:
      an array of ExtraFields
    Throws:
      `ZipException` - on error

  - ### parse

    public static ZipExtraField[] parse(byte[] data, boolean local) throws ZipException
    Parses the array into ExtraFields and populate them with the given data, throwing an exception if the data cannot be parsed.
    Parameters:
      `data` - an array of bytes
      `local` - whether data originates from the local file data or the central directory
    Returns:
      an array of ExtraFields
    Throws:
      `ZipException` - on error

  - ### parse

    public static ZipExtraField[] parse(byte[] data, boolean local, ExtraFieldParsingBehavior parsingBehavior) throws ZipException
    Parses the array into ExtraFields and populate them with the given data.
    Parameters:
      `data` - an array of bytes
      `parsingBehavior` - controls parsing of extra fields.
      `local` - whether data originates from the local file data or the central directory
    Returns:
      an array of ExtraFields
    Throws:
      `ZipException` - on error
    Since:
      1.19

  - ### parse

    public static ZipExtraField[] parse(byte[] data, boolean local, ExtraFieldUtils.UnparseableExtraField onUnparseableData) throws ZipException
    Parses the array into ExtraFields and populate them with the given data.
    Parameters:
      `data` - an array of bytes
      `local` - whether data originates from the local file data or the central directory
      `onUnparseableData` - what to do if the extra field data cannot be parsed.
    Returns:
      an array of ExtraFields
    Throws:
      `ZipException` - on error
    Since:
      1.1

  - ### register

    @Deprecated public static void register(Class<?> clazz)
    Deprecated.
    Use `ZipArchiveInputStream.setExtraFieldSupport(java.util.function.Function<org.apache.commons.compress.archivers.zip.ZipShort, org.apache.commons.compress.archivers.zip.ZipExtraField>)` instead to not leak instances between archives and applications.
    Registers a ZipExtraField implementation, overriding a matching existing entry.

    The given class must have a no-arg constructor and implement the `ZipExtraField interface`.

    Parameters:
      `clazz` - the class to register.