# sys::Buf

    sys::Obj
      sys::Buf

`public final class Buf`

Buf encapsulates a fixed capacity byte[]. The fixed capacity is available via the 'bytesLen' field. At any time a variable number of bytes are actually used as defined by the 'size' field. Use the BufInStream and BufOutStream classes to perform memory based IO against a Buf instance.

bytes

  `public inline byte[] bytes`

bytesLen

  `public short bytesLen`

size

  `public short size`

Buf

  `public void Buf(int maxBufLen)`

  Construct a buffer with the specified maximum size.

clear

  `public void clear()`

  Set size to zero. The data remains untouched, but the buffer is ready to be used to begin writing from scratch.

copyFromBuf

  `public void copyFromBuf(Buf that)`

  Copy the specified buffer bytes into this buffer's bytes and update size. If the specified buffer contains more than bytesLen bytes then the copy is truncated.

copyFromBytes

  `public void copyFromBytes(byte[] that, int off, int len)`

  Copy the specified byte array into this buffer's bytes and update size. If the specified length is greater than bytesLen bytes then the copy is truncated.

copyFromStr

  `public bool copyFromStr(Str s)`

  Copy the specified string including its null terminator into this buffer bytes field and update size accordingly. If the specified string contains more than bytesLen characters including the null terminator then return false and truncate the copy. If truncated we still add a null terminator.

get

  `public int get(int index)`

  Get the byte at the specified index.

toStr

  `public Str toStr() [javaNative]`

  Return the bytes cast to a Str reference. No guarantee is made whether the string is actually null terminated.