Class ByteArrayAnnotatedOutput
java.lang.Object
com.android.dx.util.ByteArrayAnnotatedOutput
- All Implemented Interfaces:
ByteOutput, AnnotatedOutput, Output
Implementation of
AnnotatedOutput which stores the written data
into a byte[].
Note: As per the Output interface, multi-byte
writes all use little-endian order.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a "stretchy" instance.ByteArrayAnnotatedOutput(byte[] data) Constructs an instance with a fixed maximum size.ByteArrayAnnotatedOutput(int size) Constructs a "stretchy" instance with initial sizesize. -
Method Summary
Modifier and TypeMethodDescriptionvoidalignTo(int alignment) Adds extra bytes if necessary (with value0) to force alignment of the output cursor as given.voidAdd an annotation for a specified amount of subsequent output.voidAdd an annotation for the subsequent output.booleanGet whether this instance will actually keep annotations.voidassertCursor(int expectedCursor) Asserts that the cursor is the given value.voidenableAnnotations(int annotationWidth, boolean verbose) Indicates that this instance should keep annotations.voidEnd the most recent annotation.voidFinishes up annotation processing.intGet the maximum width of the annotated output.byte[]getArray()Gets the underlyingbyte[]of this instance, which may be larger than the number of bytes writtenintGets the current cursor position.booleanGet whether this instance is intended to keep verbose annotations.byte[]Constructs and returns a newbyte[]that contains the written contents exactly (that is, with no extra unwritten bytes at the end).voidwrite(byte[] bytes) Writes abyte[]to this instance.voidwrite(byte[] bytes, int offset, int length) Writes a portion of abyte[]to this instance.voidWrites aByteArrayto this instance.voidwriteAnnotationsTo(Writer out) Writes the annotated content of this instance to the given writer.voidwriteByte(int value) Writes abyteto this instance.voidwriteInt(int value) Writes anintto this instance.voidwriteLong(long value) Writes alongto this instance.voidwriteShort(int value) Writes ashortto this instance.intwriteSleb128(int value) Writes a DWARFv3-style unsigned LEB128 integer.intwriteUleb128(int value) Writes a DWARFv3-style unsigned LEB128 integer.voidwriteZeroes(int count) Writes the given number of0bytes.
-
Constructor Details
-
ByteArrayAnnotatedOutput
public ByteArrayAnnotatedOutput(byte[] data) Constructs an instance with a fixed maximum size. Note that the given array is the only one that will be used to store data. In particular, no reallocation will occur in order to expand the capacity of the resulting instance. Also, the constructed instance does not keep annotations by default.- Parameters:
data-non-null;data array to use for output
-
ByteArrayAnnotatedOutput
public ByteArrayAnnotatedOutput()Constructs a "stretchy" instance. The underlying array may be reallocated. The constructed instance does not keep annotations by default. -
ByteArrayAnnotatedOutput
public ByteArrayAnnotatedOutput(int size) Constructs a "stretchy" instance with initial sizesize. The underlying array may be reallocated. The constructed instance does not keep annotations by default.
-
-
Method Details
-
getArray
public byte[] getArray()Gets the underlyingbyte[]of this instance, which may be larger than the number of bytes written- Returns:
non-null;thebyte[]- See Also:
-
toByteArray
public byte[] toByteArray()Constructs and returns a newbyte[]that contains the written contents exactly (that is, with no extra unwritten bytes at the end).- Returns:
non-null;an appropriately-constructed array- See Also:
-
getCursor
-
assertCursor
public void assertCursor(int expectedCursor) Asserts that the cursor is the given value.- Specified by:
assertCursorin interfaceOutput- Parameters:
expectedCursor- the expected cursor value
-
writeByte
public void writeByte(int value) Writes abyteto this instance.- Specified by:
writeBytein interfaceByteOutput- Specified by:
writeBytein interfaceOutput- Parameters:
value- the value to write; all but the low 8 bits are ignored
-
writeShort
public void writeShort(int value) Writes ashortto this instance.- Specified by:
writeShortin interfaceOutput- Parameters:
value- the value to write; all but the low 16 bits are ignored
-
writeInt
-
writeLong
-
writeUleb128
public int writeUleb128(int value) Writes a DWARFv3-style unsigned LEB128 integer. For details, see the "Dalvik Executable Format" document or DWARF v3 section 7.6.- Specified by:
writeUleb128in interfaceOutput- Parameters:
value- value to write, treated as an unsigned value- Returns:
1..5;the number of bytes actually written
-
writeSleb128
public int writeSleb128(int value) Writes a DWARFv3-style unsigned LEB128 integer. For details, see the "Dalvik Executable Format" document or DWARF v3 section 7.6.- Specified by:
writeSleb128in interfaceOutput- Parameters:
value- value to write- Returns:
1..5;the number of bytes actually written
-
write
-
write
-
write
-
writeZeroes
public void writeZeroes(int count) Writes the given number of0bytes.- Specified by:
writeZeroesin interfaceOutput- Parameters:
count->= 0;the number of zeroes to write
-
alignTo
-
annotates
public boolean annotates()Get whether this instance will actually keep annotations.- Specified by:
annotatesin interfaceAnnotatedOutput- Returns:
trueiff annotations are being kept
-
isVerbose
public boolean isVerbose()Get whether this instance is intended to keep verbose annotations. Annotators may use the result of calling this method to inform their annotation activity.- Specified by:
isVerbosein interfaceAnnotatedOutput- Returns:
trueiff annotations are to be verbose
-
annotate
Add an annotation for the subsequent output. Any previously open annotation will be closed by this call, and the new annotation marks all subsequent output until another annotation call.- Specified by:
annotatein interfaceAnnotatedOutput- Parameters:
msg-non-null;the annotation message
-
annotate
Add an annotation for a specified amount of subsequent output. Any previously open annotation will be closed by this call. If there is already pending annotation from one or more previous calls to this method, the new call "consumes" output after all the output covered by the previous calls.- Specified by:
annotatein interfaceAnnotatedOutput- Parameters:
amt->= 0;the amount of output for this annotation to covermsg-non-null;the annotation message
-
endAnnotation
public void endAnnotation()End the most recent annotation. Subsequent output will be unannotated, until the next call toAnnotatedOutput.annotate(String).- Specified by:
endAnnotationin interfaceAnnotatedOutput
-
getAnnotationWidth
public int getAnnotationWidth()Get the maximum width of the annotated output. This is advisory: Implementations of this interface are encouraged to deal with too-wide output, but annotaters are encouraged to attempt to avoid exceeding the indicated width.- Specified by:
getAnnotationWidthin interfaceAnnotatedOutput- Returns:
>= 1;the maximum width
-
enableAnnotations
public void enableAnnotations(int annotationWidth, boolean verbose) Indicates that this instance should keep annotations. This method may be called only once per instance, and only before any data has been written to the it.- Parameters:
annotationWidth->= 40;the desired maximum annotation widthverbose- whether or not to indicate verbose annotations
-
finishAnnotating
public void finishAnnotating()Finishes up annotation processing. This closes off any open annotations and removes annotations that don't refer to written data. -
writeAnnotationsTo
Writes the annotated content of this instance to the given writer.- Parameters:
out-non-null;where to write to- Throws:
IOException
-