Class TypeChunk
- java.lang.Object
-
- com.google.devrel.gmscore.tools.apk.arsc.Chunk
-
- com.google.devrel.gmscore.tools.apk.arsc.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 aPackageChunk. The resource values in this chunk correspond to the array of type strings in the enclosingPackageChunk.A
PackageChunkcan have multiple of these chunks for different (configuration, resource type) combinations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTypeChunk.EntryAnTypeChunk.Entryin aTypeChunk.-
Nested classes/interfaces inherited from class com.google.devrel.gmscore.tools.apk.arsc.Chunk
Chunk.Type
-
-
Field Summary
-
Fields inherited from class com.google.devrel.gmscore.tools.apk.arsc.Chunk
chunkSize, headerSize, METADATA_SIZE, offset, PAD_BOUNDARY
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsResource(BinaryResourceIdentifier resourceId)Returns true if this chunk contains an entry forresourceId.BinaryResourceConfigurationgetConfiguration()Returns the resource configuration that these resource entries correspond to.java.util.Map<java.lang.Integer,TypeChunk.Entry>getEntries()Returns a sparse list of 0-based indices to resource entries defined by this chunk.intgetId()Returns the (1-based) type id of the resource types that thisTypeChunkis holding.protected java.lang.StringgetKeyName(int index)PackageChunkgetPackageChunk()Returns the package enclosing this chunk, if any.protected java.lang.StringgetString(int index)intgetTotalEntryCount()Returns the total number of entries for this type + configuration, including null entries.protected Chunk.TypegetType()java.lang.StringgetTypeName()Returns the name of the type this chunk represents (e.g.protected voidinit(java.nio.ByteBuffer buffer)Finishes initialization of a chunk.voidoverrideEntries(java.util.Map<java.lang.Integer,TypeChunk.Entry> entries)Overrides the entries in this chunk at the given index:entry pairs inentries.voidoverrideEntry(int index, TypeChunk.Entry entry)Overrides an entry at the given index.voidsetConfiguration(BinaryResourceConfiguration configuration)Sets the resource configuration that this chunk's entries correspond to.protected voidwriteHeader(java.nio.ByteBuffer output)Writes the remaining header (after the type,headerSize, andchunkSize).protected voidwritePayload(java.io.DataOutput output, java.nio.ByteBuffer header, boolean shrink)Writes the chunk payload.-
Methods inherited from class com.google.devrel.gmscore.tools.apk.arsc.Chunk
getHeaderSize, getOriginalChunkSize, getParent, newInstance, newInstance, toByteArray, toByteArray, writeHeader, writePad
-
-
-
-
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:ChunkFinishes 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.
-
getId
public int getId()
Returns the (1-based) type id of the resource types that thisTypeChunkis 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 forresourceId.
-
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 inentries. For example, if the current list of entries is {0: foo, 1: bar, 2: baz}, andentriesis {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 theentrywill remove that entry fromentries. 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.
-
getType
protected Chunk.Type getType()
-
writeHeader
protected void writeHeader(java.nio.ByteBuffer output)
Description copied from class:ChunkWrites the remaining header (after the type,headerSize, andchunkSize).- Overrides:
writeHeaderin classChunk- 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.IOExceptionDescription copied from class:ChunkWrites the chunk payload. The payload is data in a chunk which is not in the firstheaderSizebytes of the chunk.- Overrides:
writePayloadin classChunk- 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 ifoutputcould not be written to (out of memory).
-
-