B4J Programming Press on the image to return to the main documentation page.

rRandomAccessFile

List of types:

AsyncStreams
B4RSerializator
ByteConverter
RandomAccessFile

AsyncStreams


Events:

NewData (Buffer() As Byte)
Error

Members:


  Initialize (Stream As B4RStream, NewDataSub As SubVoidArray, ErrorSub As SubVoidVoid) As void

  InitializePrefix (Stream As B4RStream, BigEndian As Boolean, NewDataSub As SubVoidArray, ErrorSub As SubVoidVoid) As void

  MaxBufferSize As UInt

  WaitForMoreDataDelay As UInt

  Write (Data() As Byte) As AsyncStreams

  Write2 (Data() As Byte, Start As UInt, Length As UInt) As AsyncStreams

Members description:

Initialize (Stream As B4RStream, NewDataSub As SubVoidArray, ErrorSub As SubVoidVoid) As void
Initializes the object and set the subs that will handle the events.
InitializePrefix (Stream As B4RStream, BigEndian As Boolean, NewDataSub As SubVoidArray, ErrorSub As SubVoidVoid) As void
Initializes the object in prefix mode. Both sides of the connection must adhere to the "prefix" protocol.
It is recommended to set #StackBufferSize to 600 or more.
MaxBufferSize will be set to 500 bytes and WaitForMoreDataDelay will be set to 300ms.
BigEndian - Sets the length prefix endianess.
MaxBufferSize As UInt
The internal buffer limit. The NewData event will be raised when the buffer reaches this size or if no more data is available.
The data is stored in the stack buffer. Make sure that #StackBufferSize is large enough.
WaitForMoreDataDelay As UInt
Number of milliseconds to wait for new data (when there is at least one byte available).
Write (Data() As Byte) As AsyncStreams
Writes the array to the stream.
Write2 (Data() As Byte, Start As UInt, Length As UInt) As AsyncStreams
Writes the array to the stream.

B4RSerializator

Converts arrays of objects to bytes and vice versa.
The data can be shared with other B4X tools using the B4RSerializator class (not to confuse with B4XSerializator which is not compatible with B4R).

Events:

None

Members:


  ConvertArrayToBytes (Objects() As Object) As Byte()

  ConvertArrayToBytes2 (Objects() As Object, Buffer() As Byte) As Byte()

  ConvertBytesToArray (Bytes() As Byte, ObjectsBuffer() As Object) As Object()

Members description:

ConvertArrayToBytes (Objects() As Object) As Byte()
Converts an array of objects to an array of bytes.
Supported types: numbers, strings and array of bytes. Booleans will be converted to 0 or 1.
The returned array is created on the stack buffer.
ConvertArrayToBytes2 (Objects() As Object, Buffer() As Byte) As Byte()
Similar to ConvertArrayToBytes. The returned array will share the memory with the Buffer array instead of using the stack buffer.
ConvertBytesToArray (Bytes() As Byte, ObjectsBuffer() As Object) As Object()
Converts a previously serialized array of bytes to an array of objects.
Returns an empty array if the input is invalid. Make sure to check the returned array size.
The returned array will share the memory with ObjectsBuffer array. ObjectsBuffer length must be equal or larger than the number of items.

ByteConverter

Provides methods that allow converting between different types of arrays to arrays of bytes.
The conversion methods do not modify the memory, instead they provide a different representation of the same memory block.
ArrayCopy and ObjectCopy allow copying of arrays and objects. These methods can be used to copy local objects to global variables.
The endianess used is the board's native endianess (little endian for Arduino).
Note that strings are casted to arrays of bytes automatically.

Events:

None

Members:


  ArrayCompare (Arr1() As Byte, Arr2() As Byte) As Int

  ArrayCopy (Src() As Byte, Dest() As Byte) As void

  ArrayCopy2 (Src() As Byte, SrcOffset As UInt, Dest() As Byte, DestOffset As UInt, Count As UInt) As void

  DoublesFromBytes (Bytes() As Byte) As Double()

  DoublesToBytes (UInts() As Double) As Byte()

  EndsWith (Src() As Byte, Suffix() As Byte) As Boolean

  HexFromBytes (Bytes() As Byte) As String

  HexToBytes (Hex As String) As Byte()

  IndexOf (Src() As Byte, SearchFor() As Byte) As Int

  IndexOf2 (Src() As Byte, SearchFor() As Byte, StartIndex As UInt) As Int

  IntsFromBytes (Bytes() As Byte) As Int()

  IntsToBytes (Ints() As Int) As Byte()

  LastIndexOf (Src() As Byte, SearchFor() As Byte) As Int

  LastIndexOf2 (Src() As Byte, SearchFor() As Byte, StartIndex As UInt) As Int

  LongsFromBytes (Bytes() As Byte) As Long()

  LongsToBytes (UInts() As Long) As Byte()

  ObjectCopy (Src As Object, Dest As Object, ObjectSize As UInt) As void

  ObjectFromBytes (Bytes() As Byte) As Object

  ObjectToBytes (Object As Object, ObjectSize As UInt) As Byte()

  Split (Src() As Byte, Separator() As Byte) As SplitIterator

  StartsWith (Src() As Byte, Prefix() As Byte) As Boolean

  StringFromBytes (Src() As Byte) As String

  StringToBytes (Str As String) As Byte()

  SubString (Src() As Byte, BeginIndex As UInt) As Byte()

  SubString2 (Src() As Byte, BeginIndex As UInt, EndIndex As UInt) As Byte()

  Trim (Src() As Byte) As Byte()

  UIntsFromBytes (Bytes() As Byte) As UInt()

  UIntsToBytes (UInts() As UInt) As Byte()

  ULongsFromBytes (Bytes() As Byte) As ULong()

  ULongsToBytes (ArrayULong() As ULong) As Byte()

Members description:

ArrayCompare (Arr1() As Byte, Arr2() As Byte) As Int
Compares the two arrays.
Returns 0 if both arrays are equal.
Returns a value lower than 0 if Arr2 value is larger (the first byte that is different is larger).
Returns a value larger than 0 if Arr1 value is larger.
ArrayCopy (Src() As Byte, Dest() As Byte) As void
Copies the Src array to the Dest array. The destination array length will be set
to the length of the source array. Bounds are not checked.
This method is useful for copying local arrays to global arrays.
ArrayCopy2 (Src() As Byte, SrcOffset As UInt, Dest() As Byte, DestOffset As UInt, Count As UInt) As void
Copies the bytes from the source array to the destination array.
Make sure that the destination array is large enough. Bounds are not checked.
Src - Source array.
SrcOffset - Index of the first byte to be copied.
Dest - Destination array.
DestOffset - The first byte will be copied to this index.
Count - Number of bytes to copy.
DoublesFromBytes (Bytes() As Byte) As Double()
Converts the bytes array to an array of 32 bit floating points. Note that both arrays share the same memory.
DoublesToBytes (UInts() As Double) As Byte()
Converts the 32 bit floating points array to an array of bytes. Note that both arrays share the same memory.
EndsWith (Src() As Byte, Suffix() As Byte) As Boolean
Returns true if the Src array ends with the Suffix array.
HexFromBytes (Bytes() As Byte) As String
Converts the bytes array to a hex string.
HexToBytes (Hex As String) As Byte()
Converts the hex string to a bytes array.
IndexOf (Src() As Byte, SearchFor() As Byte) As Int
Returns the index of the first occurrence of SearchFor array in the Src array.
Starts searching from the given Index.
Returns -1 if SearchFor was not found.
IndexOf2 (Src() As Byte, SearchFor() As Byte, StartIndex As UInt) As Int
Returns the index of the first occurrence of SearchFor array in the Src array.
Returns -1 if SearchFor was not found.
IntsFromBytes (Bytes() As Byte) As Int()
Converts the bytes array to an array of 16 bit ints. Note that both arrays share the same memory.
IntsToBytes (Ints() As Int) As Byte()
Converts the 16 bit ints array to an array of bytes. Note that both arrays share the same memory.
LastIndexOf (Src() As Byte, SearchFor() As Byte) As Int
Returns the index of the first occurrence of SearchFor array in the Src array.
The search starts at the end of the array and advances to the beginning.
LastIndexOf2 (Src() As Byte, SearchFor() As Byte, StartIndex As UInt) As Int
Returns the index of the first occurrence of SearchFor array in the Src array.
The search starts at the given index and advances to the beginning.
LongsFromBytes (Bytes() As Byte) As Long()
Converts the bytes array to an array of 32 bit signed longs. Note that both arrays share the same memory.
LongsToBytes (UInts() As Long) As Byte()
Converts the 32 bit signed longs array to an array of bytes. Note that both arrays share the same memory.
ObjectCopy (Src As Object, Dest As Object, ObjectSize As UInt) As void
Copies the source object to the destination object. This method makes a shallow copy of the source object's memory.
The destination object must be a variable of the same type.
You can use this method to copy local objects to global variables.
Src - The source object.
Dest - Destination variable.
ObjectSize - The object size as computed with SizeOf.
Example:
bc.ObjectCopy(LocalType, GlobalType, SizeOf(LocalType))
ObjectFromBytes (Bytes() As Byte) As Object
Converts the array of bytes to an object. Note that the array and the object share the same memory.
ObjectToBytes (Object As Object, ObjectSize As UInt) As Byte()
Converts the object (non-primitive) to an array of bytes. Note that the array and the object share the same memory.
Split (Src() As Byte, Separator() As Byte) As SplitIterator
Splits the array of bytes based on the Separator array and returns an iterator.
Example:

Dim bc As ByteConverter
For Each s() As Byte In bc.Split("abc,def,ghf", ",")
  Log(s)
Next
StartsWith (Src() As Byte, Prefix() As Byte) As Boolean
Returns true if the Src array starts with the Prefix array.
StringFromBytes (Src() As Byte) As String
Creates a new string based on the bytes array.
Note that you can print bytes arrays directly so in most cases this method is not required.
Unlike StringToBytes this method does allocate a new memory block for the returned string.
StringToBytes (Str As String) As Byte()
Converts the string to an array of bytes. This is the same as calling Str.GetBytes.
Note that the array and the string share the same memory.
SubString (Src() As Byte, BeginIndex As UInt) As Byte()
Create a new array that shares the same memory as the given array.
Src - Source array.
BeginIndex - The index of the first element in the new array.
Example:
Dim bc As ByteConverter
Log(bc.SubString("012345", 2)) '2345
SubString2 (Src() As Byte, BeginIndex As UInt, EndIndex As UInt) As Byte()
Create a new array that shares the same memory as the given array.
Src - Source array.
BeginIndex - The index of the first element in the new array.
EndIndex - The index of the last element. The last element will not be included.
Example:
Dim bc As ByteConverter
Log(bc.SubString2("012345", 2, 4)) '23
Trim (Src() As Byte) As Byte()
Creates a new array that shares the same memory as the given array, without the leading and trailing whitespace characters.
UIntsFromBytes (Bytes() As Byte) As UInt()
Converts the bytes array to an array of 16 bit unsigned ints. Note that both arrays share the same memory.
UIntsToBytes (UInts() As UInt) As Byte()
Converts the 16 bit unsigned ints array to an array of bytes. Note that both arrays share the same memory.
ULongsFromBytes (Bytes() As Byte) As ULong()
Converts the bytes array to an array of 32 bit unsigned longs. Note that both arrays share the same memory.
ULongsToBytes (ArrayULong() As ULong) As Byte()
Converts the 32 bit unsigned longs array to an array of bytes. Note that both arrays share the same memory.

RandomAccessFile


Events:

None

Members:


  CurrentPosition As UInt

  Initialize (Buffer() As Byte, LittleEndian As Boolean) As void

  ReadByte (Position As UInt) As Byte

  ReadBytes (Dest() As Byte, StartOffset As Int, Length As Int, Position As UInt) As void

  ReadBytes2 (Length As Int, Position As UInt) As Byte()

  ReadDouble32 (Position As UInt) As Double

  ReadInt16 (Position As UInt) As Int

  ReadLong32 (Position As UInt) As Long

  ReadUInt16 (Position As UInt) As UInt

  ReadULong32 (Position As UInt) As ULong

  WriteByte (Value As Byte, Position As UInt) As void

  WriteBytes (Src() As Byte, StartOffset As Int, Length As Int, Position As UInt) As void

  WriteDouble32 (Value As Double, Position As UInt) As void

  WriteInt16 (Value As Int, Position As UInt) As void

  WriteLong32 (Value As Long, Position As UInt) As void

  WriteUInt16 (Value As UInt, Position As UInt) As void

  WriteULong32 (Value As ULong, Position As UInt) As void

Members description:

CurrentPosition As UInt
Gets or sets the current position.
Initialize (Buffer() As Byte, LittleEndian As Boolean) As void
Initializes the object with the backend array.
Buffer - Backend array.
LittleEndian - Sets the endianess that is used when reading or writing numbers.
ReadByte (Position As UInt) As Byte
Reads a single byte.
ReadBytes (Dest() As Byte, StartOffset As Int, Length As Int, Position As UInt) As void
Copies bytes from the backend array to the Dest array. Boundaries are not checked.
Dest - Destination array.
StartOffset - Index of the first byte in the destination array.
Length - Number of bytes to copy.
Position - Position of the first byte.
ReadBytes2 (Length As Int, Position As UInt) As Byte()
Similar to ReadBytes, however data is not copied.
Returns an array that shares the same memory as the backend array.
Length - The returned array length.
Position - Position of the first byte in the backend array.
ReadDouble32 (Position As UInt) As Double
Reads a 4 bytes Double (equivalent to B4X Float).
ReadInt16 (Position As UInt) As Int
Reads a 2 byte Int (equivalent to B4X Short).
ReadLong32 (Position As UInt) As Long
Reads a 4 bytes Long (equivalent to B4X Int).
ReadUInt16 (Position As UInt) As UInt
Reads a 2 byte unsigned Int.
ReadULong32 (Position As UInt) As ULong
Reads a 4 bytes unsigned long.
WriteByte (Value As Byte, Position As UInt) As void
Writes a single byte.
WriteBytes (Src() As Byte, StartOffset As Int, Length As Int, Position As UInt) As void
Copies bytes to the backend array. Boundaries are not checked.
Src - Source array.
StartOffset - Offset of the first byte in the source array.
Length - Number of bytes to copy.
Position - Position of the first byte in the backend array.
WriteDouble32 (Value As Double, Position As UInt) As void
Writes a 4 bytes Double (equivalent to B4X Float).
WriteInt16 (Value As Int, Position As UInt) As void
Writes a 2 byte Int (equivalent to B4X Short).
WriteLong32 (Value As Long, Position As UInt) As void
Writes a 4 bytes Long (equivalent to B4X Int).
WriteUInt16 (Value As UInt, Position As UInt) As void
Write a 2 byte unsigned Int.
WriteULong32 (Value As ULong, Position As UInt) As void
Writes a 4 bytes unsigned Long.
Top