public class ByteDataAccessBase extends java.lang.Object implements InfoFormattedAppend
getInt16(int)
etc. are protected. That should prevent erratic free accesses to data
on application level. A derived class of this class structures the software for byte data access.
struct
are adequate mapped with a simple derived class of this class,
using the protected commonly access methods like _getLong(int, int)
with predefined indexes
in special methods like getValueXyz().
struct
with nested struct
inside are mapped
with one derived class per struct
, define one reference per nested struct
struct
inside a struct
(inheritance in C) can be mapped with
extra derived classes for the base struct and usind the
assignCasted(ByteDataAccessBase, int, int)
-method.
addChild(ByteDataAccessBase)
-method.
Thereby a parent should be defined, and the structs of the pack are children of this parent.
That structures need not be from the same type.
<+>--->
is a composition,
<>--->
is a aggregation, <|----
is a inherition.
+-------------------------------+ +----------+ | ByteDataAccessBase(sizeHead) |----data-------->| byte[] | |-------------------------------| | | |- idxBegin:int | | d a t a | |- idxNextChild:int | +----------+ +-------------+ |- idxEnd:int | | derivated | |-------------------------------|<---------------+ a known parent | user |---|>|+ addChild(child) |---parent-------+ set in addChild() | classes | |+ addChildFloat() | +-------------+ |% getInt32() |----currChild---+ | |<---------------+ +-------------------------------+This class is the base class for ByteDataAccess. It works without dynamic methods proper for C usage. All variables are package private because they should be changed only with methods of this class.
MyByteDataAccessRoot accessRoot = new MyByteDataAccessRoot(); //... invokes super.ByteDataAccessBase(lengthHead); accessRoot.assign(myData, dataLength);Any instances which represents a sub structure in data can be created as re-useable instances, which can be added as child of the root instance or as child of any already added child on demand:
MySubStruct subStruct = new SubStruct(); //an instance for accessing .... accessRoot.addChild(subStruct); //adds on current position. int value = subStruct.getValuexyz(); //now can access the data. .... //later on code: accessOther.addChild(subStruct); //reuse the instance for access int value = subStruct.getValueAbc(); //access other data.The instances of this derived class are helper to access to the data, they are not container for the data. The data are stored in a
byte[]
-array
addChild(ByteDataAccessBase)
: adds a child with its head size
addChild(ByteDataAccessBase, int)
: adds a child with a given length
addChildEmpty(ByteDataAccessBase)
: adds a child with its head size for writing, set all data to 0.
addChildEmpty(ByteDataAccessBase, int)
: same with given size of child.
addChildFloat(float)
, addChildInteger(int, long)
: writes the value and increments the #ixChildEnd after it.
addChildString(CharSequence)
, addChildString(CharSequence, String)
: writes the String.
getChildFloat()
, getChildDouble()
, getChildInteger(int)
: reads the value at ixNextChild
and increments the ixNextChild
.
getChildString(int)
reads a String and increments the ixNextChild
addChildAt(int, ByteDataAccessBase)
, addChildAt(int, ByteDataAccessBase, int)
: Used if the byte structure
is known. Adds a child not at #ixNextChild but at the given position.
addChild(ByteDataAccessBase, int)
.
assign(byte[], int)
with given length, not expandable
assign(byte[], int, int)
at a defined position in the data usefull for special cases.
With the given length >= the sizehead of the ByteDataAccessBase(int)
the internal flag bExpand
is set to false.
assignClear(byte[])
as empty instance, the data are cleared in its whole length.
assign(byte[], int)
with 0 as length argument as instance which only knows the head data, but the data are not cleared.
bExpand
is set to true. It means that the ixEnd()
which is set initially to the sizeHead
is increased if a child is added.
sufficingBytesForNextChild(int)
or getMaxNrofBytes()
it can be tested whether a child can be added
with its known length.
org.vishia.byteData.test.TestByteDataAccessBase
org.vishia.byteData.test.ExampleStringOrInt
InfoFormattedAppend.PrepareToString
Modifier and Type | Field and Description |
---|---|
protected boolean |
bBigEndian
Flag is set or get data in big endian or little endian (if false)
|
protected boolean |
bExc
If false then never an exception is thrown, Instead the work is done as soon as possible.
|
private boolean |
bExpand
|
protected boolean |
bLittleEndianBig2
Flag is set or get data in little endian but 2 Bytes as 16 bit word in big endian.
|
private java.nio.charset.Charset |
charset
The charset to build Strings.
|
private ByteDataAccessBase |
currChild
The last added child, null either if a child is not added or a child was added but the instance is used meanwhile otherwise.
|
protected byte[] |
data
The array containing the binary data.
|
private int |
ixBegin
Index of the beginning of the actual element in data
|
private int |
ixBeginLocal
Index of the beginning of the element inside the parent, relative to the parent.
|
private int |
ixEnd
Index of the end of the actual element in data.
|
private int |
ixNextChild
Index of the currents child end respectively the position of a new child.
|
private ByteDataAccessBase |
parent
The parent element, necessary especially for expand(), also for
removeChild(ByteDataAccessBase)
More as one children can refer the same parent. |
protected int |
sizeHead
Number of Memory locations (usual bytes) for the head of this instance's Type.
|
protected StringFormatter |
toStringformatter
Use especially for test, only used in toString().
|
static java.lang.String |
version
The version, history and license.
|
Modifier | Constructor and Description |
---|---|
|
ByteDataAccessBase(int sizeHead)
Any instance of ByteDataAccessBase is associated to a determined derived instance which has defined head size.
|
protected |
ByteDataAccessBase(int sizeHead,
int sizeData)
Deprecated.
Remark: Because
assign(byte[], int) decides on the size of data, and addChild(ByteDataAccessBase, int)
decides on the size of data of a child, this constructor makes no sense. Jchartmut 2015-04-12 |
Modifier and Type | Method and Description |
---|---|
private void |
_expand(int ixNextChildNew,
int ixEndNew)
Increments the
ixNextChild and/or increments the ixEnd of this and all parents. |
protected int |
_getInt(int idxInChild,
int nrofBytesAndSign)
Returns the content of 1 to 4 bytes inside the actual element as a int number,
big- or little-endian depending on setBigEndian().
|
protected long |
_getLong(int idxInChild,
int nrofBytesAndSign)
Returns the content of 1 to 8 bytes inside the actual element as a long number,
big- or little-endian depending on setBigEndian().
|
protected void |
_setInt(int idx,
int nrofBytes,
int val)
sets the content of 1 to 4 bytes inside the actual element as a long number,
big- or little-endian depending on setBigEndian().
|
protected void |
_setLong(int idx,
int nrofBytes,
long val)
sets the content of 1 to 8 bytes inside the actual element as a long number,
big- or little-endian depending on setBigEndian().
|
protected void |
_setString(int idx,
int nrofBytes,
java.lang.String value,
java.lang.String sEncoding,
boolean preventCtrlChars)
sets the content inside the actual element with the character bytes from the given String.
|
boolean |
addChild(ByteDataAccessBase child)
Adds a child with its given head size without additional data space.
|
boolean |
addChild(ByteDataAccessBase child,
int sizeChild)
Adds a child Element after the current child or as first child after head.
|
void |
addChildAt(int idxChild,
ByteDataAccessBase child)
Adds a child at any position with its head size.
|
void |
addChildAt(int idxChild,
ByteDataAccessBase child,
int sizeChild)
Adds a child at any position.
|
boolean |
addChildEmpty(ByteDataAccessBase child) |
boolean |
addChildEmpty(ByteDataAccessBase child,
int sizeChild) |
boolean |
addChildFloat(float value)
Adds a child for 1 float value without a child instance, and sets the value as float.
|
boolean |
addChildInt(int nrofBytes,
int value)
Adds a child for 1 integer value without a child instance, and sets the value as integer.
|
boolean |
addChildInteger(int nrofBytes,
long value)
Adds a child for 1 integer value without a child instance, and sets the value as integer.
|
void |
addChildString(java.lang.CharSequence value)
Adds a child with String value.
|
boolean |
addChildString(java.lang.CharSequence valueCs,
java.lang.String sEncoding)
Adds a child with String value.
|
boolean |
addChildString(java.lang.String value,
java.lang.String sEncoding,
boolean preventCtrlChars)
Adds a child with String value.
|
void |
assign(byte[] dataP)
Assigns the given data with its given length to read the data.
|
void |
assign(byte[] data,
int lengthData)
Assigns data with a given length.
|
void |
assign(byte[] dataP,
int lengthData,
int index)
Assigns new data to this element at given index in data.
|
void |
assignAt(int idxChildInParent,
ByteDataAccessBase parent)
assigns the element to the given position of the parents data to present a child of the parent.
|
void |
assignAt(int idxChildInParent,
int lengthChild,
ByteDataAccessBase parent)
assigns the element to the given position of the parents data to present a child of the parent
with a defined length.
|
protected void |
assignCasted(ByteDataAccessBase src,
int offsetCastToInput,
int lengthDst)
Deprecated.
it is confuse. Use
|
void |
assignClear(byte[] data)
Initializes a top level instance, the data will be cleared, set to 0, overall.
|
protected void |
assignDataToFixChildren()
This method can be overridden by Java applications for derived instances which contains elements of this class
assigned at defined positions in data.
|
(package private) boolean |
checkData()
Checks
data == null and gets the data from parent if necessary. |
boolean |
checkLengthElement(int size)
Checks whether a given size is possible as
setLengthElement(int) for the given instance. |
void |
clearData()
Sets all data of this element to 0.
|
void |
clearHead()
Sets all data of the head of this element to 0.
|
void |
copyData(int[] dst)
copies some data to a int[], primarily to debug a content.
|
void |
copyDataFrom(ByteDataAccessBase src)
copies the data from another references data into this data.
|
private void |
copyStdValues(ByteDataAccessBase src) |
byte[] |
data()
Returns the data buffer itself.
|
void |
detach()
Remove all connections.
|
boolean |
getBigEndian() |
protected char |
getChar(int idx)
Returns the content of 1 bytes as ASCII
inside the actual element.
|
double |
getChildDouble()
Adds a child for 1 double value without a child instance, but returns the value as integer.
|
float |
getChildFloat()
Adds a child for 1 float value without a child instance, but returns the value as integer.
|
int |
getChildInt(int nrofBytes)
Adds a child for 1 integer value without a child instance and returns the value as 32-bit-integer.
|
short |
getChildInt16()
Adds a child for 1 short value without a child instance, returns the value as short.
|
long |
getChildInteger(int nrofBytes)
adds a child for 1 integer value without a child instance and returns the value as long integer.
|
java.lang.String |
getChildString(int nrofBytes)
Adds a child for a String value without a child instance, but returns the value as String.
|
int |
getChildUint16()
Adds a child for 1 short value without a child instance, returns the value as short.
|
short |
getChildUint8()
Adds a child for 1 short value without a child instance, returns the value as short.
|
byte[] |
getData()
Returns the data buffer itself.
|
private byte[] |
getData(int recursion)
Gets the data from parent if
data == null |
protected double |
getDouble(int idx) |
protected float |
getFloat(int idx)
Gets a float value from the content of 4 byte.
|
protected float |
getFloat(int idxBytes,
int idxArray,
int lengthArray) |
protected short |
getInt16(int idx)
Returns the content of 2 bytes as a positive nr between 0..65535 inside the actual element.
|
protected int |
getInt16(int idxBytes,
int idxArray,
int lengthArray) |
protected int |
getInt32(int idx)
Returns the content of 4 bytes inside the actual element as a integer number between -2147483648 and 2147483647,
big- or little-endian depending on setBigEndian().
|
protected int |
getInt32(int idxBytes,
int idxArray,
int lengthArray) |
protected long |
getInt64(int idx) |
protected byte |
getInt8(int idx)
Returns the content of 1 bytes as a positive or negative nr between -128..127
inside the actual element.
|
protected int |
getInt8(int idxBytes,
int idxArray,
int lengthArray) |
int |
getLength()
Returns the length of the existing actual element.
|
int |
getLengthCurrent()
Returns the length of the element with all yet added children.
|
int |
getLengthHead()
Returns the length of the head.
|
int |
getLengthTotal()
Returns the length of the data.
|
int |
getMaxNrofBytes()
returns the number number of bytes there are max available from position of the current child
|
int |
getMaxNrofBytesForNextChild()
returns the maximal number of bytes which are available from position of a next current child.
|
int |
getPositionInBuffer()
Returns the position of the Element data in the assigned buffer.
|
int |
getPositionNextChildInBuffer()
Returns the position of a next child which can be added in the assigned buffer.
|
protected java.lang.String |
getString(int idx,
int nrofBytes)
Returns a String from the given position inside the actual element .
|
protected int |
getUint16(int idx)
Returns the content of 2 bytes as a positive nr between 0..65535, big-endian
inside the actual element.
|
protected int |
getUint16(int idxBytes,
int idxArray,
int lengthArray) |
protected int |
getUint32(int idx) |
protected int |
getUint32(int idxBytes,
int idxArray,
int lengthArray) |
protected short |
getUint8(int idx)
Returns the content of 1 bytes as a positive or negative nr between -128..127
inside the actual element.
|
protected int |
getUint8(int idxBytes,
int idxArray,
int lengthArray) |
protected void |
infoAppendHead(StringFormatter u,
int bytesHex)
Appends information about the head of the given element.
|
void |
infoFormattedAppend(StringFormatter u)
Appends the information about the indices and the current Children.
|
boolean |
isCurrentChildInParent() |
boolean |
isExpandable()
Returns true if the instance is set as expandable, see
assign(byte[], int) |
boolean |
isInUse() |
protected int |
ixBegin() |
protected int |
ixEnd() |
protected int |
ixNextChild() |
void |
removeChild()
Removes the current child to assign another current child instead on the position of the current child.
|
void |
removeChild(ByteDataAccessBase child)
Shorten the evaluated content of the data to the position of the given child.
|
void |
removeChildren()
Remove all children.
|
void |
setBigEndian(boolean val)
Sets the big or little endian mode.
|
void |
setCharset(java.lang.String value) |
protected void |
setDouble(int idx,
double value)
Set the content of 8 byte from a double variable.
|
void |
setException(boolean val)
Sets whether an exception should be thrown on adding a child or it should be return with false to continue
as soon as possible without exception handling.
|
protected void |
setFloat(int idx,
float value)
Set the content of 4 byte from a float variable.
|
protected void |
setFloat(int idxBytes,
int idxArray,
int lengthArray,
float val) |
private int |
setIdxtoNextCurrentChild(int sizeChild)
Prepares a new child for this.
|
protected void |
setInt16(int idx,
int value)
Set the content of 2 bytes from an integer between -32768..32768,
or from an integer number between 0..65535.
|
protected void |
setInt16(int idxBytes,
int idxArray,
int lengthArray,
int val) |
protected void |
setInt32(int idx,
int value)
Set the content of 4 bytes as a integer number between -2147483648 and 2147483647,
big- or little-endian depended from setBigEndian().
|
protected void |
setInt32(int idxBytes,
int idxArray,
int lengthArray,
int val) |
protected void |
setInt8(int idx,
int value)
Set the content of 1 bytes as a positive nr between 0..256.
|
protected void |
setInt8(int idxBytes,
int idxArray,
int lengthArray,
int val) |
void |
setLengthElement(int length)
Sets the length of the element in this and all
parent of this. |
void |
setLittleEndianBig2() |
protected int |
setString(int idx,
int nmax,
java.lang.String ss)
Sets a String to the the given position inside the actual element .
|
protected void |
setUint16(int idx,
int value)
Set the content of 2 bytes as a positive nr between 0..65535, big- or little-endian.
|
protected void |
setUint16(int idxBytes,
int idxArray,
int lengthArray,
int val) |
protected void |
setUint32(int idxBytes,
int idxArray,
int lengthArray,
int val) |
protected void |
setUint32(int idx,
long value)
Set the content of 4 bytes as a positive nr between 0..2pow32-1, big- or little-endian.
|
protected void |
setUint8(int idx,
int value)
Set the content of 1 bytes as a positive nr between 0..255, big- or little-endian.
|
protected void |
setUint8(int idxBytes,
int idxArray,
int lengthArray,
int val) |
int |
sizeHead()
Returns the given head size, which is set on constructor respectively which is a determined value of an derived instance of this.
|
boolean |
sufficingBytesForNextChild(int nrofBytes)
returns true if the given number of bytes is sufficing in the data from position of next child.
|
private void |
throwexc(java.lang.String text,
int idxArray) |
java.lang.String |
toString()
This method is especially usefully to debug in eclipse.
|
protected void |
upcast(ByteDataAccessBase src,
int length)
This method is intend to use to change the view to the data from a firstly simple view (src) to the really type
if the type is detected inside the (head) data of the firstly view.
|
void |
XXXrewind()
starts the calling loop of next().
|
public static final java.lang.String version
setLittleEndianBig2()
necessary if there is little endian for data, but big endian only for 16 bit image.
upcast(ByteDataAccessBase, int)
replaces the assignCasted(ByteDataAccessBase, int, int)
. Problems detect on usage of assignCasted:
The cast of a child should influence the parent because the next addChild(ByteDataAccessBase)
should regard the casting operation. The casting is regarded
to the data in sum. It is not only a isolated view to data. Strategy of upcast is documented there.
ixBeginLocal
stores the position inside the child, whereby ixBegin is global.
TODO description of strategy of fix children. It may be proper if assignData(...) will be invoked only for the derived class
which knows its fix children. The old concept of overridden methods here are not proper for simple C applications.
checkData()
.
The reason for checkData(): If a child (at an index) was not assigned with data, it gets the data from its parent now.
With them it is possible to call assign(byte[])
for the parent only and it runs.
addChild(ByteDataAccessBase)
etc. returns false if setException(boolean)
is false and the child cannot be added.
If the user invokes setException(false) the user must check the return value of the add...() operations.
setIdxtoNextCurrentChild(int)
:
This routine can throw an Exception, but it can return -1 on error too, possible with an exception message. Therewith more operations can be disabled by quest of return value.
setLengthElement(int)
should set the ixEnd of the child and the ixNextChild of the parent
but does not influence the this.ixNextChild. See test cases (TODO). This is fixed and all usages of this class for
org.vishia.insp* are tested well by testing the reflection access and GUI.
getChildInt(int)
, _getInt(int, int)
for 32 bit operation, _getLong(int, int)
uses 64 bit.
Used for in derived classes also. The 64-bit-operation is not proper for 32-bit embedded systems in C. TODO use it also if the size argument is <=4.
currChild
, proper for debug.
bExpand
charset
of type Charset
. In C it is a dummy yet.
In Java the Charset can be used immediately, more simple.
getString(int, int)
now may contain 0-character. Only the 0-bytes on end are removed because they are fill-bytes
for a 4-byte-alignment. _getString(int, int) removed because it was the same.
sizeHead
.
sizeHead
is set by construction. Only for the compatible now deprecated ByteDataAccess
the sizeHead
is able to set via the package-private #_setSizeHead(int)
.
ByteDataAccessBase(int, int)
as super constructor with given head and data size.
addChild(ByteDataAccessBase)
accepts an initialized not used child. Uses #kInitializedWithLength
.
That is the possibility to work without dynamic linked methods #specifyLengthElement()
etc. for proper work
especially for C usage. The overridden methods #specifyEmptyDefaultData()
, #notifyAddChild()
etc.
are proper to use in C too with the concept of the dynamic linked methods, but there does not be necessary.
It is an optimizing for C. Maybe in future the #specifyLengthElement()
and #specifyLengthElementHead()
may be depreciated because the new variant of initialized children is better to use, more simple for usage.
But it should be compatible with older versions.
#reset(int, int)
is protected now and has a second parameter. necessary public?
ByteDataAccessOld
can be used. It is compatible with the last version before this changes.
#reset(int)
, some comments.
protected final int sizeHead
protected byte[] data
private int ixBegin
private int ixBeginLocal
private int ixNextChild
addChild(ByteDataAccessBase, int)
with lenght=-1.private int ixEnd
bExpand
is set, this idxEnd and the idxEnd of all parents are increased
if an child was added. If bExpand==false then this value is set via the addChild(ByteDataAccessBase, int)
or addChildAt(int, ByteDataAccessBase, int)
.private boolean bExpand
protected boolean bBigEndian
protected boolean bLittleEndianBig2
protected boolean bExc
private ByteDataAccessBase parent
removeChild(ByteDataAccessBase)
More as one children can refer the same parent. But this refers only the current child.private ByteDataAccessBase currChild
removeChild()
. It is contained here especially for debugging.
Therefore it is private to forbid other usage.private java.nio.charset.Charset charset
protected StringFormatter toStringformatter
public ByteDataAccessBase(int sizeHead)
ByteDataAccess
.
That class defines a method ByteDataAccess.specifyLengthElementHead()
to get the head's size.sizeHead
- The size of head data, it is the number of bytes.protected ByteDataAccessBase(int sizeHead, int sizeData)
assign(byte[], int)
decides on the size of data, and addChild(ByteDataAccessBase, int)
decides on the size of data of a child, this constructor makes no sense. Jchartmut 2015-04-12sizeHead
- The size of head data, it is the number of bytes.sizeData
- number of significant bytes in data for all children.public final void setBigEndian(boolean val)
val
- true if big endian, hi byte at lower adress, false if little endian.public final void setLittleEndianBig2()
public final void setException(boolean val)
val
- true if addChild should throw an exception on error, false if addChild... operations should be return false on error.
Because the default value for the exception is true, the user should set setException(false) usually.public final void setCharset(java.lang.String value)
protected final long _getLong(int idxInChild, int nrofBytesAndSign)
idxInChild
- The position of leading byte in the actual element, the data are taken from data[idxBegin+idx].nrofBytesAndSign
- If positiv, than the method returns the unsigned interpretation of the bytes.
If negative, than the return value is negative, if the last significant bit of the given number of bytes is set.
The value represents the number of bytes to interprete as integer. It may be 1..8 respectively -1...-8.protected final int _getInt(int idxInChild, int nrofBytesAndSign)
idxInChild
- The position of leading byte in the actual element, the data are taken from data[idxBegin+idx].nrofBytesAndSign
- If positiv, than the method returns the unsigned interpretation of the bytes.
If negative, than the return value is negative, if the last significant bit of the given number of bytes is set.
The value represents the number of bytes to interprete as integer. It may be 1..8 respectively -1...-8.protected final void _setLong(int idx, int nrofBytes, long val)
idx
- the position of leading byte in the actual element, the data are set to data[idxBegin+idx].nrofBytes
- The number of bytes of the value.val
- the long value in range adequate nrof bytes.protected final void _setInt(int idx, int nrofBytes, int val)
idx
- the position of leading byte in the actual element, the data are set to data[idxBegin+idx].nrofBytes
- The number of bytes of the value.val
- the long value in range adequate nrof bytes.private final void _expand(int ixNextChildNew, int ixEndNew)
ixNextChild
and/or increments the ixEnd of this and all parents.
It is called if a new child is added inside method addChild(child) and recursively to correct
in all parents. It is called for setLengthElement(int)
ixNextChildNew
- The possible set ixNextChild position, 0 if not to change.ixEndNew
- The new end position, ixEnd is only changed if it is greater the current one.protected void assignDataToFixChildren()
public final void assign(byte[] dataP, int lengthData, int index) throws java.lang.IllegalArgumentException
ixNextChild
is set always after the known head data of this derived type
stored in the final sizeHead
.
data
- The dataP. The length of data may be greater as the number of the significant bytes.lengthData
- absolute Number of significant bytes in data from start of data (index=0).
bExpand
= true.
sizeHead()
, it defines the size of this access. Between the head and this length
some children can be added to access that data. The access is not expanded. Adding a child after this given length
throws an exception.
index
- Start position in data, often 0.java.lang.IllegalArgumentException
public final void assign(byte[] data, int lengthData)
sizeHead()
.
This method should be used only for an root element respectively this is a root element after calling this method.
If the element was used before, its connection to an other parent is dissolved.data
- The data which are accessed with this instancelengthData
- The known length of data. If 0 then the instance is expandable, see isExpandable()
.public final void assign(byte[] dataP)
detach()
a current data buffer, call assign(null);
.dataP
- public final void assignClear(byte[] data)
data
- The data. It should be not null. The data are filled with 0 initial.public final void assignAt(int idxChildInParent, int lengthChild, ByteDataAccessBase parent) throws java.lang.IllegalArgumentException
addChild(ByteDataAccessBase)
is: The position is given here
directly, it should not be the current child but a free child.
specifyLengthElementHead()
: idxChild
and specifyLengthElement()
: idxEnd.
parent
- The parent. It should reference data.lengthChild
- Number of the bytes of the free child.idxChildInParent
- The index of the free child in the data.java.lang.IllegalArgumentException
- If the indices are wrong in respect to the data.public final void assignAt(int idxChildInParent, ByteDataAccessBase parent) throws java.lang.IllegalArgumentException
parent
- The parent. It should reference data.idxChildInParent
- The index of the free child in the data.java.lang.IllegalArgumentException
- If the indices are wrong in respect to the data.@Deprecated protected final void assignCasted(ByteDataAccessBase src, int offsetCastToInput, int lengthDst) throws java.lang.IllegalArgumentException
src
- The known data accessoffsetCastToInput
- typical 0 if single inherition is used.lengthDst
- it is the same like assign(byte[], int)
: If 0 then the child is set to expandable
and its ixEnd()
is set to the sizeHead()
. If >= sizeHead then this instance is not expandable
and this value determines the valid number of data which are able to access via it.java.lang.IllegalArgumentException
- if a length of the new type is specified but the byte[]-data are shorter.
The length of byte[] is tested.private final void copyStdValues(ByteDataAccessBase src)
protected final void upcast(ByteDataAccessBase src, int length)
isCurrentChildInParent()
relation.
ixNextChild
is set proper to this: = this.ixBegin
+ length.
That helps to step in parent via addChild(ByteDataAccessBase)
src
- The firstly associated access instance to the data typically via addChild(ByteDataAccessBase)
,
it remains unchanged but it is no more the child of the parent.length
- if <= this.sizeHead, typically 0, then unused, the thissizeHead()
is used instead.
If > this.sizeHead then it determines the ixEnd()
of this and the parent ixNextChild
.
In that case it is a longer value because this instance should access head and inner children.public final boolean isExpandable()
assign(byte[], int)
public final int sizeHead()
ByteDataAccessBase(int)
.public final byte[] getData()
public final byte[] data()
private final byte[] getData(int recursion)
data
== nullrecursion
- if <0 ends and call throwexc(String, int)
public final void XXXrewind()
public final int getLengthHead()
public final int getLengthCurrent()
getLength()
returns the length
which may be not evaluated with children up to know but given with assign(byte[], int)
.public final int getLength()
public final int getLengthTotal()
public final int getMaxNrofBytes()
public final boolean checkLengthElement(int size)
setLengthElement(int)
for the given instance.
size >= sizeHead
.
If this is set to expand it returns end <= data.length
else it returns end <= ixEnd
whereby end
means the end position of the element ixNextChild
which will be given after call of #setLengthElement(size)
.
This method checks whether a calculated length is proper.
If this method returns false and setLengthElement(int)
is called notwithstanding
the setLengthElement(int)
throws an IllegalArgumentException.
See getMaxNrofBytes()
, this routine is used.size
- public final boolean getBigEndian()
public final void setLengthElement(int length)
parent
of this.
The ixEnd
of this is set with the (this.ixBegin
+length).
This method sets this as not expandable, but does not change the expandable status of the parent.
The ixNextChild
of all parents are set to this index. So adding another child to the parent
starts with that given position. A parent is expand if necessary.
length
- The length of data of this current (last) child.public final void clearHead()
public final void clearData()
public final boolean isInUse()
public final boolean isCurrentChildInParent()
public final boolean sufficingBytesForNextChild(int nrofBytes) throws java.lang.IllegalArgumentException
nrofBytes
- that should fitting in the given data range from current child position
to the end of data determines by calling assingData(...)
or by calling addChild() with a known size of child or setLengthElement() .java.lang.IllegalArgumentException
- see getMaxNrofBytesForNextChild()
public final int getMaxNrofBytesForNextChild() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public final boolean addChild(ByteDataAccessBase child, int sizeChild) throws java.lang.IllegalArgumentException
ByteAccessDerivation child = new ByteAccessDerivation(); //empty and unassigned. ... parent.addChild(child); //The byte[] data of parent are assigned, index after current child index of parent. child.addChild(grandchild); //By adding a child to this child, also the parent's index is corrected.Indices in the parent and child:
addChild()
or its adequate derived addChildXY() sets the indices after the given current child:
#rewind()
etc.
setLengthElement(int)
with the child or add some more grand children.
child
- The child will be assigned with the data of this at index after the current child's end-index.
Note that the child's sizeHead should be set correctly.sizeChild
- The number of bytes which are used from the child or 0. If it is 0, then the child's sizeHead is used
to set the position of a possible next children ixNextChild
, elsewhere ixNextChild
is set using that value.
The child itself does not use this value.bExc
is false.java.lang.IllegalArgumentException
- if the length of the head of the new current child is to far for the data.
It means, child.idxEnd > data.length.public final boolean addChild(ByteDataAccessBase child)
addChild(ByteDataAccessBase, int)
.child
- The child will be initialized newly.public final boolean addChildEmpty(ByteDataAccessBase child)
public final boolean addChildEmpty(ByteDataAccessBase child, int sizeChild)
public final void addChildAt(int idxChild, ByteDataAccessBase child, int sizeChild) throws java.lang.IllegalArgumentException
idxChild
- The index from the position of this (from this.ixBegin
).
It is not the index inside the data
.
If ixBegin
==0 because this is the root ByteDataAccess instance, it is the index in data.child
- An empty instance for a child with given child.sizeHead
. Usual instances are re-used (especially in a C-environment).
child will be filled completely. A content before is cleared except the child.sizeHead
. This value should be known in the child.sizeChild
- The size of the child. It may be 0, but >=0 (asserted)java.lang.IllegalArgumentException
public final void addChildAt(int idxChild, ByteDataAccessBase child) throws java.lang.IllegalArgumentException
idxChild
- The index from the position of this (from this.ixBegin
).
It is not the index inside the data
.
If ixBegin
==0 because this is the root ByteDataAccess instance, it is the index in data.child
- An empty instance for a child with given child.sizeHead
. Usual instances are re-used (especially in a C-environment).
child will be filled completely. A content before is cleared except the child.sizeHead
. This value should be known in the child.java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public final boolean addChildInt(int nrofBytes, int value) throws java.lang.IllegalArgumentException
nrofBytes
- of the integerjava.lang.IllegalArgumentException
public final boolean addChildInteger(int nrofBytes, long value) throws java.lang.IllegalArgumentException
nrofBytes
- of the integerjava.lang.IllegalArgumentException
public final boolean addChildFloat(float value) throws java.lang.IllegalArgumentException
Float.floatToRawIntBits(float)
.java.lang.IllegalArgumentException
public final boolean addChildString(java.lang.String value, java.lang.String sEncoding, boolean preventCtrlChars) throws java.lang.IllegalArgumentException, java.io.UnsupportedEncodingException
value
- String to addsEncoding
- If null then use the standard encoding of the system-environment.preventCtrlChars
- true then values < 0x20 are not set.
If the String value contain a control character with code < 0x20,
a '?' is written. This behavior guarantees, that byte-values < 0x20
can use to detect no-String elements, see getByteNextChild()
.java.lang.IllegalArgumentException
java.io.UnsupportedEncodingException
public final boolean addChildString(java.lang.CharSequence valueCs, java.lang.String sEncoding) throws java.lang.IllegalArgumentException, java.io.UnsupportedEncodingException
valueCs
- String to add, @pjava2c=nonPersistent.sEncoding
- String describes the encoding for translation from UTF16 to bytes.java.lang.IllegalArgumentException
- XXXjava.io.UnsupportedEncodingException
public final void addChildString(java.lang.CharSequence value) throws java.lang.IllegalArgumentException
value
- String to add, @pjava2c=nonPersistent.java.lang.IllegalArgumentException
public final short getChildInt16()
public final int getChildUint16()
public final short getChildUint8()
public final long getChildInteger(int nrofBytes) throws java.lang.IllegalArgumentException
nrofBytes
- of the integer, if negative then gets as signed integer, elsewhere as unsignedjava.lang.IllegalArgumentException
- if not data has not enaught bytes.public final int getChildInt(int nrofBytes) throws java.lang.IllegalArgumentException
nrofBytes
- of the integer, if negative then gets as signed integer, elsewhere as unsigned, Only till 4.java.lang.IllegalArgumentException
- if not data has not enaught bytes.public final float getChildFloat() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if not data has not enaught bytes.public final double getChildDouble() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if not data has not enaught bytes.public final java.lang.String getChildString(int nrofBytes)
nrofBytes
- of the String maybe with 0-bytes on end which will be removed (alignment).java.lang.IllegalArgumentException
- if not data has not enough bytes.java.io.UnsupportedEncodingException
public final void removeChild() throws java.lang.IllegalArgumentException
removeChild(ByteDataAccessBase)
.child
- java.lang.IllegalArgumentException
public final void removeChild(ByteDataAccessBase child)
removeChild()
. The ixEnd
is set to ixNextChild
if the expand mode is set.
In expand mode the ixEnd
is set to the ixNextChild
, to the current child position.
The content which was written before at following positions is not removed. It means a content can be written
with one child type, and checked with another child type after them.child
- It should be a child of this. The parent of the child should be this.public final void removeChildren()
public final void detach()
public final int getPositionInBuffer()
public final int getPositionNextChildInBuffer()
getLengthCurrent()
.public final void copyDataFrom(ByteDataAccessBase src) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public final void copyData(int[] dst)
dst
- This array is field, but only from data of the current element between idxBegin and idxEndprotected final java.lang.String getString(int idx, int nrofBytes)
idx
- The start position inside the child.nrofBytes
- The number of bytes to build the String.data
.java.lang.IndexOutOfBoundsException
- if any index is faulty.protected final int setString(int idx, int nmax, java.lang.String ss)
idx
- The start position inside the child.nmax
- Maximal number of bytesss
- The String representation of the bytes.protected final void _setString(int idx, int nrofBytes, java.lang.String value, java.lang.String sEncoding, boolean preventCtrlChars) throws java.io.UnsupportedEncodingException
idx
- the position in the actual element, the data are set to data[idxBegin+idx].nrofBytes
- The length of the byte[] area to set.
If the String value is longer as nrofBytes, it will be truncated. No exception occurs.
If the String is shorter as nrofBytes, the rest is filled with 0.value
- The String value.sEncoding
- The encoding of the String. null: Use standard encoding.preventCtrlChars
- true then values < 0x20 are not set.
If the String value contain a control character with code < 0x20,
a '?' is written. This behavior guarantees, that byte-values < 0x20
can use to detect no-String elements, see getByteNextChild()
.java.io.UnsupportedEncodingException
protected final float getFloat(int idx)
protected final double getDouble(int idx)
protected final long getInt64(int idx)
protected final int getInt32(int idx)
idx
- the position of leading byte in the actual element, the data are raken from data[idxBegin+idx].
This is not the absolute position in data, idxBegin is added.protected final int getUint32(int idx)
protected final int getUint16(int idx)
idx
- the position of leading byte in the actual element, the data are raken from data[idxBegin+idx].
This is not the absolute position in data, idxBegin is added.protected final short getInt16(int idx)
idx
- the position of leading byte in the actual element, the data are raken from data[idxBegin+idx].
This is not the absolute position in data, idxBegin is added.protected final char getChar(int idx)
idx
- the position of char in the actual element, the data are raken from data[idxBegin+idx].
This is not the absolute position in data, idxBegin is added.protected final byte getInt8(int idx)
idx
- the position of leading byte in the actual element, the data are raken from data[idxBegin+idx].
This is not the absolute position in data, idxBegin is added.protected final short getUint8(int idx)
idx
- the position of leading byte in the actual element, the data are raken from data[idxBegin+idx].
This is not the absolute position in data, idxBegin is added.protected final int getUint32(int idxBytes, int idxArray, int lengthArray)
protected final int getInt32(int idxBytes, int idxArray, int lengthArray)
protected final int getInt16(int idxBytes, int idxArray, int lengthArray)
protected final int getInt8(int idxBytes, int idxArray, int lengthArray)
protected final int getUint16(int idxBytes, int idxArray, int lengthArray)
protected final int getUint8(int idxBytes, int idxArray, int lengthArray)
protected final float getFloat(int idxBytes, int idxArray, int lengthArray)
protected final void setFloat(int idx, float value)
protected final void setDouble(int idx, double value)
protected final void setInt32(int idx, int value)
idx
- The position of leading byte in the current elements data.
This is not the absolute position in data, idxBegin is added.value
- The value in range 0..65535. The value is taken modulo 0xffffffff.protected final void setInt8(int idx, int value)
idx
- The position of leading byte in the current elements data.
This is not the absolute position in data, idxBegin is added.value
- The value in range 0..65535. The value is taken modulo 0xffff.protected final void setUint8(int idx, int value)
idx
- The position of leading byte in the current elements data.
This is not the absolute position in data, idxBegin is added.value
- The value in range 0..65535. The value is taken modulo 0xff.protected final void setUint32(int idx, long value)
idx
- The position of leading byte in the current elements data.
This is not the absolute position in data, idxBegin is added.value
- The value as long. The value is taken modulo 0xffffffff.protected final void setInt16(int idx, int value)
idx
- The position of leading byte in the current elements data.
This is not the absolute position in data, idxBegin is added.value
- The value in range 0..65535. The value is taken modulo 0xffff.protected final void setUint16(int idx, int value)
idx
- The position of leading byte in the current elements data.
This is not the absolute position in data, idxBegin is added.value
- The value in range 0..65535. The value is taken modulo 0xffff.private final void throwexc(java.lang.String text, int idxArray)
protected final void setUint32(int idxBytes, int idxArray, int lengthArray, int val)
protected final void setInt32(int idxBytes, int idxArray, int lengthArray, int val)
protected final void setInt16(int idxBytes, int idxArray, int lengthArray, int val)
protected final void setInt8(int idxBytes, int idxArray, int lengthArray, int val)
protected final void setUint16(int idxBytes, int idxArray, int lengthArray, int val)
protected final void setUint8(int idxBytes, int idxArray, int lengthArray, int val)
protected final void setFloat(int idxBytes, int idxArray, int lengthArray, float val)
private final int setIdxtoNextCurrentChild(int sizeChild)
ixNextChild
to the end of the new child given by argument sizeChild.
The size of the new child, at least its head size, should be known. It is given by the calling argument sizeChild.
addChild(ByteDataAccessBase)
for an added child or by calling
setLengthElement(int)
for the child. Therefore an argument =0 is possible.
sizeChild
- yet known size of the child to add. It have to be >=0.ixNextChild()
before this is processed.
returns -1 if the child cannot be added.protected final int ixBegin()
protected final int ixNextChild()
protected final int ixEnd()
boolean checkData()
data
== null and gets the data from parent if necessary.
With them it is possible to call assign(byte[])
for the parent only and it runs.
If the data remain null throwexc(String, int)
is invoked. It may force an exeption if that is activated.
Elsewhere it returns false, to force prevent access to data in the calling routine.public void infoFormattedAppend(StringFormatter u)
infoFormattedAppend
in interface InfoFormattedAppend
InfoFormattedAppend.infoFormattedAppend(org.vishia.util.StringFormatter)
protected void infoAppendHead(StringFormatter u, int bytesHex)
u
- The destination bufferbytesHex
- Number of shown bytes of data as hexa line.public java.lang.String toString()
toString
in class java.lang.Object