Class Bytes.BytesBuilder

  • Enclosing class:
    Bytes

    public static class Bytes.BytesBuilder
    extends Object
    This class provides an easy, efficient, reusable mechanism for building immutable Bytes objects.
    Since:
    1.0.0
    • Method Detail

      • append

        public Bytes.BytesBuilder append​(String s)
        Converts string to bytes using UTF-8 encoding and appends bytes.
        Returns:
        self
      • append

        public Bytes.BytesBuilder append​(int b)
        Append a single byte.
        Parameters:
        b - take the lower 8 bits and appends it.
        Returns:
        self
      • append

        public Bytes.BytesBuilder append​(byte[] bytes,
                                         int offset,
                                         int length)
        Append a section of bytes from array
        Parameters:
        bytes - - bytes to be appended
        offset - - start of bytes to be appended
        length - - how many bytes from 'offset' to be appended
        Returns:
        self
      • append

        public Bytes.BytesBuilder append​(InputStream in,
                                         int length)
                                  throws IOException
        Append a sequence of bytes from an InputStream
        Parameters:
        in - data source to append from
        length - number of bytes to read from data source
        Returns:
        self
        Throws:
        IOException
      • append

        public Bytes.BytesBuilder append​(ByteBuffer bb)
        Append data from a ByteBuffer
        Parameters:
        bb - data is read from the ByteBuffer in such a way that its position is not changed.
        Returns:
        self
      • setLength

        public void setLength​(int newLen)
        Sets the point at which appending will start. This method can shrink or grow the ByteBuilder from its current state. If it grows it will zero pad.
      • getLength

        public int getLength()
      • toBytes

        public Bytes toBytes()