public final class ByteArrayAnnotatedOutput extends java.lang.Object implements AnnotatedOutput, ByteOutput
AnnotatedOutput which stores the written data
into a byte[].
Note: As per the Output interface, multi-byte
writes all use little-endian order.
| Constructor and Description |
|---|
ByteArrayAnnotatedOutput()
Constructs a "stretchy" instance.
|
ByteArrayAnnotatedOutput(byte[] data)
Constructs an instance with a fixed maximum size.
|
ByteArrayAnnotatedOutput(int size)
Constructs a "stretchy" instance with initial size
size. |
| Modifier and Type | Method and Description |
|---|---|
void |
alignTo(int alignment)
Adds extra bytes if necessary (with value
0) to
force alignment of the output cursor as given. |
void |
annotate(int amt,
java.lang.String msg)
Add an annotation for a specified amount of subsequent
output.
|
void |
annotate(java.lang.String msg)
Add an annotation for the subsequent output.
|
boolean |
annotates()
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 |
endAnnotation()
End the most recent annotation.
|
void |
finishAnnotating()
Finishes up annotation processing.
|
int |
getAnnotationWidth()
Get the maximum width of the annotated output.
|
byte[] |
getArray()
Gets the underlying
byte[] of this instance, which
may be larger than the number of bytes written |
int |
getCursor()
Gets the current cursor position.
|
boolean |
isVerbose()
Get whether this instance is intended to keep verbose annotations.
|
byte[] |
toByteArray()
Constructs and returns a new
byte[] that contains
the written contents exactly (that is, with no extra unwritten
bytes at the end). |
void |
write(byte[] bytes)
Writes a
byte[] to this instance. |
void |
write(byte[] bytes,
int offset,
int length)
Writes a portion of a
byte[] to this instance. |
void |
write(ByteArray bytes)
Writes a
ByteArray to this instance. |
void |
writeAnnotationsTo(java.io.Writer out)
Writes the annotated content of this instance to the given writer.
|
void |
writeByte(int value)
Writes a
byte to this instance. |
void |
writeInt(int value)
Writes an
int to this instance. |
void |
writeLong(long value)
Writes a
long to this instance. |
void |
writeShort(int value)
Writes a
short 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 of
0 bytes. |
public ByteArrayAnnotatedOutput(byte[] data)
data - non-null; data array to use for outputpublic ByteArrayAnnotatedOutput()
public ByteArrayAnnotatedOutput(int size)
size. The
underlying array may be reallocated. The constructed instance does not
keep annotations by default.public byte[] getArray()
byte[] of this instance, which
may be larger than the number of bytes writtennon-null; the byte[]toByteArray()public byte[] toByteArray()
byte[] that contains
the written contents exactly (that is, with no extra unwritten
bytes at the end).non-null; an appropriately-constructed arraygetArray()public int getCursor()
public void assertCursor(int expectedCursor)
assertCursor in interface OutputexpectedCursor - the expected cursor valuepublic void writeByte(int value)
byte to this instance.writeByte in interface ByteOutputwriteByte in interface Outputvalue - the value to write; all but the low 8 bits are ignoredpublic void writeShort(int value)
short to this instance.writeShort in interface Outputvalue - the value to write; all but the low 16 bits are ignoredpublic void writeInt(int value)
int to this instance.public void writeLong(long value)
long to this instance.public int writeUleb128(int value)
writeUleb128 in interface Outputvalue - value to write, treated as an unsigned value1..5; the number of bytes actually writtenpublic int writeSleb128(int value)
writeSleb128 in interface Outputvalue - value to write1..5; the number of bytes actually writtenpublic void write(byte[] bytes,
int offset,
int length)
byte[] to this instance.public void write(byte[] bytes)
byte[] to this instance. This is just
a convenient shorthand for write(bytes, 0, bytes.length).public void writeZeroes(int count)
0 bytes.writeZeroes in interface Outputcount - >= 0; the number of zeroes to writepublic void alignTo(int alignment)
0) to
force alignment of the output cursor as given.public boolean annotates()
annotates in interface AnnotatedOutputtrue iff annotations are being keptpublic boolean isVerbose()
isVerbose in interface AnnotatedOutputtrue iff annotations are to be verbosepublic void annotate(java.lang.String msg)
annotate in interface AnnotatedOutputmsg - non-null; the annotation messagepublic void annotate(int amt,
java.lang.String msg)
annotate in interface AnnotatedOutputamt - >= 0; the amount of output for this annotation to
covermsg - non-null; the annotation messagepublic void endAnnotation()
AnnotatedOutput.annotate(java.lang.String).endAnnotation in interface AnnotatedOutputpublic int getAnnotationWidth()
getAnnotationWidth in interface AnnotatedOutput>= 1; the maximum widthpublic void enableAnnotations(int annotationWidth,
boolean verbose)
annotationWidth - >= 40; the desired maximum annotation widthverbose - whether or not to indicate verbose annotationspublic void finishAnnotating()
public void writeAnnotationsTo(java.io.Writer out)
throws java.io.IOException
out - non-null; where to write tojava.io.IOExceptionCopyright © 2020. All Rights Reserved.