Class PackageChunk

  • All Implemented Interfaces:
    SerializableResource

    public final class PackageChunk
    extends ChunkWithChunks
    A package chunk is a collection of resource data types within a package.
    • Constructor Detail

      • PackageChunk

        protected PackageChunk​(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 ChunkWithChunks
        Parameters:
        buffer - The buffer that the payload will be initialized from.
      • getId

        public int getId()
        Returns the package id if this is a base package, or 0 if not a base package.
      • getKeyStringPool

        public StringPoolChunk getKeyStringPool()
        Returns the string pool that contains the names of the resources in this package.
      • getTypeStringPool

        public StringPoolChunk getTypeStringPool()
        Returns the string pool that contains the type strings for this package, such as "layout", "string", "color".
      • getTypeChunks

        public java.util.Collection<TypeChunk> getTypeChunks()
        Returns all TypeChunk in this package.
      • getTypeChunks

        public java.util.Collection<TypeChunk> getTypeChunks​(int id)
        For a given type id, returns the TypeChunk objects that match that id. The type id is the 1-based index of the type in the type string pool (returned by getTypeStringPool()).
        Parameters:
        id - The 1-based type id to return TypeChunk objects for.
        Returns:
        The matching TypeChunk objects, or an empty collection if there are none.
      • getTypeChunks

        public java.util.Collection<TypeChunk> getTypeChunks​(java.lang.String type)
        For a given type, returns the TypeChunk objects that match that type (e.g. "attr", "id", "string", ...).
        Parameters:
        type - The type to return TypeChunk objects for.
        Returns:
        The matching TypeChunk objects, or an empty collection if there are none.
      • getTypeSpecChunk

        public TypeSpecChunk getTypeSpecChunk​(int id)
        For a given (1-based) type id, returns the TypeSpecChunk matching it.
      • getTypeSpecChunk

        public TypeSpecChunk getTypeSpecChunk​(java.lang.String type)
        For a given type, returns the TypeSpecChunk that matches it (e.g. "attr", "id", "string", ...).
      • getPackageName

        public java.lang.String getPackageName()
        Returns the name of this package.
      • 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 ChunkWithChunks
        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).