Class TypeChunk

  • All Implemented Interfaces:
    SerializableResource

    public final class TypeChunk
    extends Chunk
    Represents a type chunk, which contains the resource values for a specific resource type and configuration in a PackageChunk. The resource values in this chunk correspond to the array of type strings in the enclosing PackageChunk.

    A PackageChunk can have multiple of these chunks for different (configuration, resource type) combinations.

    • Constructor Detail

      • TypeChunk

        protected TypeChunk​(java.nio.ByteBuffer buffer,
                            @Nullable
                            Chunk parent)
    • Method Detail

      • init

        protected void init​(java.nio.ByteBuffer buffer)
        Description copied from class: Chunk
        Finishes initialization of a chunk. This should be called immediately after the constructor. This is separate from the constructor so that the header of a chunk can be fully initialized before the payload of that chunk is initialized for chunks that require such behavior.
        Overrides:
        init in class Chunk
        Parameters:
        buffer - The buffer that the payload will be initialized from.
      • getId

        public int getId()
        Returns the (1-based) type id of the resource types that this TypeChunk is holding.
      • getTypeName

        public java.lang.String getTypeName()
        Returns the name of the type this chunk represents (e.g. string, attr, id).
      • getConfiguration

        public BinaryResourceConfiguration getConfiguration()
        Returns the resource configuration that these resource entries correspond to.
      • setConfiguration

        public void setConfiguration​(BinaryResourceConfiguration configuration)
        Sets the resource configuration that this chunk's entries correspond to.
        Parameters:
        configuration - The new configuration.
      • getTotalEntryCount

        public int getTotalEntryCount()
        Returns the total number of entries for this type + configuration, including null entries.
      • getEntries

        public java.util.Map<java.lang.Integer,​TypeChunk.Entry> getEntries()
        Returns a sparse list of 0-based indices to resource entries defined by this chunk.
      • containsResource

        public boolean containsResource​(BinaryResourceIdentifier resourceId)
        Returns true if this chunk contains an entry for resourceId.
      • overrideEntries

        public void overrideEntries​(java.util.Map<java.lang.Integer,​TypeChunk.Entry> entries)
        Overrides the entries in this chunk at the given index:entry pairs in entries. For example, if the current list of entries is {0: foo, 1: bar, 2: baz}, and entries is {1: qux, 3: quux}, then the entries will be changed to {0: foo, 1: qux, 2: baz}. If an entry has an index that does not exist in the dense entry list, then it is considered a no-op for that single entry.
        Parameters:
        entries - A sparse list containing index:entry pairs to override.
      • overrideEntry

        public void overrideEntry​(int index,
                                  @Nullable
                                  TypeChunk.Entry entry)
        Overrides an entry at the given index. Passing null for the entry will remove that entry from entries. Indices < 0 or >= getTotalEntryCount() are a no-op.
        Parameters:
        index - The 0-based index for the entry to override.
        entry - The entry to override, or null if the entry should be removed at this location.
      • getString

        protected java.lang.String getString​(int index)
      • getKeyName

        protected java.lang.String getKeyName​(int index)
      • getPackageChunk

        @Nullable
        public PackageChunk getPackageChunk()
        Returns the package enclosing this chunk, if any. Else, returns null.
      • writeHeader

        protected void writeHeader​(java.nio.ByteBuffer output)
        Description copied from class: Chunk
        Writes the remaining header (after the type, headerSize, and chunkSize).
        Overrides:
        writeHeader in class Chunk
        Parameters:
        output - The buffer that the header will be written to.
      • writePayload

        protected void writePayload​(java.io.DataOutput output,
                                    java.nio.ByteBuffer header,
                                    boolean shrink)
                             throws java.io.IOException
        Description copied from class: Chunk
        Writes the chunk payload. The payload is data in a chunk which is not in the first headerSize bytes of the chunk.
        Overrides:
        writePayload in class Chunk
        Parameters:
        output - The stream that the payload will be written to.
        header - The already-written header. This can be modified to fix payload offsets.
        shrink - True if this payload should be optimized for size.
        Throws:
        java.io.IOException - Thrown if output could not be written to (out of memory).