Class ExtraField


  • public class ExtraField
    extends java.lang.Object
    Contains 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.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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class 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.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static ExtraField EMPTY  
    • 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.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 null if 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.IOException
        Writes the extra field to the given output buffer.
        Parameters:
        out - the output buffer to write the field; exactly size() bytes will be written
        Throws:
        java.io.IOException - failed to write the extra fields