Methods Summary |
---|
protected final void | align(com.android.dx.util.AnnotatedOutput out)Aligns the output of the given data to the alignment of this instance.
out.alignTo(alignment);
|
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 {@link
#setFileOffset}).
Note: Subclasses must implement this as appropriate for
their contents.
|
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 {@link
#setFileOffset}).
if (relative < 0) {
throw new IllegalArgumentException("relative < 0");
}
if (fileOffset < 0) {
throw new RuntimeException("fileOffset not yet set");
}
return fileOffset + relative;
|
public final int | getAlignment()Gets the alignment for this instance's final output.
return alignment;
|
public final DexFile | getFile()Gets the file that this instance is part of.
return file;
|
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.
if (fileOffset < 0) {
throw new RuntimeException("fileOffset not set");
}
return fileOffset;
|
protected final java.lang.String | getName()Returns the name of this section, for annotation purposes.
return name;
|
public abstract java.util.Collection | items()Gets the collection of all the items in this section.
It is not valid to attempt to change the returned list.
|
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.
throwIfPrepared();
prepare0();
prepared = true;
|
protected abstract void | prepare0()Does the main work of {@link #prepare}.
|
public final int | setFileOffset(int fileOffset)Sets the file offset. It is only valid to call this method once
once per instance.
if (fileOffset < 0) {
throw new IllegalArgumentException("fileOffset < 0");
}
if (this.fileOffset >= 0) {
throw new RuntimeException("fileOffset already set");
}
int mask = alignment - 1;
fileOffset = (fileOffset + mask) & ~mask;
this.fileOffset = fileOffset;
return fileOffset;
|
protected final void | throwIfNotPrepared()Throws an exception if {@link #prepare} has not been
called on this instance.
if (!prepared) {
throw new RuntimeException("not prepared");
}
|
protected final void | throwIfPrepared()Throws an exception if {@link #prepare} has already been called
on this instance.
if (prepared) {
throw new RuntimeException("already prepared");
}
|
public static void | validateAlignment(int alignment)Validates an alignment.
if ((alignment <= 0) ||
(alignment & (alignment - 1)) != 0) {
throw new IllegalArgumentException("invalid alignment");
}
|
public abstract int | writeSize()Gets the size of this instance when output, in bytes.
|
public final void | writeTo(com.android.dx.util.AnnotatedOutput out)Writes this instance to the given raw data object.
throwIfNotPrepared();
align(out);
int cursor = out.getCursor();
if (fileOffset < 0) {
fileOffset = cursor;
} else if (fileOffset != cursor) {
throw new RuntimeException("alignment mismatch: for " + this +
", at " + cursor +
", but expected " + fileOffset);
}
if (out.annotates()) {
if (name != null) {
out.annotate(0, "\n" + name + ":");
} else if (cursor != 0) {
out.annotate(0, "\n");
}
}
writeTo0(out);
|
protected abstract void | writeTo0(com.android.dx.util.AnnotatedOutput out)Writes this instance to the given raw data object. This gets
called by {@link #writeTo} after aligning the cursor of
{@code out} and verifying that either the assigned file
offset matches the actual cursor {@code out} or that the
file offset was not previously assigned, in which case it gets
assigned to {@code out}'s cursor.
|