Top Description Inners Fields Constructors Methods
org.droidparts.dexmaker.dx.util

public final Class ByteArrayAnnotatedOutput

extends Object
implements AnnotatedOutput, ByteOutput
Class Inheritance
All Implemented Interfaces
org.droidparts.dexmaker.dx.util.ByteOutput, org.droidparts.dexmaker.dx.util.AnnotatedOutput, org.droidparts.dexmaker.dx.util.Output
Imports
java.io.IOException, .Writer, java.util.ArrayList

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private ArrayList<ByteArrayAnnotatedOutput.Annotation>
annotations

null-ok; list of annotations, or null if this instance isn't keeping them

private int
annotationWidth

>= 40 (if used); the desired maximum annotation width

private int
cursor

>= 0; current output cursor

private byte[]
data

non-null; the data itself

private static final int
DEFAULT_SIZE

default size for stretchy instances

private int
hexCols

>= 8 (if used); the number of bytes of hex output to use in annotations

private final boolean
stretchy

whether the instance is stretchy, that is, whether its array may be resized to increase capacity

private boolean
verbose

whether annotations are to be verbose

Constructor Summary

AccessConstructor and Description
public
ByteArrayAnnotatedOutput(byte[]
non-null; data array to use for output
data
)

Constructs an instance with a fixed maximum size.

public
ByteArrayAnnotatedOutput()

Constructs a "stretchy" instance.

public
ByteArrayAnnotatedOutput(int size)

Constructs a "stretchy" instance with initial size size.

private
ByteArrayAnnotatedOutput(byte[]
non-null; data array to use for output
data
,
boolean
whether the instance is to be stretchy
stretchy
)

Internal constructor.

Method Summary

Modifier and TypeMethod and Description
public void
alignTo(int
> 0; the alignment; must be a power of two
alignment
)

Implements org.droidparts.dexmaker.dx.util.Output.alignTo.

Adds extra bytes if necessary (with value 0) to force alignment of the output cursor as given.
public void
annotate(String
non-null; the annotation message
msg
)

Implements org.droidparts.dexmaker.dx.util.AnnotatedOutput.annotate.

Add an annotation for the subsequent output.
public void
annotate(int
>= 0; the amount of output for this annotation to cover
amt
,
String
non-null; the annotation message
msg
)

Implements org.droidparts.dexmaker.dx.util.AnnotatedOutput.annotate.

Add an annotation for a specified amount of subsequent output.
public boolean
annotates()

Implements org.droidparts.dexmaker.dx.util.AnnotatedOutput.annotates.

Get whether this instance will actually keep annotations.
public void
assertCursor(int
the expected cursor value
expectedCursor
)

Implements org.droidparts.dexmaker.dx.util.Output.assertCursor.

Asserts that the cursor is the given value.
public void
enableAnnotations(int
>= 40; the desired maximum annotation width
annotationWidth
,
boolean
whether or not to indicate verbose annotations
verbose
)

Indicates that this instance should keep annotations.

public void
private void
ensureCapacity(int
>= 0; the desired minimum total size of the array
desiredSize
)

Reallocates the underlying array if necessary.

public void
finishAnnotating()

Finishes up annotation processing.

public int
getAnnotationWidth()

Implements org.droidparts.dexmaker.dx.util.AnnotatedOutput.getAnnotationWidth.

Get the maximum width of the annotated output.
public byte[]

Returns:

non-null; the byte[]
getArray
()

Gets the underlying byte[] of this instance, which may be larger than the number of bytes written

public int
getCursor()

Implements org.droidparts.dexmaker.dx.util.Output.getCursor.

Gets the current cursor position.
public boolean
isVerbose()

Implements org.droidparts.dexmaker.dx.util.AnnotatedOutput.isVerbose.

Get whether this instance is intended to keep verbose annotations.
private static void
throwBounds()

Throws the excpetion for when an attempt is made to write past the end of the instance.

public byte[]

Returns:

non-null; an appropriately-constructed array
toByteArray
()

Constructs and returns a new byte[] that contains the written contents exactly (that is, with no extra unwritten bytes at the end).

public void
write(ByteArray
non-null; the array to write
bytes
)

Implements org.droidparts.dexmaker.dx.util.Output.write.

Writes a ByteArray to this instance.
public void
write(byte[]
non-null; the array to write
bytes
,
int
>= 0; offset into bytes for the first byte to write
offset
,
int
>= 0; number of bytes to write
length
)

Implements org.droidparts.dexmaker.dx.util.Output.write.

Writes a portion of a byte[] to this instance.
public void
write(byte[]
non-null; the array to write
bytes
)

Implements org.droidparts.dexmaker.dx.util.Output.write.

Writes a byte[] to this instance.
public void
writeAnnotationsTo(Writer
non-null; where to write to
out
)

Writes the annotated content of this instance to the given writer.

public void
writeByte(int
the value to write; all but the low 8 bits are ignored
value
)

Implements org.droidparts.dexmaker.dx.util.Output.writeByte, org.droidparts.dexmaker.dx.util.ByteOutput.writeByte.

Writes a byte.
public void
writeInt(int
the value to write
value
)

Implements org.droidparts.dexmaker.dx.util.Output.writeInt.

Writes an int to this instance.
public void
writeLong(long
the value to write
value
)

Implements org.droidparts.dexmaker.dx.util.Output.writeLong.

Writes a long to this instance.
public void
writeShort(int
the value to write; all but the low 16 bits are ignored
value
)

Implements org.droidparts.dexmaker.dx.util.Output.writeShort.

Writes a short to this instance.
public int
writeSleb128(int
value to write
value
)

Implements org.droidparts.dexmaker.dx.util.Output.writeSleb128.

Writes a DWARFv3-style unsigned LEB128 integer.
public int
writeUleb128(int
value to write, treated as an unsigned value
value
)

Implements org.droidparts.dexmaker.dx.util.Output.writeUleb128.

Writes a DWARFv3-style unsigned LEB128 integer.
public void
writeZeroes(int
>= 0; the number of zeroes to write
count
)

Implements org.droidparts.dexmaker.dx.util.Output.writeZeroes.

Writes the given number of 0 bytes.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

annotationsback to summary
private ArrayList<ByteArrayAnnotatedOutput.Annotation> annotations

null-ok; list of annotations, or null if this instance isn't keeping them

annotationWidthback to summary
private int annotationWidth

>= 40 (if used); the desired maximum annotation width

cursorback to summary
private int cursor

>= 0; current output cursor

databack to summary
private byte[] data

non-null; the data itself

DEFAULT_SIZEback to summary
private static final int DEFAULT_SIZE

default size for stretchy instances

hexColsback to summary
private int hexCols

>= 8 (if used); the number of bytes of hex output to use in annotations

stretchyback to summary
private final boolean stretchy

whether the instance is stretchy, that is, whether its array may be resized to increase capacity

verboseback to summary
private boolean verbose

whether annotations are to be verbose

Constructor Detail

ByteArrayAnnotatedOutputback to summary
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:byte[]

non-null; data array to use for output

ByteArrayAnnotatedOutputback to summary
public ByteArrayAnnotatedOutput()

Constructs a "stretchy" instance. The underlying array may be reallocated. The constructed instance does not keep annotations by default.

ByteArrayAnnotatedOutputback to summary
public ByteArrayAnnotatedOutput(int size)

Constructs a "stretchy" instance with initial size size. The underlying array may be reallocated. The constructed instance does not keep annotations by default.

ByteArrayAnnotatedOutputback to summary
private ByteArrayAnnotatedOutput(byte[] data, boolean stretchy)

Internal constructor.

Parameters
data:byte[]

non-null; data array to use for output

stretchy:boolean

whether the instance is to be stretchy

Method Detail

alignToback to summary
public void alignTo(int alignment)

Implements org.droidparts.dexmaker.dx.util.Output.alignTo.

Doc from org.droidparts.dexmaker.dx.util.Output.alignTo.

Adds extra bytes if necessary (with value 0) to force alignment of the output cursor as given.

Parameters
alignment:int

> 0; the alignment; must be a power of two

annotateback to summary
public void annotate(String msg)

Implements org.droidparts.dexmaker.dx.util.AnnotatedOutput.annotate.

Doc from org.droidparts.dexmaker.dx.util.AnnotatedOutput.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.

Parameters
msg:String

non-null; the annotation message

annotateback to summary
public void annotate(int amt, String msg)

Implements org.droidparts.dexmaker.dx.util.AnnotatedOutput.annotate.

Doc from org.droidparts.dexmaker.dx.util.AnnotatedOutput.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.

Parameters
amt:int

>= 0; the amount of output for this annotation to cover

msg:String

non-null; the annotation message

annotatesback to summary
public boolean annotates()

Implements org.droidparts.dexmaker.dx.util.AnnotatedOutput.annotates.

Doc from org.droidparts.dexmaker.dx.util.AnnotatedOutput.annotates.

Get whether this instance will actually keep annotations.

Returns:boolean

true iff annotations are being kept

assertCursorback to summary
public void assertCursor(int expectedCursor)

Implements org.droidparts.dexmaker.dx.util.Output.assertCursor.

Doc from org.droidparts.dexmaker.dx.util.Output.assertCursor.

Asserts that the cursor is the given value.

Parameters
expectedCursor:int

the expected cursor value

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

>= 40; the desired maximum annotation width

verbose:boolean

whether or not to indicate verbose annotations

endAnnotationback to summary
public void endAnnotation()

Implements org.droidparts.dexmaker.dx.util.AnnotatedOutput.endAnnotation.

Doc from org.droidparts.dexmaker.dx.util.AnnotatedOutput.endAnnotation.

End the most recent annotation. Subsequent output will be unannotated, until the next call to annotate.

ensureCapacityback to summary
private void ensureCapacity(int desiredSize)

Reallocates the underlying array if necessary. Calls to this method should be guarded by a test of stretchy.

Parameters
desiredSize:int

>= 0; the desired minimum total size of the array

finishAnnotatingback to summary
public void finishAnnotating()

Finishes up annotation processing. This closes off any open annotations and removes annotations that don't refer to written data.

getAnnotationWidthback to summary
public int getAnnotationWidth()

Implements org.droidparts.dexmaker.dx.util.AnnotatedOutput.getAnnotationWidth.

Doc from org.droidparts.dexmaker.dx.util.AnnotatedOutput.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.

Returns:int

>= 1; the maximum width

getArrayback to summary
public byte[] getArray()

Gets the underlying byte[] of this instance, which may be larger than the number of bytes written

Returns:byte[]

non-null; the byte[]

See Also
toByteArray
getCursorback to summary
public int getCursor()

Implements org.droidparts.dexmaker.dx.util.Output.getCursor.

Doc from org.droidparts.dexmaker.dx.util.Output.getCursor.

Gets the current cursor position. This is the same as the number of bytes written to this instance.

Returns:int

>= 0; the cursor position

isVerboseback to summary
public boolean isVerbose()

Implements org.droidparts.dexmaker.dx.util.AnnotatedOutput.isVerbose.

Doc from org.droidparts.dexmaker.dx.util.AnnotatedOutput.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.

Returns:boolean

true iff annotations are to be verbose

throwBoundsback to summary
private static void throwBounds()

Throws the excpetion for when an attempt is made to write past the end of the instance.

toByteArrayback to summary
public byte[] toByteArray()

Constructs and returns a new byte[] that contains the written contents exactly (that is, with no extra unwritten bytes at the end).

Returns:byte[]

non-null; an appropriately-constructed array

See Also
getArray
writeback to summary
public void write(ByteArray bytes)

Implements org.droidparts.dexmaker.dx.util.Output.write.

Doc from org.droidparts.dexmaker.dx.util.Output.write.

Writes a ByteArray to this instance.

Parameters
bytes:ByteArray

non-null; the array to write

writeback to summary
public void write(byte[] bytes, int offset, int length)

Implements org.droidparts.dexmaker.dx.util.Output.write.

Doc from org.droidparts.dexmaker.dx.util.Output.write.

Writes a portion of a byte[] to this instance.

Parameters
bytes:byte[]

non-null; the array to write

offset:int

>= 0; offset into bytes for the first byte to write

length:int

>= 0; number of bytes to write

writeback to summary
public void write(byte[] bytes)

Implements org.droidparts.dexmaker.dx.util.Output.write.

Doc from org.droidparts.dexmaker.dx.util.Output.write.

Writes a byte[] to this instance. This is just a convenient shorthand for write(bytes, 0, bytes.length).

Parameters
bytes:byte[]

non-null; the array to write

writeAnnotationsToback to summary
public void writeAnnotationsTo(Writer out) throws IOException

Writes the annotated content of this instance to the given writer.

Parameters
out:Writer

non-null; where to write to

writeByteback to summary
public void writeByte(int value)

Implements org.droidparts.dexmaker.dx.util.Output.writeByte, org.droidparts.dexmaker.dx.util.ByteOutput.writeByte.

Doc from org.droidparts.dexmaker.dx.util.ByteOutput.writeByte.

Writes a byte.

Parameters
value:int

Doc from org.droidparts.dexmaker.dx.util.Output.writeByte.

the value to write; all but the low 8 bits are ignored

writeIntback to summary
public void writeInt(int value)

Implements org.droidparts.dexmaker.dx.util.Output.writeInt.

Doc from org.droidparts.dexmaker.dx.util.Output.writeInt.

Writes an int to this instance.

Parameters
value:int

the value to write

writeLongback to summary
public void writeLong(long value)

Implements org.droidparts.dexmaker.dx.util.Output.writeLong.

Doc from org.droidparts.dexmaker.dx.util.Output.writeLong.

Writes a long to this instance.

Parameters
value:long

the value to write

writeShortback to summary
public void writeShort(int value)

Implements org.droidparts.dexmaker.dx.util.Output.writeShort.

Doc from org.droidparts.dexmaker.dx.util.Output.writeShort.

Writes a short to this instance.

Parameters
value:int

the value to write; all but the low 16 bits are ignored

writeSleb128back to summary
public int writeSleb128(int value)

Implements org.droidparts.dexmaker.dx.util.Output.writeSleb128.

Doc from org.droidparts.dexmaker.dx.util.Output.writeSleb128.

Writes a DWARFv3-style unsigned LEB128 integer. For details, see the "Dalvik Executable Format" document or DWARF v3 section 7.6.

Parameters
value:int

value to write

Returns:int

1..5; the number of bytes actually written

writeUleb128back to summary
public int writeUleb128(int value)

Implements org.droidparts.dexmaker.dx.util.Output.writeUleb128.

Doc from org.droidparts.dexmaker.dx.util.Output.writeUleb128.

Writes a DWARFv3-style unsigned LEB128 integer. For details, see the "Dalvik Executable Format" document or DWARF v3 section 7.6.

Parameters
value:int

value to write, treated as an unsigned value

Returns:int

1..5; the number of bytes actually written

writeZeroesback to summary
public void writeZeroes(int count)

Implements org.droidparts.dexmaker.dx.util.Output.writeZeroes.

Doc from org.droidparts.dexmaker.dx.util.Output.writeZeroes.

Writes the given number of 0 bytes.

Parameters
count:int

>= 0; the number of zeroes to write

org.droidparts.dexmaker.dx.util back to summary

private Class ByteArrayAnnotatedOutput.Annotation

extends Object
Class Inheritance
  • java.lang.Object
  • org.droidparts.dexmaker.dx.util.ByteArrayAnnotatedOutput.Annotation

Annotation on output.

Field Summary

Modifier and TypeField and Description
private int
end

>= 0; end of annotated range (exclusive); Integer.MAX_VALUE if unclosed

private final int
start

>= 0; start of annotated range (inclusive)

private final String
text

non-null; annotation text

Constructor Summary

AccessConstructor and Description
public
Annotation(int
>= 0; start of annotated range
start
,
int
>= start; end of annotated range (exclusive) or Integer.MAX_VALUE if unclosed
end
,
String
non-null; annotation text
text
)

Constructs an instance.

public
Annotation(int
>= 0; start of annotated range
start
,
String
non-null; annotation text
text
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the end
getEnd
()

Gets the end.

public int

Returns:

the start
getStart
()

Gets the start.

public String

Returns:

non-null; the text
getText
()

Gets the text.

public void
setEnd(int
>= start; the end
end
)

Sets the end as given.

public void
setEndIfUnset(int
>= start; the end
end
)

Sets the end as given, but only if the instance is unclosed; otherwise, do nothing.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

endback to summary
private int end

>= 0; end of annotated range (exclusive); Integer.MAX_VALUE if unclosed

startback to summary
private final int start

>= 0; start of annotated range (inclusive)

textback to summary
private final String text

non-null; annotation text

Constructor Detail

Annotationback to summary
public Annotation(int start, int end, String text)

Constructs an instance.

Parameters
start:int

>= 0; start of annotated range

end:int

>= start; end of annotated range (exclusive) or Integer.MAX_VALUE if unclosed

text:String

non-null; annotation text

Annotationback to summary
public Annotation(int start, String text)

Constructs an instance. It is initally unclosed.

Parameters
start:int

>= 0; start of annotated range

text:String

non-null; annotation text

Method Detail

getEndback to summary
public int getEnd()

Gets the end.

Returns:int

the end

getStartback to summary
public int getStart()

Gets the start.

Returns:int

the start

getTextback to summary
public String getText()

Gets the text.

Returns:String

non-null; the text

setEndback to summary
public void setEnd(int end)

Sets the end as given.

Parameters
end:int

>= start; the end

setEndIfUnsetback to summary
public void setEndIfUnset(int end)

Sets the end as given, but only if the instance is unclosed; otherwise, do nothing.

Parameters
end:int

>= start; the end