Package com.android.dx.dex.file
Class Section
java.lang.Object
com.android.dx.dex.file.Section
- Direct Known Subclasses:
MixedItemSection
,UniformItemSection
A section of a
.dex
file. Each section consists of a list
of items of some sort or other.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final void
align
(AnnotatedOutput out) Aligns the output of the given data to the alignment of this instance.abstract int
getAbsoluteItemOffset
(Item item) Returns the absolute file offset of the given item which must be contained in this section.final int
getAbsoluteOffset
(int relative) Returns the absolute file offset, given an offset from the start of this instance's output.final int
Gets the alignment for this instance's final output.final DexFile
getFile()
Gets the file that this instance is part of.final int
Gets the offset from the start of the file to this part.protected final String
getName()
Returns the name of this section, for annotation purposes.abstract Collection
<? extends Item> items()
Gets the collection of all the items in this section.final void
prepare()
Prepares this instance for writing.protected abstract void
prepare0()
Does the main work ofprepare()
.final int
setFileOffset
(int fileOffset) Sets the file offset.protected final void
Throws an exception ifprepare()
has not been called on this instance.protected final void
Throws an exception ifprepare()
has already been called on this instance.static void
validateAlignment
(int alignment) Validates an alignment.abstract int
Gets the size of this instance when output, in bytes.final void
writeTo
(AnnotatedOutput out) Writes this instance to the given raw data object.protected abstract void
writeTo0
(AnnotatedOutput out) Writes this instance to the given raw data object.
-
Constructor Details
-
Section
Constructs an instance. The file offset is initially unknown.- Parameters:
name
-null-ok;
the name of this instance, for annotation purposesfile
-non-null;
file that this instance is part ofalignment
-> 0;
alignment requirement for the final output; must be a power of 2
-
-
Method Details
-
validateAlignment
public static void validateAlignment(int alignment) Validates an alignment.- Parameters:
alignment
- the alignment- Throws:
IllegalArgumentException
- thrown ifalignment
isn't a positive power of 2
-
getFile
Gets the file that this instance is part of.- Returns:
non-null;
the file
-
getAlignment
public final int getAlignment()Gets the alignment for this instance's final output.- Returns:
> 0;
the alignment
-
getFileOffset
public final int getFileOffset()Gets the offset from the start of the file to this part. This throws an exception if the offset has not yet been set.- Returns:
>= 0;
the file offset
-
setFileOffset
public final int setFileOffset(int fileOffset) Sets the file offset. It is only valid to call this method once once per instance.- Parameters:
fileOffset
->= 0;
the desired offset from the start of the file where this for this instance- Returns:
>= 0;
the offset that this instance should be placed at in order to meet its alignment constraint
-
writeTo
Writes this instance to the given raw data object.- Parameters:
out
-non-null;
where to write to
-
getAbsoluteOffset
public final int getAbsoluteOffset(int relative) Returns the absolute file offset, given an offset from the start of this instance's output. This is only valid to call once this instance has been assigned a file offset (viasetFileOffset(int)
).- Parameters:
relative
->= 0;
the relative offset- Returns:
>= 0;
the corresponding absolute file offset
-
getAbsoluteItemOffset
Returns the absolute file offset of the given item which must be contained in this section. This is only valid to call once this instance has been assigned a file offset (viasetFileOffset(int)
).Note: Subclasses must implement this as appropriate for their contents.
- Parameters:
item
-non-null;
the item in question- Returns:
>= 0;
the item's absolute file offset
-
prepare
public final void prepare()Prepares this instance for writing. This performs any necessary prerequisites, including particularly adding stuff to other sections. This method may only be called once per instance; subsequent calls will throw an exception. -
items
Gets the collection of all the items in this section. It is not valid to attempt to change the returned list.- Returns:
non-null;
the items
-
prepare0
protected abstract void prepare0()Does the main work ofprepare()
. -
writeSize
public abstract int writeSize()Gets the size of this instance when output, in bytes.- Returns:
>= 0;
the size of this instance, in bytes
-
throwIfNotPrepared
protected final void throwIfNotPrepared()Throws an exception ifprepare()
has not been called on this instance. -
throwIfPrepared
protected final void throwIfPrepared()Throws an exception ifprepare()
has already been called on this instance. -
align
Aligns the output of the given data to the alignment of this instance.- Parameters:
out
-non-null;
the output to align
-
writeTo0
Writes this instance to the given raw data object. This gets called bywriteTo(com.android.dx.util.AnnotatedOutput)
after aligning the cursor ofout
and verifying that either the assigned file offset matches the actual cursorout
or that the file offset was not previously assigned, in which case it gets assigned toout
's cursor.- Parameters:
out
-non-null;
where to write to
-
getName
Returns the name of this section, for annotation purposes.- Returns:
null-ok;
name of this part, for annotation purposes
-