|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.vishia.byteData.ByteDataAccess
public abstract class ByteDataAccess
This class is a base class to control the access to binary data.
The binary data may typically used or produced from a part of software written in C or C++.
There the binary data are struct-constructs.
It is able to support several kinds of struct constructs:
struct are adequate mapped with a derivated class of this class,
using the protected commonly access methods like _getInt(int, int) with predefined indexes
in special methods like getValueXyz().struct with nested struct inside are mapped
with one derivated class per struct, define one reference per nested struct
and overwriting the method assignDataToFixChilds()struct inside a struct (inherition in C) can be mapped with
extra derivated classes for the base struct and usind the
assignCasted_i(ByteDataAccess, int)-method.next() sets the indices to a possible but not yet defined current child:
addChild() or its adequate addChildXY() sets the indices to the given current child:
specifyLengthElement() if this method returns >=0.
specifyLengthElementHead() if this method returns >=0.
setLengthElement(int) with the child
or setLengthCurrentChildElement(int) with the parent, respectively with this.
specifyLengthCurrentChildElement() supplied the number of bytes.
But if this method is not overwritten in the inherited class, an exception is thrown.
<+>---> is a composition,
<>---> is a aggregation, <|---- is a inherition.
+-------------------------------+ +----------+
| ByteDataAccess |----data-------->| byte[] |
|-------------------------------| +----------+
|idxBegin:int |
|idxChild:int |<---------------+ a known parent
+-------------+ |idxEnd:int |---parent-------+ setted in addChild()
| derivated | |-------------------------------|
| user |---|>|specifyLengthElement() |
| classes | |specifyLengthElementHead() |--currentChild--+ the actual child element
+-------------+ |specifyLengthCurrentChild() |<---------------+
+-------------------------------+
| Field Summary | |
|---|---|
static int |
_version_
The version. |
static byte |
kEndOfElements
Definition of the code of end of information, return from next() |
static byte |
kNothing
Definition of the code of no information, return from next() |
static byte |
kText
Aussage: es ist ein String (XML: text()), kein Tag im String |
static byte |
kUndefined
coding: the value is undefined |
| Constructor Summary | |
|---|---|
ByteDataAccess()
Constructs a new empty instance. |
|
| Method Summary | |
|---|---|
boolean |
addChild(ByteDataAccess child)
adds an child Element after the current child or as first child after head. |
void |
addChildEmpty(ByteDataAccess child)
Adds a child Element at current end of data to write data. |
void |
addChildFloat(float value)
Adds a child for 1 integer value without a child instance, and sets the value as integer. |
void |
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. |
void |
addChildString(java.lang.CharSequence value,
java.lang.String sEncoding)
Adds a child with String value. |
void |
addChildString(java.lang.String value)
Adds a child with String value. |
void |
addChildString(java.lang.String value,
java.lang.String sEncoding,
boolean preventCtrlChars)
Adds a child with String value. |
int |
addText(java.lang.String ss)
Deprecated. |
void |
assignAsChild(ByteDataAccess parent)
Deprecated. use addChild() |
void |
assignAtIndex(int idxChildInParent,
ByteDataAccess parent)
assigns the element to the given position of the parents data to present a child of the parent. |
void |
assignAtIndex(int idxChildInParent,
int lengthChild,
ByteDataAccess parent)
assigns the element to the given position of the parents data to present a child of the parent with a defined length. |
void |
assignData(byte[] data,
int length)
Assigns new data to this element. |
void |
assignData(byte[] data,
int lengthData,
int index)
Assigns new data to this element at given index in data. |
void |
assignEmpty(byte[] data)
Initializes a top level, the data are considered as non initalized. |
void |
copyData(int[] dst)
copies some data to a int[], primarily to debug a content. |
void |
copyDataFrom(ByteDataAccess src)
Copies the data into a byte[] |
void |
detach()
Remove all connections. |
void |
elementAt(int indexObjectArray)
Counts the idxChild by given index, idxChild is ByteCount from idxBegin |
void |
expandParent()
Expands the end index of the parent, it means the management of the expanse of the data. |
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. |
long |
getChildInteger(int nrofBytes)
Adds a child for 1 integer value without a child instance, but returns the value as integer. |
java.lang.String |
getChildString(int nrofBytes)
Adds a child for a String value without a child instance, but returns the value as String. |
ByteDataAccess |
getCurrentChild()
|
byte[] |
getData()
Returns the data buffer itself. |
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(). |
int |
getLength()
Returns the length of the existing actual element. |
int |
getLengthCurrentChildElement()
Returns the length of the current child element. |
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 number number of bytes there are max 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 the current child in the assigned buffer. |
java.lang.String |
getText()
Returns the current string or null on end |
int |
getUint32(int idx)
|
boolean |
isTextByte(byte nn)
Returns true if the current child element represents a TEXT(), direct ASCII chars, false if the element is a complex element. |
int |
next()
Sets the data index to the position after the current child element and returns its code. |
void |
removeChild()
remove the current child to assign another current child instead of the first one. |
void |
removeChildren()
Remove all children. |
void |
rewind()
starts the calling loop of next(). |
void |
setBigEndian(boolean val)
Sets the big or little endian mode. |
void |
setLengthCurrentChildElement(int lengthOfCurrentChild)
Sets the length of the current child element after calling next(). |
void |
setLengthElement(int length)
Sets the length of the current element, considering all children. |
abstract int |
specifyLengthElementHead()
Specifies the length of the head data. |
boolean |
sufficingBytesForNextChild(int nrofBytes)
returns true if the given number of bytes is sufficing in the data from position of next child. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int _version_
public static final byte kEndOfElements
public static final byte kNothing
public static final byte kText
public static final byte kUndefined
| Constructor Detail |
|---|
public ByteDataAccess()
| Method Detail |
|---|
public final int getLengthHead()
specifyLengthElementHead()
of the derivated class.
public abstract int specifyLengthElementHead()
protected void specifyLengthElementHead()
{ return kIdxFirstChild; //kIdxFistChild should be defined as static final int.
}
public void assignData(byte[] data,
int length)
throws java.lang.IllegalArgumentException
assign(null, 0);.
data - The data. The length of data may be greater as
the number of the significant bytes.length - Number of significant bytes in data.
If length is > data.length, an exception may be thrown
in any state of the evaluation.
java.lang.IllegalArgumentException - if the length is > data.length
public void assignData(byte[] data,
int lengthData,
int index)
throws java.lang.IllegalArgumentException
assign(null, 0);.
data - The data. The length of data may be greater as
the number of the significant bytes.lengthData - absolute Number of significant bytes in data from idx=0.
If length is > data.length, an exception is thrown.
If the length is <0 (especially -1), it means, it is not known outside.
Than the element is initialized with its known head length.
The length mustn't not ==0, it is tested. Use -1 also if the head length is 0.index - Start position in data
java.lang.IllegalArgumentExceptionpublic final void assignEmpty(byte[] data)
specifyLengthElementHead(). The child Positions
are set to the end of head, no childs are presumed.
The head should be filled with data after that calling some methods like
setInt32(int, int).addChild(ByteDataAccess)
and filled with data after that.
...........the data undefined with defined length.........
+++++ Head, the length should be known.
####****#####**** Space for children,
data - The data. The reference should be initialized, it means
the data have a defined maximum of length. But it is not tested here.
java.lang.IllegalArgumentExceptionpublic final void removeChildren()
public final void detach()
public final void assignAsChild(ByteDataAccess parent)
throws java.lang.IllegalArgumentException
next() should be called before. The pattern of using is:
int nWhat; //code of the element
while( (nWhat = dataElement.next()) != ByteDataAccess.kEndOfElements )
{ switch(nWhat) //test the first byte of the current element
{ case ByteDataAccess.kText:
{ sText = dataElement.getText();
} break;
case code1:
{ code1Element.assignAsChild(dataElement);
evaluateValue(code1Element);
} break:
case code2:
{ code1Element.assignAsChild(dataElement);
evaluateValue(code1Element);
} break:
default: throw new IllegalArgumentException("unknown Element", dataElement);
}
}
The difference to addChild(ByteDataAccess) is: addChild() is used
to writeout to data, addChild() appends the child always after idxEnd,
but this method is used to read from data and appends the child at position of the current child.
specifyLengthElementHead(): idxChild
and specifyLengthElement(): idxEnd.
The idxChildEnd of parent is setted, so calling next() after this operation
increments in data after this new child.
parent - The parent. It should reference data, and a current child position
should be set by calling next() before. See sample at next().
java.lang.IllegalArgumentException - If the data are wrong. The exception is thrown
orginal from specifyLengthElement().
public final void assignAtIndex(int idxChildInParent,
int lengthChild,
ByteDataAccess parent)
throws java.lang.IllegalArgumentException
addChild(ByteDataAccess) 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 assignAtIndex(int idxChildInParent,
ByteDataAccess 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.
public final boolean addChild(ByteDataAccess child)
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.
child - The child will be assigned with the data of this at index after the current child's end-index.
java.lang.IllegalArgumentException - if the length of the old current child is not determined yet.
Either the method specifyLengthElement() should be overwritten or the method
setLengthElement(int) for the child or setLengthCurrentChildElement(int)
should be called to prevent this exception.
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 void removeChild()
throws java.lang.IllegalArgumentException
child -
java.lang.IllegalArgumentException
public final void addChildEmpty(ByteDataAccess child)
throws java.lang.IllegalArgumentException
child.specifyEmptyDefaultData().
child - The child will associated to this and should be used
to add some content.
java.lang.IllegalArgumentException
public final void expandParent()
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public final long getChildInteger(int nrofBytes)
throws java.lang.IllegalArgumentException
nrofBytes - of the integer
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 void addChildInteger(int nrofBytes,
long value)
throws java.lang.IllegalArgumentException
nrofBytes - of the integer
java.lang.IllegalArgumentException
public final void addChildFloat(float value)
throws java.lang.IllegalArgumentException
nrofBytes - of the integer
java.lang.IllegalArgumentException
public final java.lang.String getChildString(int nrofBytes)
throws java.lang.IllegalArgumentException,
java.io.UnsupportedEncodingException
nrofBytes - of the integer
java.lang.IllegalArgumentException - if not data has not enaught bytes.
java.io.UnsupportedEncodingException
public final void 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 void addChildString(java.lang.String value)
throws java.lang.IllegalArgumentException
value - String to add
java.lang.IllegalArgumentException
public final void addChildString(java.lang.CharSequence value,
java.lang.String sEncoding)
throws java.lang.IllegalArgumentException,
java.io.UnsupportedEncodingException
value - String to add, @pjava2c=nonPersistent.
java.lang.IllegalArgumentException
java.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 int addText(java.lang.String ss)
throws java.lang.IllegalArgumentException
ss - The String to writecolor - The color
java.lang.IllegalArgumentExceptionpublic final void rewind()
public final int next()
throws java.lang.IllegalArgumentException
while( (eElement = code.next()) != kEndOfElements)
{ switch(eElement) { ... }
}
java.lang.IllegalArgumentException
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 - if the length of the current child is not determined yet.
Either the method specifyLengthElement() should be overwritten or the method
setLengthElement(int) for the child or setLengthCurrentChildElement(int)
should be called to prevent this exception.public final int getMaxNrofBytes()
public final int getLength()
public final int getLengthTotal()
public final byte[] getData()
public final int getPositionInBuffer()
public final int getPositionNextChildInBuffer()
public final int getLengthCurrentChildElement()
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - if the user has not defined a overloaded methode specifyLengthCurrentChildElement()
or this method has thrown the exception because the length is not determinable.public final void setLengthCurrentChildElement(int lengthOfCurrentChild)
public final void setLengthElement(int length)
length - The length inclusive all children.public final boolean isTextByte(byte nn)
public final java.lang.String getText()
public void setBigEndian(boolean val)
val - true if big endian, hi byte at lower adress, false if little endian.public final void copyData(int[] dst)
dst - This array is field, but only from data of the current element between idxBegin and idxEndpublic 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.public final int getUint32(int idx)
public final void copyDataFrom(ByteDataAccess src)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentExceptionpublic final void elementAt(int indexObjectArray)
indexObjectArray - Index of Arraypublic final ByteDataAccess getCurrentChild()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||