A byteArray implements a mutable sequence of characters.
At any point in time it contains some particular sequence of characters,
but the length and content of the sequence can be changed through certain method calls.
ByteArray are used by the compiler to implement the binary string concatenation operator +.
For example, the code:
x = "a" + 4 + "c"
is compiled to the equivalent of:
x = new ByteArray.create("a").append(4).append("c").toTXT
The principal operations on a ByteArray are the append and insert methods,
which are overloaded so as to accept data of any type.
The append method always adds these characters at the end of the buffer;
the insert method adds the characters at a specified point.
Every byteArray has a capacity. As long as the length of the character sequence contained
in the byteArray does not exceed the capacity, it is not necessary to allocate a new internal buffer array.
If the internal buffer overflows, it is automatically made larger.
How can use the constructors of the ByteArray concept.
$buff = ByteArray.create()
print " BuffLength: " + $buff.getLength -- > 0
print " BuffCapacity: " + $buff.getCapacity -- > 16
$buff = ByteArray.create(1024)
print " BuffLength: " + $buff.getLength -- > 0
print "BuffCapacity: " + $buff.getCapacity ---> 1024
print "\nCreate ByteArray with : This is a test"
$buff = ByteArray.create("This is a test")
print " BuffLength: " + $buff.getLength ---> 24
print $buff ---> This is a test
How can use the append and the insert methods of the ByteArray concept.
#create empty byteArray concept
$buff = ByteArray.create()
#append to String to ByteArray
$buff = $buff.append("This")
$buff = $buff.append( ByteArray.create(" is a number ") )
#append the number '3'=51 to ByteArray
$buff = $buff.append( 51 )
#insert character ':' to specified position
$buff = $buff.insert(17, ':')
print $buff ---> This is a number :3
How can use the getCharAt and the setCharAt methods in byteArray concept.
#create byteArray concept initialized with the specified String
$buff = ByteArray.create("This is a test")
print $buff.getCharAt(3) ---> s
print $buff.getCharAt(11) ---> e
$buff = $buff.setCharAt(6, 'z')
print $buff ---> This iz a test
How can use the deleteCharAt and the delete methods in byteArray concept.
#create byteArray concept initialized with the specified String
$buff = ByteArray.create("This is a test")
print $buff.deleteCharAt(3) ---> Thi is a test
print $buff.delete(0,4) ---> is a test
Methods inherited from: Concept
cloneConcept, extendsConcept, fromXML, getAllInheritedConcepts, getConceptAttribute, getConceptAttributeField, getConceptAttributeFields, getConceptAttributes, getConceptConstructors, getConceptElement, getConceptElementField, getConceptElementFields, getConceptElements, getConceptLabel, getConceptMethod, getConceptMethods, getConceptOperators, getConceptType, getErrorHandler, getInheritedConcepts, getResourceURI, hasConceptAttribute, hasConceptElement, hasConceptMethod, hasPath, isHidden, loadContent, setConceptLabel, setErrorHandler, setHidden, setShowEmpty, showEmpty, toTXT, toXML, setResourceURI |
|
Parameters: |
$length : | the initial capacity. |
|
Exceptions: |
nevativeSizeException :
(Error) | if the $length argument is less than 0. |
Constructs a byteArray with no characters in it and an initial
capacity specified by the $length argument.
Parameters: |
$str : | the initial contents of the byteArray. |
|
Constructs a byteArray so that it represents the same sequence of characters
as the string argument;
in other words, the initial contents of the string buffer is a copy of the argument string.
The initial capacity of the string buffer is the length of the string argument.
Appends the string representation of the Real argument,
which will be converted to character concept, to this byteArray.
$b = ByteArray.create("Initial value.")
print $b.append(97.682)
-- the result is --
Initial value.a
Parameters: |
$ch : | a Character concept. |
|
Appends the string representation of the Charatacter argument to this byteArray.
The length of this byteArray increases by 1.
$b = ByteArray.create("Initial value.")
print $b.append('a')
-- the result is --
Initial value.a
Appends the string representation of the Integer argument,
which will be converted to character concept, to this byteArray.
$b = ByteArray.create("Initial value.")
print $b.append(97)
-- the result is --
Initial value.a
Appends the string to this byteArray.
The characters of the String argument are appended, in order, to the contents
of this byteArray, increasing the length of this byteArray by the length of the argument.
$b = ByteArray.create("Initial value.")
print $b.append("text")
-- the result is --
Initial value.text
Parameters: |
$flag : | a Logical concept. |
|
Appends the string representation of the Logical argument to the byteArray.
$b = ByteArray.create("Initial value.")
print $b.append(true)
-- the result is --
Initial value.true
Parameters: |
$buffer : | the byteArray concept to be appended. |
|
Appends the string representation of the byteArray argument to this byteArray.
The characters of the byteArray argument are appended, in order,
to the contents of this byteArray. The length of this byteArray
increases by the length of the argument.
$b = ByteArray.create("Initial value.")
$ba = ByteArray.create("Second array.")
print $b.append($ba)
-- the result is --
Initial value.Second array.
Parameters: |
$start : | The beginning index, inclusive. |
$end : | The ending index, exclusive. |
|
Exceptions: |
indexOutOfBoundsException :
(Error) | if $start is negative, greater than length(), or greater than end. |
Removes the characters in a substring of this byteArray.
The substring begins at the specified $start and extends to
the character at index $end - 1 or to the end of the byteArray
if no such character exists.
If $start is equal to $end, no changes are made.
$b = ByteArray.create("Initial value.")
print $b.delete(5, 11)
-- the result is --
Initlue.
Parameters: |
$index : | Index of character to remove. |
|
Exceptions: |
indexOutOfBoundsException :
(Error) | If the $index is negative or greater than or equal to length(). |
Removes the character at the specified position in this byteArray
(shortening the byteArray by one character).
$b = ByteArray.create("Initial value.")
print $b.deleteCharAt(8)
-- the result is --
Initialvalue.
Parameters: |
$minCapacity : | the minimum desired capacity. |
|
Ensures that the capacity of the buffer is at
least equal to the specified minimum.
If the current capacity of this byteArray is less than the argument,
then a new internal buffer is allocated with greater capacity.
The new capacity is the larger of:
- The minimumCapacity argument.
- Twice the old capacity, plus 2.
$b = ByteArray.create("Initial value.")
print $b.getCapacity
$b.ensureCapacity(20)
print $b.getCapacity
-- the result is --
14
30 (= 2 * 14 + 2)
Returns the current capacity of the byteArray.
The capacity is the amount of storage available
for newly inserted characters;
beyond which an allocation will occur.
$b = ByteArray.create("Initial value.")
print $b.getCapacity
-- the result is --
14
Parameters: |
$index : | the index of the desired character. |
|
Exceptions: |
indexOutOfBoundsException :
(Error) | if $index is negative or greater than or equal to length(). |
The specified character of the sequence currently represented by the byteArray,
as indicated by the $index argument, is returned.
The first character of a byteArray is at index 0, the next at index 1,
and so on, for array indexing.
The $index argument must be greater than or equal to 0, and less than the length of this byteArray.
$b = ByteArray.create("Initial value.")
print $b.getCharAt(4)
-- the result is --
t
Returns the length (character count) of this byteArray.
Parameters: |
$offset : | the offset. |
$buffer : | a byteArray concept. |
|
Exceptions: |
indexOutOfBoundsException :
(Error) | if the $offset is invalid. |
Inserts the string representation of the byteArray argument into this byteArray.
The characters of the array argument are inserted into the contents of this byteArray
at the position indicated by $offset.
The length of this byteArray increases by the length of the argument.
$b = ByteArray.create("Initial value.")
print $b.getLength
-- the result is --
14
Parameters: |
$offset : | the offset. |
$nr : | a Real concept. |
|
Exceptions: |
indexOutOfBoundsException :
(Error) | if the $offset is invalid. |
Inserts the string representation of the Real argument,
which will be converted to the character concept, into this byteArray
at the indicated by $offset.
The $offset argument must be greater than or equal to 0, and less than or
equal to the length of this byteArray.
$b = ByteArray.create("Initial value.")
print $b.insert(9, 97.582)
-- the result is --
Initial avalue.
Parameters: |
$offset : | the offset. |
$nr : | a Real concept. |
|
Exceptions: |
indexOutOfBoundsException :
(Error) | if the $offset is invalid. |
Inserts the string representation of the second Integer argument,
which will be converted to the character concept, into this byteArray
at the indicated by $offset.
The $offset argument must be greater than or equal to 0,
and less than or equal to the length of this byteArray.
$b = ByteArray.create("Initial value.")
print $b.insert(9, 97)
-- the result is --
Initial avalue.
Parameters: |
$offset : | the offset. |
$flag : | a Logical concept. |
|
Exceptions: |
indexOutOfBoundsException :
(Error) | if the $offset is invalid. |
Inserts the string representation of the Logical argument
into this byteArray at the indicated by $offset.
.
The $offset argument must be greater than or equal to 0,
and less than or equal to the length of this byteArray.
$b = ByteArray.create("Initial value.")
print $b.insert(9, true)
-- the result is --
Initial truevalue.
Parameters: |
$offset : | the offset. |
$ch : | a Character concept. |
|
Exceptions: |
indexOutOfBoundsException :
(Error) | if the $offset is invalid. |
Inserts the string representation of the Character argument into this byteArray.
The second argument is inserted into the contents of this byteArray at the position
indicated by $offset. The length of this byteArray increases by one.
The $offset argument must be greater than or equal to 0,
and less than or equal to the length of this byteArray.
$b = ByteArray.create("Initial value.")
print $b.insert(9, 'a')
-- the result is --
Initial truevalue.
Parameters: |
$offset : | the offset. |
$str : | a String concept. |
|
Exceptions: |
indexOutOfBoundsException :
(Error) | if the $offset is invalid. |
Inserts the string into this byteArray.
The characters of the String argument are inserted, in order,
into this byteArray at the indicated $offset, moving up any
characters originally above that position and increasing the
length of this string buffer by the length of the argument.
The $offset argument must be greater than or equal to 0,
and less than or equal to the length of this byteArray.
$b = ByteArray.create("Initial value.")
print $b.insert(9, "BA ")
-- the result is --
Initial BA value.
Parameters: |
$index : | the index of the character to modify. |
$ch : | the new character. |
|
Exceptions: |
indexOutOfBoundsException :
(Error) | if $index is negative or greater than or equal to length(). |
The character at the specified $index of this byteArray is set to $ch.
The byteArray is altered to represent a new character sequence that is
identical to the old character sequence, except that it contains the
character $ch at position $index.
The $offset argument must be greater than or equal to 0,
and less than the length of this byteArray.
$b = ByteArray.create("Initial value.")
print $b.setCharAt(8, '_')
-- the result is --
Initial_value.
Parameters: |
$newLength : | the new length of the buffer. |
|
Exceptions: |
indexOutOfBoundsException :
(Error) | if the $newLength argument is negative. |
Sets the length of this byteArray. This byteArray is altered to represent
a new character sequence whose length is specified by the argument.
If the $newLength argument is less than the current length of the byteArray,
the byteArray is truncated to contain exactly the number of characters given
by the $newLength argument.
If the $newLength argument is greater than or equal to the current length,
sufficient null characters ('\u0000') are appended to the byteArray so
that length becomes the $newLength argument.
The $newLength argument must be greater than or equal to 0.
$b = ByteArray.create("Initial value.")
print $b.getLength
$b.setLength(20)
print $b.getLength
-- the result is --
14
20