Top Description Fields Constructors Methods
org.droidparts.dexmaker.dx.dex.file

public abstract Class Section

extends Object
Class Inheritance
Known Direct Subclasses
org.droidparts.dexmaker.dx.dex.file.UniformItemSection, org.droidparts.dexmaker.dx.dex.file.MixedItemSection
Imports
org.droidparts.dexmaker.dx.util.AnnotatedOutput, java.util.Collection

A section of a .dex file. Each section consists of a list of items of some sort or other.

Field Summary

Modifier and TypeField and Description
private final int
alignment

> 0; alignment requirement for the final output; must be a power of 2

private final DexFile
file

non-null; file that this instance is part of

private int
fileOffset

>= -1; offset from the start of the file to this part, or -1 if not yet known

private final String
name

null-ok; name of this part, for annotation purposes

private boolean
prepared

whether prepare has been called successfully on this instance

Constructor Summary

AccessConstructor and Description
public
Section(String
null-ok; the name of this instance, for annotation purposes
name
,
DexFile
non-null; file that this instance is part of
file
,
int
> 0; alignment requirement for the final output; must be a power of 2
alignment
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
protected final void
align(AnnotatedOutput
non-null; the output to align
out
)

Aligns the output of the given data to the alignment of this instance.

public abstract int

Returns:

>= 0; the item's absolute file offset
getAbsoluteItemOffset
(Item
non-null; the item in question
item
)

Returns the absolute file offset of the given item which must be contained in this section.

public final int

Returns:

>= 0; the corresponding absolute file offset
getAbsoluteOffset
(int
>= 0; the relative offset
relative
)

Returns the absolute file offset, given an offset from the start of this instance's output.

public final int

Returns:

> 0; the alignment
getAlignment
()

Gets the alignment for this instance's final output.

public final DexFile

Returns:

non-null; the file
getFile
()

Gets the file that this instance is part of.

public final int

Returns:

>= 0; the file offset
getFileOffset
()

Gets the offset from the start of the file to this part.

protected final String

Returns:

null-ok; name of this part, for annotation purposes
getName
()

Returns the name of this section, for annotation purposes.

public abstract Collection<? extends Item>

Returns:

non-null; the items
items
()

Gets the collection of all the items in this section.

public final void
prepare()

Prepares this instance for writing.

protected abstract void
prepare0()

Does the main work of prepare.

public final int

Returns:

>= 0; the offset that this instance should be placed at in order to meet its alignment constraint
setFileOffset
(int
>= 0; the desired offset from the start of the file where this for this instance
fileOffset
)

Sets the file offset.

protected final void
throwIfNotPrepared()

Throws an exception if prepare has not been called on this instance.

protected final void
throwIfPrepared()

Throws an exception if prepare has already been called on this instance.

public static void
validateAlignment(int
the alignment
alignment
)

Validates an alignment.

public abstract int

Returns:

>= 0; the size of this instance, in bytes
writeSize
()

Gets the size of this instance when output, in bytes.

public final void
writeTo(AnnotatedOutput
non-null; where to write to
out
)

Writes this instance to the given raw data object.

protected abstract void
writeTo0(AnnotatedOutput
non-null; where to write to
out
)

Writes this instance to the given raw data object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

alignmentback to summary
private final int alignment

> 0; alignment requirement for the final output; must be a power of 2

fileback to summary
private final DexFile file

non-null; file that this instance is part of

fileOffsetback to summary
private int fileOffset

>= -1; offset from the start of the file to this part, or -1 if not yet known

nameback to summary
private final String name

null-ok; name of this part, for annotation purposes

preparedback to summary
private boolean prepared

whether prepare has been called successfully on this instance

Constructor Detail

Sectionback to summary
public Section(String name, DexFile file, int alignment)

Constructs an instance. The file offset is initially unknown.

Parameters
name:String

null-ok; the name of this instance, for annotation purposes

file:DexFile

non-null; file that this instance is part of

alignment:int

> 0; alignment requirement for the final output; must be a power of 2

Method Detail

alignback to summary
protected final void align(AnnotatedOutput out)

Aligns the output of the given data to the alignment of this instance.

Parameters
out:AnnotatedOutput

non-null; the output to align

getAbsoluteItemOffsetback to summary
public abstract int getAbsoluteItemOffset(Item item)

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 (via setFileOffset).

Note

Subclasses must implement this as appropriate for their contents.

Parameters
item:Item

non-null; the item in question

Returns:int

>= 0; the item's absolute file offset

getAbsoluteOffsetback to summary
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 (via setFileOffset).

Parameters
relative:int

>= 0; the relative offset

Returns:int

>= 0; the corresponding absolute file offset

getAlignmentback to summary
public final int getAlignment()

Gets the alignment for this instance's final output.

Returns:int

> 0; the alignment

getFileback to summary
public final DexFile getFile()

Gets the file that this instance is part of.

Returns:DexFile

non-null; the file

getFileOffsetback to summary
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:int

>= 0; the file offset

getNameback to summary
protected final String getName()

Returns the name of this section, for annotation purposes.

Returns:String

null-ok; name of this part, for annotation purposes

itemsback to summary
public abstract Collection<? extends Item> items()

Gets the collection of all the items in this section. It is not valid to attempt to change the returned list.

Returns:Collection<? extends Item>

non-null; the items

prepareback to summary
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.

prepare0back to summary
protected abstract void prepare0()

Does the main work of prepare.

setFileOffsetback to summary
public final int setFileOffset(int fileOffset)

Sets the file offset. It is only valid to call this method once once per instance.

Parameters
fileOffset:int

>= 0; the desired offset from the start of the file where this for this instance

Returns:int

>= 0; the offset that this instance should be placed at in order to meet its alignment constraint

throwIfNotPreparedback to summary
protected final void throwIfNotPrepared()

Throws an exception if prepare has not been called on this instance.

throwIfPreparedback to summary
protected final void throwIfPrepared()

Throws an exception if prepare has already been called on this instance.

validateAlignmentback to summary
public static void validateAlignment(int alignment)

Validates an alignment.

Parameters
alignment:int

the alignment

Exceptions
IllegalArgumentException:
thrown if alignment isn't a positive power of 2
writeSizeback to summary
public abstract int writeSize()

Gets the size of this instance when output, in bytes.

Returns:int

>= 0; the size of this instance, in bytes

writeToback to summary
public final void writeTo(AnnotatedOutput out)

Writes this instance to the given raw data object.

Parameters
out:AnnotatedOutput

non-null; where to write to

writeTo0back to summary
protected abstract void writeTo0(AnnotatedOutput out)

Writes this instance to the given raw data object. This gets called by writeTo after aligning the cursor of out and verifying that either the assigned file offset matches the actual cursor out or that the file offset was not previously assigned, in which case it gets assigned to out's cursor.

Parameters
out:AnnotatedOutput

non-null; where to write to