mn8 Language Reference | Index    

ByteArray

SUMMARY: NO ATTRIBUTES  NO ELEMENTS  CONSTRUCTORS SUMMARY  NO OPERATORS  METHODS SUMMARYDETAIL: NO ATTRIBUTES  NO ELEMENTS  CONSTRUCTOR DETAILS  NO OPERATORS  METHOD DETAILS

Description

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.

Usage

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

Version: 0.1
Authors:Szabo Csaba ()
Location:
Inherits: Concept

Constructor List

create (Integer $length)
create (String $str)
top

Method List

ByteArrayappend (Real $nr)
ByteArrayappend (Character $ch)
ByteArrayappend (Integer $nr)
ByteArrayappend (String $str)
ByteArrayappend (Logical $flag)
ByteArrayappend (ByteArray $buffer)
ByteArraydelete (Integer $start, Integer $end)
ByteArraydeleteCharAt (Integer $index)
ensureCapacity (Integer $minCapacity)
IntegergetCapacity
CharactergetCharAt (Integer $index)
IntegergetLength
ByteArrayinsert (Integer $offset, ByteArray $buffer)
ByteArrayinsert (Integer $offset, Real $nr)
ByteArrayinsert (Integer $offset, Integer $nr)
ByteArrayinsert (Integer $offset, Logical $flag)
ByteArrayinsert (Integer $offset, Character $ch)
ByteArrayinsert (Integer $offset, String $str)
setCharAt (Integer $index, Character $ch)
setLength (Integer $newLength)
top
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

Detailed Constructor Info

create (Integer $length)
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.

top
create (String $str)
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.

top

Detailed Method Info

append (Real $nr)
Parameters:
$nr :a Real concept.
Returns: ByteArray

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
            

top
append (Character $ch)
Parameters:
$ch :a Character concept.
Returns: ByteArray

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
            

top
append (Integer $nr)
Parameters:
$nr :an Integer concept.
Returns: ByteArray

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
            

top
append (String $str)
Parameters:
$str :a String concept.
Returns: ByteArray

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
            

top
append (Logical $flag)
Parameters:
$flag :a Logical concept.
Returns: ByteArray

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
            

top
append (ByteArray $buffer)
Parameters:
$buffer :the byteArray concept to be appended.
Returns: ByteArray

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.
            

top
delete (Integer $start, Integer $end)
Parameters:
$start :The beginning index, inclusive.
$end :The ending index, exclusive.
Returns: ByteArray
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.
            

top
deleteCharAt (Integer $index)
Parameters:
$index :Index of character to remove.
Returns: ByteArray
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.
            

top
ensureCapacity (Integer $minCapacity)
Parameters:
$minCapacity :the minimum desired capacity.
Returns:

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:

            $b = ByteArray.create("Initial value.")
            print $b.getCapacity
            $b.ensureCapacity(20)
            print $b.getCapacity
            -- the result is --
            14
            30 (= 2 * 14 + 2)
            

top
getCapacity
Returns: Integer

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
            

top
getCharAt (Integer $index)
Parameters:
$index :the index of the desired character.
Returns: 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
            

top
getLength
Returns: Integer

Returns the length (character count) of this byteArray.

top
insert (Integer $offset, ByteArray $buffer)
Parameters:
$offset :the offset.
$buffer :a byteArray concept.
Returns: ByteArray
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
            

top
insert (Integer $offset, Real $nr)
Parameters:
$offset :the offset.
$nr :a Real concept.
Returns: ByteArray
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.
            

top
insert (Integer $offset, Integer $nr)
Parameters:
$offset :the offset.
$nr :a Real concept.
Returns: ByteArray
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.
            

top
insert (Integer $offset, Logical $flag)
Parameters:
$offset :the offset.
$flag :a Logical concept.
Returns: ByteArray
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.
            

top
insert (Integer $offset, Character $ch)
Parameters:
$offset :the offset.
$ch :a Character concept.
Returns: ByteArray
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.
            

top
insert (Integer $offset, String $str)
Parameters:
$offset :the offset.
$str :a String concept.
Returns: ByteArray
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.
            

top
setCharAt (Integer $index, Character $ch)
Parameters:
$index :the index of the character to modify.
$ch :the new character.
Returns:
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.
            

top
setLength (Integer $newLength)
Parameters:
$newLength :the new length of the buffer.
Returns:
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
            

top