Class ExtraField
- java.lang.Object
-
- com.android.tools.build.apkzlib.zip.ExtraField
-
public class ExtraField extends java.lang.ObjectContains an extra field.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.Segmentand contains a header ID and data.Each instance of
ExtraFieldis immutable. The extra field of a particular entry can be changed by creating a new instanceofExtraFieldand pass it toStoredEntry.setLocalExtra(ExtraField).Instances of
ExtraFieldcan 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 neithergetSegments()norgetSingleSegment(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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExtraField.AlignmentSegmentSegment 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 classExtraField.RawDataSegmentSegment of raw data: this class represents a general segment containing an array of bytes as data.static interfaceExtraField.SegmentField inside the extra field.
-
Field Summary
Fields Modifier and Type Field Description static ExtraFieldEMPTY
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.google.common.collect.ImmutableList<ExtraField.Segment>getSegments()Obtains all segments in the extra field.ExtraField.SegmentgetSingleSegment(int headerId)Obtains the only segment with the provided header ID.intsize()Obtains the size of the extra field.voidwrite(java.nio.ByteBuffer out)Writes the extra field to the given output buffer.
-
-
-
Field Detail
-
EMPTY
public static final ExtraField EMPTY
-
-
Constructor Detail
-
ExtraField
public ExtraField(byte[] rawData)
Creates an extra field based on existing raw data.- Parameters:
rawData- the raw data; will not be parsed unless needed
-
ExtraField
public ExtraField()
Creates a new extra field with no segments.
-
ExtraField
public ExtraField(com.google.common.collect.ImmutableList<ExtraField.Segment> segments)
Creates a new extra field with the given segments.- Parameters:
segments- the segments
-
-
Method Detail
-
getSegments
public com.google.common.collect.ImmutableList<ExtraField.Segment> getSegments() throws java.io.IOException
Obtains all segments in the extra field.- Returns:
- all segments
- Throws:
java.io.IOException- failed to parse the extra field
-
getSingleSegment
@Nullable public ExtraField.Segment getSingleSegment(int headerId) throws java.io.IOException
Obtains the only segment with the provided header ID.- Parameters:
headerId- the header ID- Returns:
- the segment found or
nullif no segment contains the provided header ID - Throws:
java.io.IOException- there is more than one header with the provided header ID
-
size
public int size()
Obtains the size of the extra field.- Returns:
- the size
-
write
public void write(java.nio.ByteBuffer out) throws java.io.IOExceptionWrites the extra field to the given output buffer.- Parameters:
out- the output buffer to write the field; exactlysize()bytes will be written- Throws:
java.io.IOException- failed to write the extra fields
-
-