Class StringPoolChunk
- java.lang.Object
-
- com.google.devrel.gmscore.tools.apk.arsc.Chunk
-
- com.google.devrel.gmscore.tools.apk.arsc.StringPoolChunk
-
- All Implemented Interfaces:
SerializableResource
public final class StringPoolChunk extends Chunk
Represents a string pool structure.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStringPoolChunk.StringPoolStyleRepresents all of the styles for a particular string.-
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
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedStringPoolChunk(java.nio.ByteBuffer buffer, Chunk parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetString(int index)Returns a string at the given (0-based) index.intgetStringCount()Returns the number of strings in this pool.BinaryResourceString.TypegetStringType()Returns the type of strings in this pool.StringPoolChunk.StringPoolStylegetStyle(int index)Returns a style at the given (0-based) index.intgetStyleCount()Returns the number of styles in this pool.protected Chunk.TypegetType()intindexOf(java.lang.String string)Returns the 0-based index of the first occurrence of the given string, or -1 if the string is not in the pool.protected voidinit(java.nio.ByteBuffer buffer)Finishes initialization of a chunk.booleanisSorted()True if this string pool contains already-sorted strings.booleanisUTF8()True if this string pool contains strings in UTF-8 format.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
-
StringPoolChunk
protected StringPoolChunk(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.
-
indexOf
public int indexOf(java.lang.String string)
Returns the 0-based index of the first occurrence of the given string, or -1 if the string is not in the pool. This runs in O(n) time.- Parameters:
string- The string to check the pool for.- Returns:
- Index of the string, or -1 if not found.
-
getString
public java.lang.String getString(int index)
Returns a string at the given (0-based) index.- Parameters:
index- The (0-based) index of the string to return.- Throws:
java.lang.IndexOutOfBoundsException- If the index is out of range (index < 0 || index >= size()).
-
getStringCount
public int getStringCount()
Returns the number of strings in this pool.
-
getStyle
public StringPoolChunk.StringPoolStyle getStyle(int index)
Returns a style at the given (0-based) index.- Parameters:
index- The (0-based) index of the style to return.- Throws:
java.lang.IndexOutOfBoundsException- If the index is out of range (index < 0 || index >= size()).
-
getStyleCount
public int getStyleCount()
Returns the number of styles in this pool.
-
getStringType
public BinaryResourceString.Type getStringType()
Returns the type of strings in this pool.
-
getType
protected Chunk.Type getType()
-
isUTF8
public boolean isUTF8()
True if this string pool contains strings in UTF-8 format. Otherwise, strings are in UTF-16.- Returns:
- true if @{code strings} are in UTF-8; false if they're in UTF-16.
-
isSorted
public boolean isSorted()
True if this string pool contains already-sorted strings.- Returns:
- true if @{code strings} are sorted.
-
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).
-
-