Package com.android.dx.util
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
ConstructorDescriptionConstructs 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 TypeMethodDescriptionvoid
alignTo
(int alignment) Adds extra bytes if necessary (with value0
) to force alignment of the output cursor as given.void
Add an annotation for a specified amount of subsequent output.void
Add an annotation for the subsequent output.boolean
Get whether this instance will actually keep annotations.void
assertCursor
(int expectedCursor) Asserts that the cursor is the given value.void
enableAnnotations
(int annotationWidth, boolean verbose) Indicates that this instance should keep annotations.void
End the most recent annotation.void
Finishes up annotation processing.int
Get the maximum width of the annotated output.byte[]
getArray()
Gets the underlyingbyte[]
of this instance, which may be larger than the number of bytes writtenint
Gets the current cursor position.boolean
Get 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).void
write
(byte[] bytes) Writes abyte[]
to this instance.void
write
(byte[] bytes, int offset, int length) Writes a portion of abyte[]
to this instance.void
Writes aByteArray
to this instance.void
writeAnnotationsTo
(Writer out) Writes the annotated content of this instance to the given writer.void
writeByte
(int value) Writes abyte
to this instance.void
writeInt
(int value) Writes anint
to this instance.void
writeLong
(long value) Writes along
to this instance.void
writeShort
(int value) Writes ashort
to this instance.int
writeSleb128
(int value) Writes a DWARFv3-style unsigned LEB128 integer.int
writeUleb128
(int value) Writes a DWARFv3-style unsigned LEB128 integer.void
writeZeroes
(int count) Writes the given number of0
bytes.
-
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
public int getCursor()Gets the current cursor position. This is the same as the number of bytes written to this instance. -
assertCursor
public void assertCursor(int expectedCursor) Asserts that the cursor is the given value.- Specified by:
assertCursor
in interfaceOutput
- Parameters:
expectedCursor
- the expected cursor value
-
writeByte
public void writeByte(int value) Writes abyte
to this instance.- Specified by:
writeByte
in interfaceByteOutput
- Specified by:
writeByte
in interfaceOutput
- Parameters:
value
- the value to write; all but the low 8 bits are ignored
-
writeShort
public void writeShort(int value) Writes ashort
to this instance.- Specified by:
writeShort
in interfaceOutput
- Parameters:
value
- the value to write; all but the low 16 bits are ignored
-
writeInt
public void writeInt(int value) Writes anint
to this instance. -
writeLong
public void writeLong(long value) Writes along
to this instance. -
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:
writeUleb128
in 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:
writeSleb128
in interfaceOutput
- Parameters:
value
- value to write- Returns:
1..5;
the number of bytes actually written
-
write
Writes aByteArray
to this instance. -
write
public void write(byte[] bytes, int offset, int length) Writes a portion of abyte[]
to this instance. -
write
public void write(byte[] bytes) Writes abyte[]
to this instance. This is just a convenient shorthand forwrite(bytes, 0, bytes.length)
. -
writeZeroes
public void writeZeroes(int count) Writes the given number of0
bytes.- Specified by:
writeZeroes
in interfaceOutput
- Parameters:
count
->= 0;
the number of zeroes to write
-
alignTo
public void alignTo(int alignment) Adds extra bytes if necessary (with value0
) to force alignment of the output cursor as given. -
annotates
public boolean annotates()Get whether this instance will actually keep annotations.- Specified by:
annotates
in interfaceAnnotatedOutput
- Returns:
true
iff 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:
isVerbose
in interfaceAnnotatedOutput
- Returns:
true
iff 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:
annotate
in 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:
annotate
in 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(java.lang.String)
.- Specified by:
endAnnotation
in 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:
getAnnotationWidth
in 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
-