public class ExtraField
extends java.lang.Object
According to the zip specification, the extra field is composed of a sequence of fields. This class provides a way to access, parse and modify that information.
The zip specification calls fields to the fields inside the extra field. Because this
terminology is confusing, we use segment to refer to a part of the extra field. Each
segment is represented by an instance of ExtraField.Segment and contains a header ID and data.
Each instance of ExtraField is immutable. The extra field of a particular entry can be
changed by creating a new instanceof ExtraField and pass it to StoredEntry.setLocalExtra(ExtraField).
Instances of ExtraField can be created directly from the list of segments in it or
from the raw byte data. If created from the raw byte data, the data will only be parsed on
demand. So, if neither getSegments() nor getSingleSegment(int) is invoked, the
extra field will not be parsed. This guarantees low performance impact of the using the extra
field unless its contents are needed.
| Modifier and Type | Class and Description |
|---|---|
static class |
ExtraField.AlignmentSegment
Segment with information on an alignment: this segment contains information on how an entry
should be aligned and contains zero-filled data to force alignment.
|
static class |
ExtraField.RawDataSegment
Segment of raw data: this class represents a general segment containing an array of bytes as
data.
|
static interface |
ExtraField.Segment
Field inside the extra field.
|
| Constructor and Description |
|---|
ExtraField()
Creates a new extra field with no segments.
|
ExtraField(byte[] rawData)
Creates an extra field based on existing raw data.
|
ExtraField(com.google.common.collect.ImmutableList<ExtraField.Segment> segments)
Creates a new extra field with the given segments.
|
| Modifier and Type | Method and Description |
|---|---|
com.google.common.collect.ImmutableList<ExtraField.Segment> |
getSegments()
Obtains all segments in the extra field.
|
ExtraField.Segment |
getSingleSegment(int headerId)
Obtains the only segment with the provided header ID.
|
int |
size()
Obtains the size of the extra field.
|
void |
write(java.nio.ByteBuffer out)
Writes the extra field to the given output buffer.
|
public ExtraField(byte[] rawData)
rawData - the raw data; will not be parsed unless neededpublic ExtraField()
public ExtraField(com.google.common.collect.ImmutableList<ExtraField.Segment> segments)
segments - the segmentspublic com.google.common.collect.ImmutableList<ExtraField.Segment> getSegments() throws java.io.IOException
java.io.IOException - failed to parse the extra field@Nullable public ExtraField.Segment getSingleSegment(int headerId) throws java.io.IOException
headerId - the header IDnull if no segment contains the provided header IDjava.io.IOException - there is more than one header with the provided header IDpublic int size()
public void write(java.nio.ByteBuffer out)
throws java.io.IOException
out - the output buffer to write the field; exactly size() bytes will be writtenjava.io.IOException - failed to write the extra fields