B4A Library [B4X] BytesBuilder - simplifies working with arrays of bytes

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jan 31, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Edit: BytesBuilder is included in B4XCollections library (named B4XBytesBuilder).

    BytesBuilder class, which is compatible with B4A, B4i and B4J, makes it easier to work with bytes.
    You can think of it as a combination of String and StringBuilder, but instead of holding characters it holds bytes.

    Modifying the stored data is done with:
    • Append - Adds data at the end.
    • Insert - Inserts data at the given index.
    • Set - Replaces data starting from the given index
    • Remove - Removes the data in the given range.
    • Clear - Clears the data.
    Note that the internal buffer grows automatically as needed.

    Reading the data is done with:
    • SubArray / SubArray2 - Similar to String.SubString
    • ToArray - Similar to StringBuilder.ToString. Returns a complete copy of the data.
    • IndexOf / IndexOf2 - Similar to String.IndexOf

    Dependencies:
    B4A, B4J - ByteConverter
    B4i - iRandomAccessFile

    Example:
    Code:
    Dim bb As BytesBuilder
    bb.Initialize
    For i = 0 To 255
       bb.Append(
    Array As Byte(i))
    Next
    bb.Insert(
    1Array As Byte(0xFF0XFF0xFF))
    Log(bb.IndexOf(Array As Byte(101112)))
    Log(bb.IndexOf(Array As Byte(0)))
    Log(bb.IndexOf2(Array As Byte(0xFF), 3))
    Dim bc As ByteConverter
    Log(bc.HexFromBytes(bb.ToArray))
    Log(bc.HexFromBytes(bb.SubArray2(250300)))
    The class is attached.
     

    Attached Files:

    Last edited: Jan 9, 2019
  2. Beja

    Beja Expert Licensed User

    Wow! That's the class b4x was missing.
    Thanks Erel .. You don't stop surprising us with new useful tools .all thumps up!
     
    DonManfred likes this.
  3. naifnas

    naifnas Active Member Licensed User

    Thanks
    your alloys this first
     
  4. victormedranop

    victormedranop Well-Known Member Licensed User

    Just when I finished this APS.
    Uffffffff!!!!!!

    Victor
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice