- java.lang.Object
-
- kala.compress.compressors.gzip.ExtraField
-
- All Implemented Interfaces:
java.lang.Iterable<ExtraField.SubField>
public class ExtraField extends java.lang.Object implements java.lang.Iterable<ExtraField.SubField>
If theFLG.FEXTRAbit is set, an "extra field" is present in the header, with total length XLEN bytes. It consists of a series of subfields, each of the form:+---+---+---+---+==================================+ |SI1|SI2| LEN |... LEN bytes of subfield data ...| +---+---+---+---+==================================+
This class does not expose the internal subfields list to prevent adding subfields without total extra length validation. However a copy of the list is available.- Since:
- 1.28.0
- See Also:
- RFC 1952 GZIP File Format Specification
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExtraField.SubFieldIf theFLG.FEXTRAbit is set, an "extra field" is present in the header, with total length XLEN bytes.
-
Field Summary
Fields Modifier and Type Field Description private static intMAX_SIZEprivate java.util.List<ExtraField.SubField>subFieldsprivate inttotalSizeprivate static byte[]ZERO_BYTES
-
Constructor Summary
Constructors Constructor Description ExtraField()Constructs a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ExtraFieldaddSubField(java.lang.String id, byte[] payload)Append a subfield by a 2-chars ISO-8859-1 string.(package private) static ExtraFieldfromBytes(byte[] bytes)ExtraField.SubFieldgetSubFieldAt(int index)Gets the subfield at the given index.java.util.Iterator<ExtraField.SubField>iterator()Returns an iterator over the SubField elements in this extra field in proper sequence.(package private) byte[]toByteArray()
-
-
-
Field Detail
-
MAX_SIZE
private static final int MAX_SIZE
- See Also:
- Constant Field Values
-
ZERO_BYTES
private static final byte[] ZERO_BYTES
-
subFields
private final java.util.List<ExtraField.SubField> subFields
-
totalSize
private int totalSize
-
-
Method Detail
-
fromBytes
static ExtraField fromBytes(byte[] bytes) throws java.io.IOException
- Throws:
java.io.IOException
-
addSubField
public ExtraField addSubField(java.lang.String id, byte[] payload) throws java.io.IOException
Append a subfield by a 2-chars ISO-8859-1 string. The char at index 0 and 1 are respectiovely si1 and si2 (subfield id 1 and 2).- Parameters:
id- The subfield ID.payload- The subfield payload.- Returns:
- this instance.
- Throws:
java.lang.NullPointerException- ifidisnull.java.lang.NullPointerException- ifpayloadisnull.java.lang.IllegalArgumentException- if the subfield is not 2 characters or the payload is nulljava.io.IOException- if appending this subfield would exceed the max size 65535 of the extra header.
-
getSubFieldAt
public ExtraField.SubField getSubFieldAt(int index)
Gets the subfield at the given index.- Parameters:
index- index of the element to return- Returns:
- the subfield at the specified position in this list
- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size())
-
iterator
public java.util.Iterator<ExtraField.SubField> iterator()
Returns an iterator over the SubField elements in this extra field in proper sequence.- Specified by:
iteratorin interfacejava.lang.Iterable<ExtraField.SubField>- Returns:
- an iterator over the SubField elements in this extra field in proper sequence.
-
toByteArray
byte[] toByteArray()
-
-