Top Description Inners Fields Constructors Methods
org.apache.commons.compress.archivers.zip

public Class ExtraFieldUtils

extends Object
Class Inheritance
Imports
java.lang.reflect.Constructor, java.util.ArrayList, .List, .Objects, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, java.util.function.Supplier, java.util.zip.ZipException

ZipExtraField related methods.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ExtraFieldUtils.UnparseableExtraField

"enum" for the possible actions to take if the extra field cannot be parsed.

Field Summary

Modifier and TypeField and Description
pack-priv static final ZipExtraField[]
private static final ConcurrentMap<ZipShort, Supplier<ZipExtraField>>
IMPLEMENTATIONS

Static registry of known extra fields.

private static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static ZipExtraField

Returns:

an instance of the appropriate ExtraField
createExtraField
(final ZipShort
the header identifier
headerId
)

Creates an instance of the appropriate ExtraField, falls back to UnrecognizedExtraField.

public static ZipExtraField

Returns:

an instance of the appropriate ZipExtraField or null if the id is not supported
createExtraFieldNoDefault
(final ZipShort
the header identifier
headerId
)

Creates an instance of the appropriate ZipExtraField.

public static ZipExtraField

Returns:

the filled field, will never be null
fillExtraField
(final ZipExtraField
the extra field instance to fill
ze
,
final byte[]
the array of extra field data
data
,
final int
offset into data where this field's data starts
off
,
final int
the length of this field's data
len
,
final boolean
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.
local
)

Fills in the extra field data into the given instance.

public static byte[]

Returns:

an array of bytes
mergeCentralDirectoryData
(final ZipExtraField[]
an array of ExtraFields
data
)

Merges the central directory fields of the given ZipExtraFields.

public static byte[]

Returns:

an array of bytes
mergeLocalFileDataData
(final ZipExtraField[]
an array of ExtraFiles
data
)

Merges the local file data fields of the given ZipExtraFields.

public static ZipExtraField[]

Returns:

an array of ExtraFields
parse
(final byte[]
an array of bytes as it appears in local file data
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.

public static ZipExtraField[]

Returns:

an array of ExtraFields
parse
(final byte[]
an array of bytes
data
,
final boolean
whether data originates from the local file data or the central directory
local
)

Parses the array into ExtraFields and populate them with the given data, throwing an exception if the data cannot be parsed.

public static ZipExtraField[]

Returns:

an array of ExtraFields
parse
(final byte[]
an array of bytes
data
,
final boolean
whether data originates from the local file data or the central directory
local
,
final ExtraFieldParsingBehavior
controls parsing of extra fields.
parsingBehavior
)

Parses the array into ExtraFields and populate them with the given data.

public static ZipExtraField[]

Returns:

an array of ExtraFields
parse
(final byte[]
an array of bytes
data
,
final boolean
whether data originates from the local file data or the central directory
local
,
final ExtraFieldUtils.UnparseableExtraField
what to do if the extra field data cannot be parsed.
onUnparseableData
)

Parses the array into ExtraFields and populate them with the given data.

public static void
register(final Class<?>
the class to register.
clazz
)

Deprecated Use ZipArchiveInputStream#setExtraFieldSupport instead to not leak instances between archives and applications.
Registers a ZipExtraField implementation, overriding a matching existing entry.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_ZIP_EXTRA_FIELD_ARRAYback to summary
pack-priv static final ZipExtraField[] EMPTY_ZIP_EXTRA_FIELD_ARRAY
IMPLEMENTATIONSback to summary
private static final ConcurrentMap<ZipShort, Supplier<ZipExtraField>> IMPLEMENTATIONS

Static registry of known extra fields.

WORDback to summary
private static final int WORD

Constructor Detail

ExtraFieldUtilsback to summary
public ExtraFieldUtils()

Method Detail

createExtraFieldback to summary
public static ZipExtraField createExtraField(final ZipShort headerId)

Creates an instance of the appropriate ExtraField, falls back to UnrecognizedExtraField.

Parameters
headerId:ZipShort

the header identifier

Returns:ZipExtraField

an instance of the appropriate ExtraField

createExtraFieldNoDefaultback to summary
public static ZipExtraField createExtraFieldNoDefault(final ZipShort headerId)

Creates an instance of the appropriate ZipExtraField.

Parameters
headerId:ZipShort

the header identifier

Returns:ZipExtraField

an instance of the appropriate ZipExtraField or null if the id is not supported

Since
1.19
fillExtraFieldback to summary
public static ZipExtraField fillExtraField(final ZipExtraField ze, final byte[] data, final int off, final int len, final boolean local) throws ZipException

Fills in the extra field data into the given instance.

Calls ZipExtraField#parseFromCentralDirectoryData or ZipExtraField#parseFromLocalFileData internally and wraps any ArrayIndexOutOfBoundsException thrown into a ZipException.

Parameters
ze:ZipExtraField

the extra field instance to fill

data:byte[]

the array of extra field data

off:int

offset into data where this field's data starts

len:int

the length of this field's data

local:boolean

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:ZipExtraField

the filled field, will never be null

Exceptions
ZipException:
if an error occurs
Since
1.19
mergeCentralDirectoryDataback to summary
public static byte[] mergeCentralDirectoryData(final ZipExtraField[] data)

Merges the central directory fields of the given ZipExtraFields.

Parameters
data:ZipExtraField[]

an array of ExtraFields

Returns:byte[]

an array of bytes

mergeLocalFileDataDataback to summary
public static byte[] mergeLocalFileDataData(final ZipExtraField[] data)

Merges the local file data fields of the given ZipExtraFields.

Parameters
data:ZipExtraField[]

an array of ExtraFiles

Returns:byte[]

an array of bytes

parseback to summary
public static ZipExtraField[] parse(final 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:byte[]

an array of bytes as it appears in local file data

Returns:ZipExtraField[]

an array of ExtraFields

Exceptions
ZipException:
on error
parseback to summary
public static ZipExtraField[] parse(final byte[] data, final 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:byte[]

an array of bytes

local:boolean

whether data originates from the local file data or the central directory

Returns:ZipExtraField[]

an array of ExtraFields

Exceptions
ZipException:
on error
parseback to summary
public static ZipExtraField[] parse(final byte[] data, final boolean local, final ExtraFieldParsingBehavior parsingBehavior) throws ZipException

Parses the array into ExtraFields and populate them with the given data.

Parameters
data:byte[]

an array of bytes

local:boolean

whether data originates from the local file data or the central directory

parsingBehavior:ExtraFieldParsingBehavior

controls parsing of extra fields.

Returns:ZipExtraField[]

an array of ExtraFields

Exceptions
ZipException:
on error
Since
1.19
parseback to summary
public static ZipExtraField[] parse(final byte[] data, final boolean local, final ExtraFieldUtils.UnparseableExtraField onUnparseableData) throws ZipException

Parses the array into ExtraFields and populate them with the given data.

Parameters
data:byte[]

an array of bytes

local:boolean

whether data originates from the local file data or the central directory

onUnparseableData:ExtraFieldUtils.UnparseableExtraField

what to do if the extra field data cannot be parsed.

Returns:ZipExtraField[]

an array of ExtraFields

Exceptions
ZipException:
on error
Since
1.1
registerback to summary
public static void register(final Class<?> clazz)

Deprecated

Use ZipArchiveInputStream#setExtraFieldSupport 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:Class<?>

the class to register.

Annotations
@Deprecated
org.apache.commons.compress.archivers.zip back to summary

public final Class ExtraFieldUtils.UnparseableExtraField

extends Object
implements UnparseableExtraFieldBehavior
Class Inheritance
  • java.lang.Object
  • org.apache.commons.compress.archivers.zip.ExtraFieldUtils.UnparseableExtraField
All Implemented Interfaces
org.apache.commons.compress.archivers.zip.UnparseableExtraFieldBehavior

"enum" for the possible actions to take if the extra field cannot be parsed.

This class has been created long before Java 5 and would have been a real enum ever since.

Since
1.1

Field Summary

Modifier and TypeField and Description
private final int
public static final ExtraFieldUtils.UnparseableExtraField
READ

Read the extra field data into an instance of UnparseableExtraFieldData.

public static final int
READ_KEY

Key for "read" action.

public static final ExtraFieldUtils.UnparseableExtraField
SKIP

Skip the extra field entirely and don't make its data available - effectively removing the extra field data.

public static final int
SKIP_KEY

Key for "skip" action.

public static final ExtraFieldUtils.UnparseableExtraField
THROW

Throw an exception if field cannot be parsed.

public static final int
THROW_KEY

Key for "throw an exception" action.

Constructor Summary

AccessConstructor and Description
private
UnparseableExtraField(final int k)

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the key
getKey
()

Key of the action to take.

public ZipExtraField
onUnparseableExtraField(final byte[]
the array of extra field data
data
,
final int
offset into data where the unparseable data starts
off
,
final int
the length of unparseable data
len
,
final boolean
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.
local
,
final int
length of the extra field claimed by the third and forth byte if it did follow the recommended pattern
claimedLength
)

Implements org.apache.commons.compress.archivers.zip.UnparseableExtraFieldBehavior.onUnparseableExtraField.

Decides what to do with extra field data that doesn't follow the recommended pattern.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

keyback to summary
private final int key
READback to summary
public static final ExtraFieldUtils.UnparseableExtraField READ

Read the extra field data into an instance of UnparseableExtraFieldData.

READ_KEYback to summary
public static final int READ_KEY

Key for "read" action.

SKIPback to summary
public static final ExtraFieldUtils.UnparseableExtraField SKIP

Skip the extra field entirely and don't make its data available - effectively removing the extra field data.

SKIP_KEYback to summary
public static final int SKIP_KEY

Key for "skip" action.

THROWback to summary
public static final ExtraFieldUtils.UnparseableExtraField THROW

Throw an exception if field cannot be parsed.

THROW_KEYback to summary
public static final int THROW_KEY

Key for "throw an exception" action.

Constructor Detail

UnparseableExtraFieldback to summary
private UnparseableExtraField(final int k)

Method Detail

getKeyback to summary
public int getKey()

Key of the action to take.

Returns:int

the key

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

Implements org.apache.commons.compress.archivers.zip.UnparseableExtraFieldBehavior.onUnparseableExtraField.

Doc from org.apache.commons.compress.archivers.zip.UnparseableExtraFieldBehavior.onUnparseableExtraField.

Decides what to do with extra field data that doesn't follow the recommended pattern.

Parameters
data:byte[]

the array of extra field data

off:int

offset into data where the unparseable data starts

len:int

the length of unparseable data

local:boolean

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:int

length of the extra field claimed by the third and forth byte if it did follow the recommended pattern

Returns:ZipExtraField

null if the data should be ignored or an extra field implementation that represents the data

Annotations
@Override
Exceptions
ZipException:
if an error occurs or unparseable extra fields must not be accepted